C
C#17mo ago
kruug

❔ 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
Angius
Angius17mo ago
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.0
mtreit
mtreit17mo ago
If you know the path to the element in question you can potentially just use an XPath query
kruug
kruugOP17mo ago
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.
Angius
Angius17mo ago
Why not just... deserialize it? RSS is fairly standardized, so you're not dealing with random bullshit data being thrown at you
kruug
kruugOP17mo ago
Thanks, that turned up results I hadn't come across yet.
Angius
Angius17mo ago
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
Accord
Accord17mo ago
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.

Did you find this page helpful?