Parsing XML in VB.NET using XMLDocument
-
Hello! I've got a piece of code where I need to parse a XML-file and store the data in a DataTable do modify and use the data from the file. I'm a bit stuck on the SelectNodes method. If I have a XML file that looks like this:
146413 DataExport 1.0.0 x4 2011-08-23T00:01:45.2367404+02:00
The following code works like a charm:
Dim xd As XmlDocument Dim xnl As XmlNodeList xd = New XmlDocument() xd.Load(fileName) xnl = xd.SelectNodes("/MASTER.DATA/Envelope")
BUT! The file doesn't exactly look like that. The MASTER.DATA actually looks like this:
And all of a sudden I don't get bupkis with the above mentioned code. What am I doing wrong?? :confused: Any help is greatly appreciated. :) //Jagg
Wexelblats algorithm: Pick two: 1. Good, 2. Fast, 3. Cheap
-
Hello! I've got a piece of code where I need to parse a XML-file and store the data in a DataTable do modify and use the data from the file. I'm a bit stuck on the SelectNodes method. If I have a XML file that looks like this:
146413 DataExport 1.0.0 x4 2011-08-23T00:01:45.2367404+02:00
The following code works like a charm:
Dim xd As XmlDocument Dim xnl As XmlNodeList xd = New XmlDocument() xd.Load(fileName) xnl = xd.SelectNodes("/MASTER.DATA/Envelope")
BUT! The file doesn't exactly look like that. The MASTER.DATA actually looks like this:
And all of a sudden I don't get bupkis with the above mentioned code. What am I doing wrong?? :confused: Any help is greatly appreciated. :) //Jagg
Wexelblats algorithm: Pick two: 1. Good, 2. Fast, 3. Cheap
I'm not sure whether the dot in the name of your rootnode is allowed. I'd go for a name without a dot.
(more stuff)
The query below should work;
xnl = xd.SelectNodes("//MASTERDATA/Envelope")
Or, to get a specific piece;
xnl = xd.SelectNodes("//MASTERDATA/Envelope[MessageId='146413']")
Hope this helps :)
Bastard Programmer from Hell :suss:
-
I'm not sure whether the dot in the name of your rootnode is allowed. I'd go for a name without a dot.
(more stuff)
The query below should work;
xnl = xd.SelectNodes("//MASTERDATA/Envelope")
Or, to get a specific piece;
xnl = xd.SelectNodes("//MASTERDATA/Envelope[MessageId='146413']")
Hope this helps :)
Bastard Programmer from Hell :suss:
Hi, thanks for the reply. However, that didn't work either. It works as soon as I remove all the other definitions (xmlns:xsi, xsi:schemaLocation and xmlns) from the MASTER.DATA (or MASTERDATA) but as soon as they are in the file it goes completely blank. I don't get any errors, I just don't find anything. Regarding removing the dot (MASTER.DATA) it's probably not possible, this file gets sent automatically from one of our back end systems. :sigh:
Wexelblats algorithm: Pick two: 1. Good, 2. Fast, 3. Cheap