Page 1 of 1

Reading a XML file

Posted: 15 Mar 2014, 20:56
by gilligan
Hi,

I have to parse a XML file like the below example. First I tried with the Ventuz-Node but that doesn't work properly. The problem is that the number of fields in each entry can be different (like in the example).

With .Net I wrote a small program that works very well, but the code doesn't work in the Ventuz script node because I used an array like this:
struct feed {
private string Vorname;
private string Nachname;
private string Beruf;
private string Hobby;
private string Alter;
}
feed[,] entry;


So, my questions.
1. Is there a trick to do it with the Ventuz xml node?
2. Can I do it with the Ventuz script node if there is a way to output the values of the array?

Regards
Gill


----------------------------------------------------------
XML File
----------------------------------------------------------
<myXML>
<entry>
<field name="Vorname">
Harald
</field>
<field name="Nachname">
Holz
</field>
<field name="Beruf">
Zimmermann
</field>
<field name="Hobby">
Segeln
</field>
<field name="Alter">
32
</field>
</entry>

<entry>
<field name="Vorname">
Dirk
</field>
<field name="Nachname">
Meier
</field>
<field name="Beruf">
Angestellter
</field>
</field>
<field name="Alter">
25
</field>
</entry>

<entry>
<field name="Vorname">
Kai
</field>
<field name="Nachname">
Schlösser
</field>
<field name="Beruf">
Kapitän
</field>
<field name="Hobby">
Angeln
</field>
<field name="Alter">
60
</field>
</entry>
</myXML>

Re: Reading a XML file

Posted: 17 Mar 2014, 14:14
by SamTheSwede
You have two consecutive </field> in the second entry, but I don't think that is your real problem?

You should use XPath nodes to search for the attribute names and you will not go wrong. See attached example!

All the best,

Sam

Re: Reading a XML file

Posted: 17 Mar 2014, 22:03
by gilligan
Hi Sam,
thank you for your quick response. It was very helpful and I learned a lot about the features of XPATH. So I can do XML parsing only with Ventuz functions - great!

Regards
Gill