0

我有这样的 xml 数据

string data = @"<DeliveryReport><message id=""093102403501103726"" 
    sentdate=""2013/10/24 08:50:11"" donedate=""2013/10/24 08:50:12""
    status=""NOT_DELIVERED"" gsmerror=""1"" /></DeliveryReport>";

并且正在转换/解析它

if (data != null)
{
    XDocument xmlDoc = XDocument.Load(data);

    var tutorials = from tutorial in xmlDoc.Descendants("message")
        select new
        {

        };
}

在路径中抛出错误非法字符。任何人都可以告诉我我错过了什么吗?

4

2 回答 2

3

您正在使用XDocument.Load(string),它接受文件名或 URL 以从以下位置加载 XML:

参数
uri:一个 URI 字符串,它引用要加载到新 XDocument 中的文件。

你想要XDocument.Parse(string),它已经在一个字符串中接受 XML:

参数
text:包含 XML 的字符串。

于 2013-10-24T13:16:02.873 回答
0

尝试使用创建时的TextReader重载:LoadXDocument

if (data != null)
{
    XDocument xmlDoc = XDocument.Load(new System.IO.StringReader(data));

    var tutorials = from tutorial in xmlDoc.Descendants("message")
                    select new
                    {

                    };

}
于 2013-10-24T13:17:53.257 回答