开发者

LINQ To XML Getting a value without the nodes inside

I have this XML:

<chunk type="manufacturer_info" id="" note="">test: <chunk type="style" style="link">${manufacturer_website}</chunk></chunk>

I need to get "test: " 开发者_如何学编程separately from the inner element.

EDIT: This is coming into a function as an XElement.


The <chunk> element has two child nodes: a text node and a <chunk> element.

You can get the value of the text node as follows:

var element = XElement.Parse(@"<chunk type=""manufacturer_info"" ...");

var result = string.Concat(element.Nodes().OfType<XText>());
// result == "test: "


Here you go.

          string xml =  @"<Chunks><chunk type='manufacturer_info' id='' note=''>test:                <chunk type='style' style='link'>${manufacturer_website}</chunk></chunk></Chunks>";

          var xDoc = XDocument.Parse(xml);
          var res = xDoc.DescendantNodes().OfType<XText>().First().Value;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜