I know the web link of an XML file, and I'm using it in my app.
It's root element is feed
and it has several child elements called entry
. Each entry
has an element summary
which consists of both text and several child tags. For example,
<entry>
<title type="text">money giving</title>
<author>
<name>BMA</name>
</author>
<summary type="text">
<short-description>we give you money</short-description>
<tab id="0" header="Header & d">
This is Line 1
This is Line 2
This is Line 3
</tab>
<tab id="1" header="abc">
Only one line here
</tab>
</summary>
</entry>
I want to get the complete text inside summary
, including the child tags short-description
and tags
. I have tried using this code :
XmlDocument xmlDoc = await XmlDocument.LoadFromUriAsync(new Uri("http://bigmanani.com/Kiosk-RSS_updated.xml"));
XDocument xDoc = XDocument.Parse(xmlDoc.GetXml());
XElement root = xDoc.Root;
XNamespace ad = "http://www.w3.org/2005/Atom";
IEnumerable<string> title = from abc in root.Descendants(ad+"summary") select (string )abc;
foreach(string one in title)
DebugMessage(one);
The problem's that I get only the textual part of the summary
element, and the child elements short-description
and tab
are ignored completely. How can I get the complete text instead ?
It sounds like you just don't want the cast to string, which is documented as:
If the XElement has children, the concatenated string value of all of the element's text and descendant's text is returned.
You probably want ToString()
instead:
Returns the indented XML for this node.
So:
var title = root.Descendants(ad + "summary").Select(x => x.ToString());
(There's no benefit in using a query expression for just a simple projection - calling the extension method is simpler.)
See more on this question at Stackoverflow