C
C#6mo ago
Brokemia

Getting the Value of XElement including tags

I have an XElement and I want to get its value, including any child elements of it expressed as tags. So for example, I have
<test>1<a>2</a>3</test>
<test>1<a>2</a>3</test>
And I want to get 1<a>2</a>3 as a string. What's an easy way to do that?
10 Replies
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Brokemia
BrokemiaOP6mo ago
Then it's a bad example I guess. Idk enough of the xml standard to see why that's wrong. This is the real xml https://raw.githubusercontent.com/EverestAPI/Everest/dev/lib-stripped/Celeste.xml I'll have an XElement for one of the <member> elements and I want to get anything inside it
Omnissiah
Omnissiah6mo ago
XmlDocument has InnerXml for a node, in XElement there should be something similar maybe you can do node.ToString()?
Brokemia
BrokemiaOP6mo ago
Hmm, ToString() kind of works. I could take all the child nodes, ToString them and concat together I could also switch to XmlDocument tbh
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Brokemia
BrokemiaOP6mo ago
Might be, although it seems like your first suggestion wouldn't let me take the innerXML (or equivalent) as a string I did a little research into the second option when I started this but didn't find anything immediate, I'll check a little harder though
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Brokemia
BrokemiaOP6mo ago
Yeah, so I took a look at DocFx, they're just using XElement and have a ton of code that I don't need at all for my use-case. I ended up just switching my existing approach to XmlDocument and it seems to work pretty well
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Brokemia
BrokemiaOP6mo ago
I'm not sure what the benefit would I be since my approach is already working, and their code is tailored to their use case and would need to be altered a bunch
Want results from more Discord servers?
Add your server