I have an XML format of this structure (the real world example is horrendously long and complicated, but this should illustrate it):
<document> <post>
<author>Bill Smith</author>
<subject>Test Article</subject>
<dates>
<uploaded>some date</uploaded>
<published>some date</published>
</dates>
</post>
<post>
<author>Bill Smith</author>
<subject>Test Article</subject>
<dates>
<uploaded>some date</uploaded>
<published>some date</published>
</dates>
</post> </document>
I have wrote a simple query to pull out each of the posts. I can get the author and subject fine, but I don't know how to drill down into the dates part to pull out the published bit.
Thanks
You can use the following LINQ to get the first "published" element.
You can give any expressions as parameter to the 'Descendants' method. If you have xml as a string, you can use the following to read it into an
XDocument
Please remember to check for nulls!! :-)