问题描述
我正在尝试获取架构并针对我的 xml 进行验证.
XmlReaderSetting settings = new System.Xml.XmlReaderSettings();settings.Schemas.Add(null, "http://example.com/myschema.xsd");settings.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler(settings_ValidationEventHandler);settings.ValidationType = ValidationType.Schema;settings.IgnoreWhitespace = false;XmlReader 阅读器 = XmlReader.Create(xml, settings);
我明白了
无效的URI:Uri字符串太长System.UriFormatException 未处理 Message=Invalid URI: Uri 字符串太长.源 = 系统堆栈跟踪:在 System.Uri.CreateThis(字符串 uri,布尔值 dontEscape,UriKind uriKind)在 System.Uri..ctor(字符串 uriString,UriKind uriKind)在 System.Xml.XmlResolver.ResolveUri(Uri baseUri,字符串 relativeUri)在 System.Xml.XmlUrlResolver.ResolveUri(Uri baseUri,字符串 relativeUri)在 System.Xml.XmlReaderSettings.CreateReader(字符串 inputUri,XmlParserContext inputContext)在 System.Xml.XmlReader.Create(字符串 inputUri,XmlReaderSettings 设置,XmlParserContext inputContext)在 System.Xml.XmlReader.Create(字符串 inputUri,XmlReaderSettings 设置)在 Program.cs:line 42 中的 ConsoleApplication2.Program.Main(String[] args)在 System.AppDomain._nExecuteAssembly(RuntimeAssembly 程序集,字符串 [] 参数)在 System.AppDomain.ExecuteAssembly(字符串 assemblyFile,证据 assemblySecurity,String [] args)在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()在 System.Threading.ThreadHelper.ThreadStart_Context(对象状态)在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback 回调,对象状态,布尔 ignoreSyncCtx)在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback 回调,对象状态)在 System.Threading.ThreadHelper.ThreadStart() 内部异常:
不告诉我最大长度是多少或任何东西.以前有人收到过这个吗?
如果参数是字符串,问题是你的 xmlreader.create 函数中的 xml 应该是 uri.
例如.
XmlReader reader = XmlReader.Create("http://ServerName/data/books.xml", settings);
在您的情况下,xml 文件被解释为 url,因此它抱怨限制.
看看这个 msdn 文档 XmlReader.Create 方法一>对于不同的重载方法..
我猜你应该使用 TextReader 之一.p>
I am trying to grab a schema and validate against my xml.
XmlReaderSetting settings = new System.Xml.XmlReaderSettings();
settings.Schemas.Add(null, "http://example.com/myschema.xsd");
settings.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler(settings_ValidationEventHandler);
settings.ValidationType = ValidationType.Schema;
settings.IgnoreWhitespace = false;
XmlReader reader = XmlReader.Create(xml, settings);
I get
Invalid URI: The Uri string is too long
System.UriFormatException was unhandled Message=Invalid URI: The Uri string is too long. Source=System StackTrace:
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString, UriKind uriKind)
at System.Xml.XmlResolver.ResolveUri(Uri baseUri, String relativeUri)
at System.Xml.XmlUrlResolver.ResolveUri(Uri baseUri, String relativeUri)
at System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext)
at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings, XmlParserContext inputContext)
at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings)
at ConsoleApplication2.Program.Main(String[] args) in Program.cs:line 42
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart() InnerException:
Does not tell me what the max length is or anything. Anyone ever get this before?
the problem is that the xml in your xmlreader.create function should be a uri if the argument is a string.
eg.
XmlReader reader = XmlReader.Create("http://ServerName/data/books.xml", settings);
In your case the xml file is being interpreted as the url and hence it is complaining about the limit.
look at this msdn doc XmlReader.Create Method for different overloaded methods..
I am guessing you should use the TextReader one.
这篇关于无效的 URI:Uri 字符串太长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!