Reputation: 2761
I have a function that returns the value from a specific tag in an XML document:
XElement elem = XElement.Parse(xml_string);
string ret = elem.Element(key).Value.ToString();
return ret;
I'm trying to figure out how to create another method that returns the full string contents contained within a tag, including child tags and child values.
i.e. if I have:
<foo>
Hello
<child1>val1</child1>
<child2>val2</child2>
</foo>
The method above properly returns 'Hello', but what I want is another method that returns:
Hello<child1>val1</child1><child2>val2</child2>
Upvotes: 0
Views: 1408
Reputation: 2394
The easiest option is to spin through the collection returned by XElement.Nodes() and concatenate the XNode.ToString() values for all of those nodes. If you don't want it formatted (and it sounds like you don't), call XNode.ToString(SaveOptions.DisableFormatting)
Upvotes: 1