Hello Ventuzians!
THE FORUMS ARE CLOSED!

Please join our discord server HERE!! << click me :D

We are shutting our Ventuz Forum, but don't worry, it will all be archived for you to search in if you have a query. From now on, please add all your comments, questions or observations into our Discord Server

Thanks for the great time - see you on discord!!
Dee, Karol, Daniel and the whoooole Product and Support team!

Reading a XML file

Q and A about functionality and how to solve a special task for your application.

Moderator: Support

Post Reply
gilligan

Reading a XML file

Post by gilligan » 15 Mar 2014, 20:56

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>

SamTheSwede
Posts: 91
Joined: 18 Jan 2012, 11:31

Re: Reading a XML file

Post by SamTheSwede » 17 Mar 2014, 14:14

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
Attachments
Step-through-xml.vza
(18.75 KiB) Downloaded 295 times

gilligan

Re: Reading a XML file

Post by gilligan » 17 Mar 2014, 22:03

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

Post Reply