問題描述
我正在嘗試獲取架構并針對我的 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 字符串太長的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!