LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

XML

Solved!
Go to solution

Hello,

I have problems to get the requested informations from a XML File.
I use Lab View 2019 32 Bit.
The XML File contains the configuration of the different interfaces.
Depending on the interface type (RS232, GPIB, Ethernet) different parameters are saved.
Because Lab View does not maintain unions, an array of Clusters with all the possible interface parameter is created to save the requested parameters. If I run XML_Parser_2.vi, in the cluster Array are 3 times the parameters of the first Interface stored. If I add an additional Interface into the XML File, than the result cluster array contain 4 x the datas of the first interface. This fact I can not understand. How can I get the reference of all the interface from XML File into an Array? Or how can I step from first interface reference to the next and so on until the end is reached? Does somebody has an idea how I can solve this? 

With the upper small for loop I get all the device of interface from XML File. The for loop at the bottom does not work as required (but without any errors).

domare_0-1646487136810.png

 

0 Kudos
Message 1 of 9
(1,171 Views)

I have done something similar to what you are trying to do here, and I believe there is a problem with your XML file format.

 

You have to think of XML as a tree:

 

You have:

  • Interfaces
    • Interface
      • Index
      • Type
      • Etc...
    • Interface
      • Index
      • Type
      • Etc...
    • Interface
      • Index
      • Type
      • Etc...

I think that is confusing XML parser because how can it determine the difference between:

 

Interfaces.Interface.Index 0... and Interfaces.Interface.Index 1...?

 

 Your format should be something like:

  • Interfaces
    • Interface_0
      • Index
      • Type
      • Etc...
    • Interface_1
      • Index
      • Type
      • Etc...
    • Interface_2
      • Index
      • Type
      • Etc...

Here's an example of my test rack config file

 

 

 

 

<?xml version="1.0" encoding="utf-8"?>
<Test_Rack_Configuration>
  <AC_Source>
    <Type>
      <!--Valid AC_Source values are "Ci5001" "Elgar" "none"-->
      <!--***For CSW5550 use "Ci5001"***-->Ci5001</Type>
    <VISA>
      <!--VISA Resource or VISA Alias-->TCPIP0::192.168.0.7::inst0::INSTR</VISA>
    <Vout>
      <!--Output voltage range (VAC)-->
      <Max>300</Max>
      <Min>0</Min>
    </Vout>
    <Freq>
      <!--Output voltage range (Hz)-->
      <Max>70</Max>
      <Min>40</Min>
    </Freq>
    <Iout>
      <!--Output current range (Aac) -->
      <!--Enter Output current range for AC Source-->
      <!--This is IMPORTANT!  The Safe Operating Limits uses this value to set default AC input trip levels!-->
      <!--For Ci5001iX 150V range = 30 Amps 300V range= 15 Amps-->
      <!--Iout Max will also be use to set the current limit of the AC source-->
      <Max>30</Max>
      <Min>0</Min>
    </Iout>
  </AC_Source>
  <AC_Load>
    <Type>
      <!--Valid AC_Load values are "Ci3091" "NHR" "none"-->NHR</Type>
    <VISA>
      <!--VISA Resource or VISA Alias Ignored for NHR-->
    </VISA>
    <Vin>
      <!--Input voltage range (Vrms)-->
      <Max>350</Max>
      <Min>50</Min>
    </Vin>
    <Freq>
      <!--Input frequency range (Hz)-->
      <Max>440</Max>
      <Min>45</Min>
    </Freq>
    <CC>
      <!--Load current range (Arms) constant current mode-->
      <!--To enable short circuit testing set Min to -1-->
      <Max>30</Max>
      <Min>0</Min>
    </CC>
    <CV>
      <!--Load voltage range (Vrms) constant voltage mode-->
      <Max>350</Max>
      <Min>50</Min>
    </CV>
    <CP>
      <!--Load power range (Watts) constant power mode-->
      <Max>3000</Max>
      <Min>0</Min>
    </CP>
    <CR>
      <!--Load resistance range (Ohms) constant resistance mode-->
      <Max>1000</Max>
      <Min>2.5</Min>
    </CR>
  </AC_Load>

 

  • Test_Rack_Configuration
    • AC_Source
      • Type
      • VISA
      • Vout
        • Max
        • Min
      • Freq
        • Max
        • Min
      • Iout
        • Max
        • Min
    • AC_Load
      • Type
      • VISA
      • Ect...
    • DC_Source
      • Type
      • VISA
      • Etc...
    • Etc...

The path of all my XML tags is clear, concise, easily parsed and mapped to a cluster.

 

Test_Rack_Configuration.AC_Source.Type = Ci5001

Test_Rack_Configuration.AC_Source.VISA = TCPIP0::192.168.0.7::inst0::INSTR

Test_Rack_Configuration.AC_Source.Vout.Max = 300

Test_Rack_Configuration.AC_Source.Vout.Min = 0

...

 

 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 2 of 9
(1,115 Views)

@domare wrote:

If I add an additional Interface into the XML File, than the result cluster array contain 4 x the datas of the first interface. This fact I can not understand.

 


The "Insert into Array" function fails silently when the input index is out of range of the input array. Play around with the "Index" to see it in action:

LLindenbauer_0-1646650950096.png

 

The solution would be to use "build array" instead and keep track of the index in another way.

 

Message 3 of 9
(1,095 Views)

I have noticed another possible error (I can't check, I can't open your files):

 

Your XPaths inside the loop should probably be "./Index" and "./Type" instead of the path from the root. Check https://en.wikipedia.org/wiki/XPath#Axis_specifiers

 

0 Kudos
Message 4 of 9
(1,075 Views)

Thank you very much for your post. I attach the files unzipped. Because it was not possible to send the XML File TestConfiguration.XML I added the content of this file hereinafter.

Best regards

0 Kudos
Message 5 of 9
(1,019 Views)

Hello ,

thank you very much for your post. This could be the problem because all interface have the same name interface. But how can I get the references to the datas if the interface changed  to Interface_0, Interface_1 and so on? Are place holder available ?

How would you make the query if you had 2 AC Sources?  

 

Test_Rack_Configuration

  • AC_Source_0
    • Type
    • VISA
    • Etc...
  • AC_Source_1
    • Type
    • VISA
    • Etc...

How would be your XPath Expression to get the Reference to AC_Source_0 and AC_Source_1 in an Array? 

/Test_Rack_Configuration/AC_Source_*

 

Best regards

0 Kudos
Message 6 of 9
(1,050 Views)

@domare wrote:

 

Test_Rack_Configuration

  • AC_Source_0
    • Type
    • VISA
    • Etc...
  • AC_Source_1
    • Type
    • VISA
    • Etc...

How would be your XPath Expression to get the Reference to AC_Source_0 and AC_Source_1 in an Array? 

/Test_Rack_Configuration/AC_Source_*

 

Best regards


/Test_Rack_Configuration/*

 

You can also use the "starts-with" function.

 

I don't think that will solve your problem, though.

0 Kudos
Message 7 of 9
(1,031 Views)

@domare wrote:

Hello ,

thank you very much for your post. This could be the problem because all interface have the same name interface. But how can I get the references to the datas if the interface changed  to Interface_0, Interface_1 and so on? Are place holder available ?

How would you make the query if you had 2 AC Sources?  

 

Test_Rack_Configuration

  • AC_Source_0
    • Type
    • VISA
    • Etc...
  • AC_Source_1
    • Type
    • VISA
    • Etc...

How would be your XPath Expression to get the Reference to AC_Source_0 and AC_Source_1 in an Array? 

/Test_Rack_Configuration/AC_Source_*

 

Best regards


I would simply have AC_Source_0, AC_Source_1...etc.

 

I do my XML Parsing a little different. I search for the XML tags by level and put the value returned into a cluster.

 

XML1Capture.PNG

XML2Capture.PNG

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 8 of 9
(1,014 Views)
Solution
Accepted by topic author domare

Hello,

thank you very much for your help.

 

I found a solution to my difficulties. Although the bigger for loop steps trough all the Interface references, the Get First Matched Node.vi always give the reference of the first Node back.

With the changed XPath String 

domare_4-1646782982454.png

in the for loop, the Function of the VI works as requested.

 

domare_5-1646783169610.png

 

 

domare_0-1646782351806.png

Thanks to all which helped me to find a solution!

 

Best regards 

 

Message 9 of 9
(992 Views)