无效的URI:URI字符串太长 [英] Invalid URI: The Uri string is too long

查看:3641
本文介绍了无效的URI:URI字符串太长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图抓住一个架构和验证对我的XML。

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);

我收到

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?

推荐答案

的问题是,在你的xmlreader.create功能的XML应该是一个URI,如果该参数是一个字符串。

the problem is that the xml in your xmlreader.create function should be a uri if the argument is a string.

如:

XmlReader reader = XmlReader.Create("http://ServerName/data/books.xml", settings);

在你的情况下,XML文件将被PTED作为URL跨$ P $,因此它是抱怨的限制。

In your case the xml file is being interpreted as the url and hence it is complaining about the limit.

看看这个MSDN文档 XmlReader.Create方法 针对不同的重载方法。

look at this msdn doc XmlReader.Create Method for different overloaded methods..

我猜你应该使用的TextReader 之一。

这篇关于无效的URI:URI字符串太长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆