08-10-2012 12:50 PM
Just starting to learn about XML.
I have a simple XML file that I created which is as follows
<?xml version="1.0" encoding="utf-8" ?> <Probes> <Probe> <Location>Ambient</Location> </Probe> <Probe> <Location>panel1</Location> </Probe> <Probe> <Location>panel2</Location> </Probe> <Probe> <Location>panel3</Location> </Probe> </Probes>
Using XML Property Node - Child Nodes Array results in an array of 9 elements:
#text Probe #text Probe #text Probe #text Probe #text
My question is what are all the #text that are there? Shouldn't the child nodes be just the probes?
Solved! Go to Solution.
08-11-2012 06:25 PM
Any unwanted newline or space is going to cause one of those #text nodes. The string you posted contains some type of newline character (it is a bit too human readable), that will give you those unwanted text nodes. Try using Search and Replace to get rid of all vertical whitespace.
08-11-2012 08:15 PM
Which editor do you use to create XML files?
I have XP, and I am guessing that text editors add newline carriage returns.
I downloaded Microsoft's XML Notepad 2007, and it had no trouble parsing the XML file
08-11-2012 11:49 PM
It sounds to me like you may be heading down a dark path. Instead of using the 'Child Nodes Array' and fighting through the complications like extraneous text nodes, let me suggest you look into XPath and use 'Get All Matched Nodes.vi' or 'Get First Matched Node.vi' to get the elements. XPath makes parsing XML a breeze.
For Example:
Of course I hope that using XP does not mean you are using LV8.6 or earlier since the XPath VIs are new to LV9.
If you are using LV8.6 or earlier I suggest looking into the .NET functions to implement XPath. Once you get the hang of it, it still beats trying to parse XML the old fashioned way.
As to the editor, I generate very few XML files by hand, mostly I get them from other programs and parse them in LV. Again, XPath smooths out the rough edges.
08-12-2012 08:03 AM
Unfortunately, we only have LabVIEW 8.6 at work.
I will look into using XPath with .NET
What do you use to validate an XML with DTD?