問(wèn)題描述
我正在嘗試獲取架構(gòu)并針對(duì)我的 xml 進(jìn)行驗(yàn)證.
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);
我明白了
無(wú)效的URI:Uri字符串太長(zhǎng)System.UriFormatException 未處理 Message=Invalid URI: Uri 字符串太長(zhǎng).源 = 系統(tǒng)堆棧跟蹤:在 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 設(shè)置,XmlParserContext inputContext)在 System.Xml.XmlReader.Create(字符串 inputUri,XmlReaderSettings 設(shè)置)在 Program.cs:line 42 中的 ConsoleApplication2.Program.Main(String[] args)在 System.AppDomain._nExecuteAssembly(RuntimeAssembly 程序集,字符串 [] 參數(shù))在 System.AppDomain.ExecuteAssembly(字符串 assemblyFile,證據(jù) assemblySecurity,String [] args)在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()在 System.Threading.ThreadHelper.ThreadStart_Context(對(duì)象狀態(tài))在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback 回調(diào),對(duì)象狀態(tài),布爾 ignoreSyncCtx)在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback 回調(diào),對(duì)象狀態(tài))在 System.Threading.ThreadHelper.ThreadStart() 內(nèi)部異常:
不告訴我最大長(zhǎng)度是多少或任何東西.以前有人收到過(guò)這個(gè)嗎?
如果參數(shù)是字符串,問(wèn)題是你的 xmlreader.create 函數(shù)中的 xml 應(yīng)該是 uri.
例如.
XmlReader reader = XmlReader.Create("http://ServerName/data/books.xml", settings);
在您的情況下,xml 文件被解釋為 url,因此它抱怨限制.
看看這個(gè) msdn 文檔 XmlReader.Create 方法一>對(duì)于不同的重載方法..
我猜你應(yīng)該使用 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.
這篇關(guān)于無(wú)效的 URI:Uri 字符串太長(zhǎng)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!