在路径XML非法字符 [英] XML Illegal Characters in path

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

问题描述

我查询肥皂基础的服务,并希望分析但是返回的XML当我尝试将XML加载到一个在XDOC为了查询数据。我得到错误信息路径非法字符?这(下图)是从服务返回的XML。我只是想获得比赛的列表,并把它们放到一个List我已经安装。该XML并加载到一个XML文档,但这样的格式必须正确?

I am querying a soap based service and wish to analyse the XML returned however when I try to load the XML into an XDoc in order to query the data. am getting an 'illegal characters in path' error message? This (below) is the XML returned from the service. I simply want to get the list of competitions and put them into a List I have setup. The XMl Does load into an XML Document though so must be correctly formatted?.

在做到这一点,避开错误,将不胜感激的最好方式任何意见。

Any advice on the best way to do this and get round the error would be greatly appreciated.

<?xml version="1.0" ?> 
- <gsmrs version="2.0" sport="soccer" lang="en" last_generated="2010-08-27 20:40:05">
- <method method_id="3" name="get_competitions">
  <parameter name="area_id" value="1" /> 
  <parameter name="authorized" value="yes" /> 
  <parameter name="lang" value="en" /> 
  </method>
  <competition competition_id="11" name="2. Bundesliga" soccertype="default" teamtype="default" display_order="20" type="club" area_id="80" last_updated="2010-08-27 19:53:14" area_name="Germany" countrycode="DEU" /> 
  </gsmrs>

下面是我的代码,我需要能够查询在XDOC数据:

Here is my code, I need to be able to query the data in an XDoc:

string theXml = myGSM.get_competitions("", "", 1, "en", "yes");
XmlDocument myDoc = new XmlDocument();
MyDoc.LoadXml(theXml);
XDocument xDoc = XDocument.Load(myDoc.InnerXml);

在预先感谢。

推荐答案

您不显示你的源代码,但我猜你在做什么是这样的:

You don't show your source code, however I guess what you are doing is this:

string xml = ... retrieve ...;
XmlDocument doc = new XmlDocument();
doc.Load(xml); // error thrown here



加载方法期望一个的文件名的不是一个XML本身。要加载一个实际的XML,只需使用的loadXML 方法:

The Load method expects a file name not an XML itself. To load an actual XML, just use the LoadXml method:

... same code ...
doc.LoadXml(xml);



同样地,使用的XDocument 负载(串)方法需要的文件名的,而不是实际的XML。然而,有没有的loadXML 的方法,所以从字符串加载XML的正确方法是这样的:

Similarly, using XDocument the Load(string) method expects a filename, not an actual XML. However, there's no LoadXml method, so the correct way of loading the XML from a string is like this:

string xml = ... retrieve ...;
XDocument doc;
using (StringReader s = new StringReader(xml))
{
    doc = XDocument.Load(s);
}



作为事实上开发任何东西的时候,它是要付出非常好的主意注意在语义的参数(这意味着)不仅是他们的类型。当一个参数的类型是字符串这并不意味着人们可以在短短的任何一个字符串饲料。

As a matter of fact when developing anything, it's a very good idea to pay attention to the semantics (meaning) of parameters not just their types. When the type of a parameter is a string it doesn't mean one can feed in just anything that is a string.

另外,在关于你更新的问题,这是没有意义的使用的XmlDocument 的XDocument 在同一时间。选择一个或另一个。

Also in respect to your updated question, it makes no sense to use XmlDocument and XDocument at the same time. Choose one or the another.

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

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