From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Forum Italiano sui Prodotti NI

annulla
Visualizzazione dei risultati per 
Cerca invece 
Intendevi dire: 

what is #text name for a node, parsing an xml file?

my purpose is to parse an xml file and put its own structure (tree) in a tree indicator.

Then I want to select from the tree the elements i'm interested in and copy them in another file.

 

by now I have written the code which put the xml structure in the tree but instead of the actual value of the elements i get "#text" as you can see in the picture. what does it mean? Which function should i use to get the value without having that result?

 

I'attaching my vi, I used a recursive vi to parse all the xml file.

This is how the xml looks like:

 

 

<section name="beta" date="7/31/2009" time="3:43:03 PM" version="1.0">
   <Cluster>
      <Name />
      <NumElts>7</NumElts>
-     <Array>
          <Name />
          <Dimsize>2</Dimsize>
          <Dimsize>4</Dimsize>
-        <DBL>
                  <Name>number: 0 to 1</Name>
                  <Val>1.43163770585081</Val>
      </DBL>
-        <DBL>
                  <Name>number: 0 to 1</Name>
                  <Val>1.26232847139484</Val>
      </DBL>
-       <DBL>
                  <Name>number: 0 to 1</Name>
                  <Val>1.68462668947382</Val>
     </DBL>

 .......

Scarica tutti
0 Kudos
Messaggio 1 di 10
8.605Visualizzazioni

Hi DiegoDC,

I'm working on your issue. Can you post the xml file that generates the screenshoot you sent?

Thanks

Fabio M.
NI
Principal Engineer
0 Kudos
Messaggio 2 di 10
8.598Visualizzazioni

Of course

there you go

thank you

Scarica tutti
0 Kudos
Messaggio 3 di 10
8.594Visualizzazioni

Hi DiegoDC,

 try to add "Decimate 1D Array" in getchildren_t.vi like attachment.

Does this resolve your problem?

D. Beninato
0 Kudos
Messaggio 4 di 10
8.582Visualizzazioni

Thank you, very simple and effective solution.

But where do these "#text" nodes come from? I'm concerned this solution may not work in general or may leads to loss of data.

 

Another problem: using the Get Node Text vi I'm trying to populate the second column with the corresponding values of the nodes in the tree.

Unfortunately I got unexpected new lines and I don't know how to fix it.

 

One question more: after I populated my tree, how can I let the user select from front panel one node and get its content and for instance return that value to an application which print it out on a csv file?
0 Kudos
Messaggio 5 di 10
8.555Visualizzazioni
sorry I forgot to attach my vi
Scarica tutti
0 Kudos
Messaggio 6 di 10
8.554Visualizzazioni

The "#text" nodes correspond to xml tags that have not text but only other xml tags.

You have to check if the node has any subnode to avoid the "#text" node.

 

I think the white spaces came from the node that has not text but you add to the tree.

 

I can give you one suggestion:

working in labview with XML is quite hard. Why don't you use Labview Schema? If you formatting your xml file like Labview does you can use the Labview schema function and convert any xml data in cluster.

 

In order to export subtree you have to check which row the user select with a property node, navigate though the subnode, formatting the text and write it on a cvs file.

D. Beninato
0 Kudos
Messaggio 7 di 10
8.539Visualizzazioni

I solved the problem of new lines with "Trim Whitespace VI"

 

unfortunately I'm supposed to use another schema, but now with your help I think I.m almost done with this vi.

 

I want to put the build tree vi and the convert to csv vi in a main vi, i'm using the event structure. one button to build the tree and select the section and another button to convert into csv.

 

now I have to pass my tree from the build_tree vi to a main vi. when I run it, it happen that the tree in the main vi is not updated, where is the problem?

Scarica tutti
Messaggio 8 di 10
8.533Visualizzazioni

Hi Diego,

how do you pass data about the tree?

D. Beninato
0 Kudos
Messaggio 9 di 10
8.511Visualizzazioni

I was trying to pass it as a string...then I tried by reference and it did work.

Thank you. 

 

 

0 Kudos
Messaggio 10 di 10
8.500Visualizzazioni