Can’t seem to find how to appropriately parse this using XElement:
<messages>
<message subclass="a" context="d" key="g">
<message subclass="b" context="e" key="h">
<message subclass="c" context="f" key="i">
</messages>
I’d like to get this out to a List where is three strings subclass, context, key.
Your input is not valid XML, it’s missing closing tags on the inner message elements. But assuming the format was valid, you could parse out your structure as in:
You can also use
XDocumentfor a full XML document, and use theLoadmethod instead ofParseif you were using an XML file or a stream, for example. Additionally, you can select into a concrete class if you have one defined. Given a class definition ofYou could use
select new Messagein the query, and the result would be aList<Message>, whereas right now it is a list of an anonymous type.