路径错误非法字符,而在C#中XML解析 [英] Illegal characters in path error while parsing XML in C#

查看:650
本文介绍了路径错误非法字符,而在C#中XML解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我得到一个路径错误非法字符,而使用XmlTextReader的方法。基本上,我送一个长的URL来tr.im,并tr.im并将响应作为XML流,我试图解析,但我得到了上述的错误。你们可以指导我,为什么我得到这个错误,我要去哪里错了吗?下面的代码:


I'm getting an "Illegal characters in path error" while using XMLTextReader method. Basically, I'm sending a long URL to tr.im, and tr.im sends the response as an XML stream, which I'm trying to parse but I get the above mentioned error. Can you guys guide me as to why I'm getting this error and where I'm going wrong? Here's the code:

WebRequest wrURL;
Stream objStream;
string strURL;
wrURL = WebRequest.Create("http://api.tr.im/api/trim_url.xml?url=" + HttpUtility.UrlEncode(txtURL.Text));
objStream = wrURL.GetResponse().GetResponseStream();
StreamReader objSReader = new StreamReader(objStream);
strURL = objSReader.ReadToEnd().ToString();
XmlTextReader reader = new XmlTextReader(strURL); //getting the error at this point



我使用Visual Studio 2008中,快速版

I'm using Visual Studio 2008, Express Edition

推荐答案

为什么你正在使用的XmlTextReader的构造函数,它接受一个文件路径作为参数,但你传递XML内容,而不是原因。

The reason why is you are using the constructor of XmlTextReader which takes a file path as the parameter but you're passing XML content instead.

试试下面的代码

XmlTextReader reader = new XmlTextReader(new StringReader(strURL));

这篇关于路径错误非法字符,而在C#中XML解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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