❔ Is there a way to read XML the same way I would read JSON?
With JSON, I can use NewtonSoft and access a node like data["name"]["subname"]. Is there a way to do that same thing but with XML data?
7 Replies
Not as easily, no
Your best bet would probably be loading the file into
XmlDocument
and using all available methods to search for nodes and traverse the tree: https://learn.microsoft.com/en-us/dotnet/api/system.xml.xmldocument?view=net-7.0If you know the path to the element in question you can potentially just use an XPath query
It's for an RSS feed, so I'm hoping to keep each group together (Post title, post date, etc). But everything I'm seeing doesn't read like it can guarantee everything that goes together will stay together.
Why not just... deserialize it?
RSS is fairly standardized, so you're not dealing with random bullshit data being thrown at you
Thanks, that turned up results I hadn't come across yet.
Nice
Deserializing XML isn't as easy as deserializing JSON for whatever reason, but it's still better than traversing the tree with magic strings
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.