开发者

C# XDocument needs to be parsed to XML again

I have a Xdocument that is populated as follows:

XDocument xDoc = XDocument.Parse(new StreamReader(response.GetResponseStream()).ReadToEnd());

This gives me an XDocument that looks as follows:

<GetReportAsXMLS开发者_运维百科tring>
     <report>
        <reportItem Count ="562..................
</GetReportAsXMLStringResult>

Anything between the tag is all just a giant string(Black). How would I get this portion of the document to format as XML? The tag is also part of the string. I just don't know how to make this show it as not XML.

Thanks


It's hard to say from your description, but it looks like you'll need to first parse the response stream (valid xml), which contains another xml document (as a string). You'll need to extract the string from the 'outer' xml document and parse it into a new one:

psuedocode:

XDocument outer = response.GetResponseStream();
String innerXml = outer.Element("report").Value;
XDocument inner = XDocument.Parse(innerXml);


You have this XML content :

<GetReportAsXMLString>
  <report>
    <reportItem Count =\"562\"/>
    <reportItem Count =\"562\"/>
  </report>
</GetReportAsXMLString>

and you want to extract only the "reportItem" nodes?

If so you can do this:

string xml = "<GetReportAsXMLString><report><reportItem Count =\"562\"/><reportItem Count =\"562\"/></report></GetReportAsXMLString>";
XDocument xDoc = XDocument.Parse(xml);
IEnumerable<XElement> elList = xDoc.Descendants().Where(x => x.Name.LocalName.Equals("report")).Descendants().Where(x => x.Name.LocalName.Equals("reportItem"));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜