加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 无效的URI:Uri字符串太长

发布时间:2020-12-15 06:27:30 所属栏目:百科 来源:网络整理
导读:我试图抓住一个模式并验证我的xml. XmlReaderSetting settings = new System.Xml.XmlReaderSettings(); settings.Schemas.Add(null,"http://example.com/myschema.xsd"); settings.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler(
我试图抓住一个模式并验证我的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,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,Object state)
       at System.Threading.ThreadHelper.ThreadStart()   InnerException:

不告诉我最大长度是什么或什么.以前有人得过吗?

解决方法

问题是,如果参数是一个字符串,xmlreader.create函数中的xml应该是一个uri.

例如.

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

在你的情况下,xml文件被解释为url,因此它正在抱怨极限.

看看这个msdn doc XmlReader.Create Method
对于不同的重载方法

我猜你应该使用TextReader.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读