For simplicity let's say my XML is
<root><Mode>TestMode1</Mode><ShipperID>1234</ShipperID></root>
And I have the following code:
Dim xmlObj As XElement = XElement.Parse(exampleString) Console.WriteLine(xmlObj.<Mode>.Value)
Or
Dim doc As XDocument = XDocument.Parse(exampleString) Dim specificElement = doc.Root.Element("Mode").Value Console.WriteLine(specificElement)
Which is the right way to go? The first treats the XML as an element whereas the second treats it as a document.
I prefer the first because I can reference the properties in the XML dynamically whereas in the second I need to reference by string.
Which way is the recommended way to go?
No comments:
Post a Comment