XML file - Child Nodes Array

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.

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.

Similar Messages

  • Obtain Array from an XML file with Multiple Arrays

    Hi,
    So I have been struggling with this program I am making for the last few months but I am almost there. I have a program that creates multiple arrays and place them one after another in an xml file and each array has its own unique name. Now I would like to create a VI that takes this XML file and when the user inputs the specific array name they are looking for it goes into the xml file finds the entire array under that name and displays it in an output indictor to be viewed on the VI. Attached is a sample of my xml file and the VI that creates this xml file.
    Thanks,
    dlovell
    Solved!
    Go to Solution.
    Attachments:
    I_Win.zip ‏20 KB

    Here is a slightly different version. The one above reads from a file. This is how you would read from an already loaded XML string.
    =====================
    LabVIEW 2012
    Attachments:
    Find Array.vi ‏18 KB

  • Place contents of xml file to 2D array

    i have a xml file like
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE map SYSTEM "map.dtd">
    <map width="5" height="5" goal="6" name="Hallways of Dooom">
         <random-item type='lantern' amount='5' />
         <random-item type='health' amount='10' />
         <tile x="1" y="0" type="floor">
              <renderhint>floor:wood</renderhint>
         </tile>
         <tile x="0" y="1" type="wall" />
         <tile x="1" y="1" type="floor" startlocation="1" />
         <tile x="3" y="1" type="floor">
              <item type="treasure">Bar of Silver</item>
              <renderhint>floor:stone,blood</renderhint>
         </tile>
    </map>i was asked to creat a 5*5 2D array from it. each tile represents a position on the point. If the type of tile is wall, it is represented by number 2; if it is floor, it is represented by number 1.
    i have written my code as following:
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.*;
    import org.xml.sax.SAXException;
    import java.io.*;
    public class parsexml
        public void parseXML()
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
         factory.setValidating(true);
         factory.setIgnoringElementContentWhitespace(true);
         try {
             DocumentBuilder parser = factory.newDocumentBuilder();
             Document doc = parser.parse(new File("hallways.xml"));
             System.out.println("XML file parsed.");
             processTree(doc);
         } catch (ParserConfigurationException e) {
             e.printStackTrace();
         } catch (SAXException e) {
             e.printStackTrace();
         } catch (IOException e) {
             e.printStackTrace();
        public void processTree(Document doc)
         int column = 0;
         int row = 0;
         int hori = 0;
         int vert = 0;
         String Type = "";
         Node element = doc.getDocumentElement();
         NamedNodeMap attrs = element.getAttributes();
         for (int i = 0; i < attrs.getLength(); i++) {
             Node attr = attrs.item(i);
             String attrName = attr.getNodeName();
             if (attrName == "width") {
              column = Integer.parseInt(attr.getNodeValue());
             if (attrName == "height") {
              row = Integer.parseInt(attr.getNodeValue());
         int[][] map = new int[row][column];
         NodeList children = element.getChildNodes();
         for (int i = 0; i < children.getLength(); i++) {
             Node child = children.item(i);
             String nodeName = child.getNodeName();
             if (nodeName == "tile") {
              NamedNodeMap attributes = child.getAttributes();
              for (int a = 0; a < attributes.getLength(); a++) {
                  Node attribute = attributes.item(a);
                  String attributeName = attribute.getNodeName();
                  if (attributeName == "x") {
                   hori = Integer.parseInt(attribute.getNodeValue());
                  if (attributeName == "y") {
                   vert = Integer.parseInt(attribute.getNodeValue());
                  if (attributeName == "type") {
                   Type = attribute.getNodeValue();
             if (Type == "floor") {
              map[hori][vert] = 1;
             } else if (Type == "wall") {
              map[hori][vert] = 2;
         print(map);
        public void print(int[][] map)
         for (int r = 0; r < map.length; r++) {
             for (int c = 0; c < map[r].length; c++) {
              System.out.print(map[r][c]);
             System.out.println();
        public static void main(String[] args)
         parsexml xml = new parsexml();
         xml.parseXML();
    }When i run the program, i found it doesn't fills the spcified position on the array. all I get is a 5*5 grid of 0s.
    Can anyone tells me why? thank you in advance.

    Unless someone is willing to put in the time to do your job for you, you'll have to debug it yourself. Put in some debugging statements. In their simplest form this is just a bunch of System.out.println("your message here") calls where you put in messages describing the current point of execution (like what method you just started or are about to finish) and the values of relevant data (such as method parameters, loop indices, whatever you feel is important).
    Then run the program and see what it tells you.

  • How to generate xml file from an array of data using jQuery

    Hi All,
    Iam facing the problem with diaplaying array of data into a xml file, Actually iam using SAPUI5 commons table to display the backend data, each row in the table has checkbox. If we select each checkbox, iam getting the particular record and push it into an empty array and then i should show that array of data into xml file.

    OData.request 
    requestUri: url,  
    method: "POST",
    headers: {                    
    "X-Requested-With": "XMLHttpRequest",                  
    "Content-Type": "application/atom+xml",
    "DataServiceVersion": "2.0", 
    "Accept": "application/atom+xml,application/atomsvc+xml,application/xml",  
    "X-CSRF-Token": header_xcsrf_token   
    data: requestTableDATAArray
    // Response after posting and set message
    function (data, response) 
    alert(response.body);//gives xml format

  • Find keyword in XML file from an array of keywords

    Hi,
    I have an array of collection of keyword:
    $KeyWord = @("Fail","Exception","Terminated","Error")
    I want to check in a textfile sample.xml, if any or all keywords from the array $KeyWord exist. If any of the keyword exist in the textfile, a boolean variable $ExceptionOccurred will return $true.
    The code I am using working good with a TEXT file, but not working with XML file. Is there a way to convert XML to Text and then look for keyword in plaintext?
    Code:
    $KeyWord = @("Fail","Exception","Terminated","Error")
    $sampleFile = Get-Content .\file1.txt
    $ExceptionOccurred = $false
    $KeyWord | ForEach {
        If ($sampleFile -contains $_) {
            $ExceptionOccurred = $true
    $ExceptionOccurred

    hello,
    with PowerShell you can parsing XML files.
    Example XML-File:
    <ListOfData><Table><service>Backup1</service><description>Backup</description><status>Fail</status></Table><Table><service>Backup2</service><description>Backup</description><status>Exception</status></Table><Table><service>Backup2</service><description>Backup</description><status>Error</status></Table></ListOfData>
    with Select-Object you expand the XML as Table and ForEach-Object with if match the attribute "status" for value in the $KeyWord array.
    $KeyWord = @("Fail","Exception","Terminated","Error")[xml]$xml = Get-Content .\file.xml$xml.ListOfData | Select-Object -ExpandProperty Table | ForEach-Object{if($KeyWord -contains $_.status){$ExceptionOccurred = $true}}

  • Original xml from child nodes

    I need to be able to get a String with the original xml for all the child nodes once I traverse a DOM tree and find a particular node.

    Use the method suggested above, but unless you've done it before it might not be obvious how to get it into a string.
    Here's the trick:
    // Create a StringWriter
    StringWriter sw = new StringWriter();
    // Wrap the StringWriter with a PrintWriter
    PrintWriter pw = new PrintWriter(sw);
    // Print the node, passing the printwriter
    yourNode.print(pw);
    // Retrieve the string result from the underlying stringwriter
    String theXMLText = sw.toString();

  • How to ignore a node while reading data from XML file

    Hi All,
    I have a XML file that i am reading that XML file using XMLStreamReader and then i need to create another XML file that has specific nodes(from the database).
    I need to ignore nodes(with values) that are not in the database and while creating the XML file, only nodes that are it the database should be written in the new file.*
    For eg.
    <XML>
    <Stud>
    <Name>XYZ</Name>
    <Roll>1</Roll>
    <Class>1</Class>
    </Stud>
    <Stud>
    <Name>ABC</Name>
    <Roll>2</Roll>
    <Class>1</Class>
    </Stud>
    </XML>
    In database i have only two node :<Name> and <Roll>.
    So, my new XML will be
    <XML>
    <Stud>
    <Name>XYZ</Name>
    <Roll>1</Roll>
    </Stud>
    <Stud>
    <Name>ABC</Name>
    <Roll>2</Roll>
    </Stud>
    </XML>

    Hi gborges,
    Since you're new to LabVIEW, I thought I would post a few helpful links.  A great way to learn some LabVIEW basics is to look over the introductions --
    Three Hour LabVIEW Introduction Course
    Six Hour LabVIEW Introduction Course
    You might even want to think about signing up for the LabVIEW Basics I & II courses which are taught by Applications Engineers.  You can always search for KnowledgeBases and, of course, you already know about our forums!
    Happy coding,
    Megan B.
    National Instruments

  • Read xml file to array

    I would like to read an xml file to an array before placing it in a document. I have seen people on here do something similar but I just can't get it to work.
    Right now I am having to open the docuement as just a file read it into an array and then pull the elements I want with a regex expression, which is pretty tedious.
    It seems the framework has some pretty nice xml element functions if I could just read the file in an xml format
    Right now I am doing something like this to read the file
    myfile = new File (path to file);
    myfile.open("r");
    myothervariable = myfile.read();
    myfile.close();
    But I am just reading it as simple text. I can't use any of the xml properties or functions on any of this. Does this make sense?
    Thanks in advance for any help

    Do this:
    myfile = new File (path to file);
    myfile.open("r");
    myXML = new XML (myfile.read());
    myfile.close();
    You now have an XML object that you can parse with JavaScript. See the ESTK's JavaScript Tools Guide (in the ESTK's Help menu), the chapter entitled "Integrating XML into JavaScript" (ch. 9 in CS5).
    Peter

  • How to extract data from an arbitrary xml file and export in a nice csv file?

    Hallo,
    I'm facing big problems in the use of XML files. I have an
    application which generates XML files with clusters containing arrays
    and scalars like in the example pasted below. My task is to
    read it and export the data in a human-friendly CSV document.
    Since I don't know the actual content of the cluster, I need some kind
    of intelligent vi which goes through the XML file looking for arrays
    and other data structures in order to export them properly in the CSV
    format (columns with headers).
    Thank you
    <Cluster>
    <Name></Name>
    <NumElts>3</NumElts>
    <Array>
    <Name></Name>
    <Dimsize>6</Dimsize>
    <I32>
    <Name></Name>
    <Val>0</Val>
    </I32>
    <I32>
    <Name></Name>
    <Val>1</Val>
    </I32>
    <I32>
    <Name></Name>
    <Val>2</Val>
    </I32>
    <I32>
    <Name></Name>
    <Val>3</Val>
    </I32>
    <I32>
    <Name></Name>
    <Val>4</Val>
    </I32>
    <I32>
    <Name></Name>
    <Val>5</Val>
    </I32>
    </Array>
    <DBL>
    <Name></Name>
    <Val>3.14159265358979</Val>
    </DBL>
    <String>
    <Name></Name>
    <Val>ciao</Val>
    </String>
    </Cluster>
    Solved!
    Go to Solution.

    Thank you again,
    I'm forwarding my vi draft with many comments and an xml file sample.
    Data in cluster is stored according to the LabVIEW schema, infact it is generated by LabVIEW.
    What I'm trying to do is to access the element of the cluster and read their content using the Invoke node and Property node functions. Could you give it a look, there may be something wrong, I'm not able to access cluster children.
    Which funcions should I use? Could you give me an example? You may use the draft I enclosed...
    Then write these data in a csv file
    should be the easier part.
    BODY{font:x-small 'Verdana';margin-right:1.5em}
    .c{cursor:hand}
    .b{color:red;font-family:'Courier New';font-weight:bold;text-decoration:none}
    .e{margin-left:1em;text-indent:-1em;margin-right:1em}
    .k{margin-left:1em;text-indent:-1em;margin-right:1em}
    .t{color:#990000}
    .xt{color:#990099}
    .ns{color:red}
    .dt{color:green}
    .m{color:blue}
    .tx{font-weight:bold}
    .db{text-indent:0px;margin-left:1em;margin-top:0px;margin-bottom:0px;padding-left:.3em;border-left:1px solid #CCCCCC;font:small Courier}
    .di{font:small Courier}
    .d{color:blue}
    .pi{color:blue}
    .cb{text-indent:0px;margin-left:1em;margin-top:0px;margin-bottom:0px;padding-left:.3em;font:small Courier;color:#888888}
    .ci{font:small Courier;color:#888888}
    PRE{margin:0px;display:inline}
      <?xml
    version="1.0" encoding="iso-8859-1" ?>
     <Contents type="Data"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="XMLSection.xsd">
     <section name="beta"
    date="7/31/2009" time="3:43:03 PM" version="1.0">
     <Cluster>
      <Name />
      <NumElts>1</NumElts>
     <Array>
      <Name />
      <Dimsize>4</Dimsize>
     <DBL>
      <Name>number: 0 to 1</Name>
      <Val>0.93317638164326</Val>
      </DBL>
     <DBL>
      <Name>number: 0 to 1</Name>
      <Val>0.79233924020314</Val>
      </DBL>
     <DBL>
      <Name>number: 0 to 1</Name>
      <Val>0.39199947274518</Val>
      </DBL>
     <DBL>
      <Name>number: 0 to 1</Name>
      <Val>0.74817197429441</Val>
      </DBL>
      </Array>
      </Cluster>
      </section>
      </Contents>
    Attachments:
    read_array.vi ‏12 KB

  • Error while saving xml file using PDFDocument API

    Hi,
    I am trying to save xml file using byte array obtained from interactive form element in webdynpro java.
    The file gets saved but I get fllowing error message when I open the file.
    The XML page cannot be displayed
    Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
    An invalid character was found in text content. Error processing resource 'http://uxjciesk.wdf.sap.corp:50000/irj/go/km/doc...
    The code I am trying to achieve the functionality is:
    byte[] byteArray  = wdContext.currentContextElement().getPdfSource();
    IWDPDFDocumentHandler pdfDocumentHandler = WDPDFDocumentFactory.getDocumentHandler();
    IWDPDFDocumentAccessibleContext documentAccessibleContext = pdfDocumentHandler.getDocumentAccessibleContext();
    documentAccessibleContext.setPDF(byteArray);
    IWDPDFDocument pdfDocument = documentAccessibleContext.execute();
    ByteArrayInputStream dataInputStream = (ByteArrayInputStream) pdfDocument.getPDFAsStream();
    further, the datainputstream is used to store the file. I am able to save same xdp template in pdf file format successfully, the error only occurs for xml file storage.
    Please, advise.
    Regards,
    Urvashi

    Hi Urvashi,
        Try this code
              String contentStr = getXMLData(wdContext.currentContextElement().getPdfSource().read(false));
              String data = "";
              ByteArrayOutputStream pdfSourceOutputStream = new ByteArrayOutputStream();
              try {
                   InputStream pdfSourceInputStream = wdContext.currentContextElement().getData().read(false);
                   BufferedInputStream bufferedInputStream = new BufferedInputStream(wdContext.currentContextElement().getData().read(false));
                   int aByte;
                   while ((aByte = bufferedInputStream.read()) != -1) {
                        pdfSourceOutputStream.write(aByte);
                   pdfSourceOutputStream.flush();
                   pdfSourceOutputStream.close();
                   IWDPDFDocument pdfDocument = null;
                   try {
                        // Create an instance for PDFDocumnetHandler
                        IWDPDFDocumentHandler pdfDocumentHandler = WDPDFDocumentFactory.getDocumentHandler();
                        //Create an Inatance for PDFDocumentAccessibleContext
                        IWDPDFDocumentAccessibleContext documentAccessibleContext =     pdfDocumentHandler.getDocumentAccessibleContext();
                        //set the pdf data as OutputStream to the PDFDocumentAccessibleContext instance
                        documentAccessibleContext.setPDF(pdfSourceOutputStream);
                        //call the server to get the data                      
                        pdfDocument = documentAccessibleContext.execute();
                        //get the xml data in a InputStream
                        ByteArrayInputStream dataInputStream = (ByteArrayInputStream) pdfDocument.getData();
                   } catch (Exception e) {
                        data = "Null";
              } catch (IOException e) {
    Regards,
    Mathan

  • Read external xml file

    hi,
    I want to load (some of the) content of an xml file into an
    array. (actionscript in FLEX)
    I found an example at the flex documentation (
    over
    here
    but when i try this examle:
    quote:
    <mx:Script>
    <![CDATA[
    var myXML:XML = new XML();
    var XML_URL:String = "http://www.example.com/Sample3.xml";
    var myXMLURL:URLRequest = new URLRequest(XML_URL);
    var myLoader:URLLoader = new URLLoader(myXMLURL);
    myLoader.addEventListener("complete", xmlLoaded);
    function xmlLoaded(evtObj:Event) {
    myXML = XML(myLoader.data);
    trace("Data loaded.");
    ]]>
    </mx:Script>
    i get two errors:
    - 1120: Acces of undifined property myLoader.
    - 1120: Acces of undifined property mxLoaded
    Can anyone tell me how i can solve this problem?

    You can't do all that stuff outside a function. The variables
    do not exist until they all have been created during the object
    instantiation.
    Declare the variables in the global scope, then do the value
    assignments in a function, say initApp(), that you call in the
    creationComplete event on the Application tag.
    Tracy

  • AS3 & XML file reading in

    Is there a need to read a XMl file into an array or can you load an XML file and then call the information when its needed. EX.  I have an xml file that I want to load in and then when the user clicks on a button they information that is requeted loads in from the xml file.  So not all the information from the XML file is needed at the time of load.  Is this possible or should I load it into an array?

    Hope this will get you started:
    http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e72.html

  • How to change the attributes of an XML file

    hi peeps 'ope you can help me here i need to change the attributes of an xml file, i parse it first using a DOM parser but i cant find a way to change the attributes in the XML file, setAttribute() works only at runtime and doesn't change the attribute in the file itself. I can't find a method that will answer my question. I've searched through the forum and found similar threads....they say in order to write and change the attribute i must use the write() method of the XmlDocument class defined in com.sun.xml.tree.XmlDocument. But, i found another thread, and it says that com.sun.xml.tree.XmlDocument is not safe to use and i should use org.apache.crimson.tree.XmlDocument.....i can't find the XmlDocument class and the API for this package so i really dont know where to start...hope you guys can help me! thnx

    thanks for responding roland....i already found the solution...i didn't use the XmlDocument class because i can't find any documents about it except for JAXP 1.0 here is my code snippet...i used the TransformerFactory and Transformer class to write
    import org.w3c.dom.*;
    import org.w3c.dom.traversal.*;
    import javax.xml.parsers.*;
    import javax.xml.transform.*;
    import javax.xml.transform.dom.*;
    import javax.xml.transform.stream.*;
    Document doc = null;
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    dbf.setValidating(false);
    doc = db.parse(fileGetFile); //this is the XML file
    n1 = (Node)doc.getDocumentElement();
    e1 = (Element) n1;
    NodeList nodeList = doc.getElementsByTagName ("File");
    //just insert whatever you want to do with the XML...parse it..set/change the attribute..etc....sample snippet below changes the attribute downloaded to "no"
    for(int iWriteFailed = 0; iWriteFailed <nodeList.getLength() ; iWriteFailed ++){     
    n2 = nodeList.item(iWriteFailed);
    e2 = (Element) n2;          
    e2.setAttribute("downloaded", "no");}
    try{
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.transform(new DOMSource(doc), new StreamResult ( new FileOutputStream ( fileGetFile) ) );}
    catch(Exception trans){}
    thanks for responding and keeping the information interchange alive here in the forum...
    Pau

  • Editing XML File

    Any idea or url around for an example how to edit XML files
    with ASP.VB ?
    thanks fpr any reply
    Sebastian

    To modify an XML document obtain a DOM stucture of the XML file, select nodes with XPath expression, and modify nodes.
    http://otn.oracle.com/pub/notes/technote_domparser.html

  • Select Between two date ranges from xml file

    Hi ,
    I have a column date_ with datatype VARCHAR2(150) it stores
    data as
    05/19/2010 11:23 AM
    05/20/2010 12:23 PM
    05/22/2010 11:23 AM
    05/25/2010 11:23 AM
    i have to select all the rows between 05/19/2010 and 05/22/2010 how to do that this column is in xml file

    I have a table wit two fields
    Field1 is integer and field2 is xmltype
    in the xmltype i store an xml file
    <ParentNode>
    <Node>
    <Cat>1</Cat>
    <Date>05/19/2010 11:23 AM </Date>
    </Node>
    <Node>
    <Cat>2</Cat>
    <Date>05/20/2010 12:23 PM </Date>
    </Node>
    <Node>
    <Cat>3</Cat>
    <Date>05/22/2010 11:23 AM </Date>
    </Node>
    </Parentnode>
    I am using teh below query to retrive teh result
    SELECT T.Feild1, XML.* FROM Tablename T,
    XMLTable( 'Parentnod/Node' PASSING T.Feild2 COLUMNS Cat NUMBER PATH 'Cat' ,
    DATE_ VARCHAR2(100) PATH 'Date'
    )XML where cat >1;
    now i have to do teh same to select the rows between two date range 05/19/2010 and 05/21/2010
    hope i am able to make teh question simple

Maybe you are looking for

  • Oracle DB service - wrong credencials

    Hi, all. We've got a problem with communicating between web server (Win 2003, IIS 6) named WEB and DB server (Win 2003 Itanium, Oracle 10g 10.2) named ORACLE. DB service has to read the file from special folder at web server into BLOB using special d

  • DTW Template for SALES ORDERS

    Hi All,             Can anybody give me the name of the DTW template used for Sales Orders Updation.              I am Using SAP Business One 2005B version. Thanks and Regards, Sree.

  • Connection method

    Hi Hussein and Helios, What is the default connection method in ebs whether shared server or dediacted server? can i change that? Edited by: user3266490 on Feb 26, 2010 8:11 PM

  • Wont detect sd card after windows 8 upgrade

    Hi I need help.  My HP Pavilion M7 1015dx wont read/detect any SD card after I upgraded to Windows 8.

  • Audio-input failure

    Hi all I used to record guitar tracks on Garageband using my guitar which was plugged into the audio-in port on my macbook. I think I may have overloaded it one day because now whenever I try the same set-up all I get is a loud tapping noise whenever