06-30-2022 08:40 AM
Hello !
So here's the thing : i made a XML file with lots of data, i want to extract all of the data in the root element .
For example my file is :
"<?xml version="1.0" encoding="UTF-8"?>
<root>
<city>Paris</city>
<weather>sunny</weather>
</root>"
and i want to have in a buffer:
"<city>Paris</city>
<weather>sunny</weather>"
How can I do that ?
Thanks in advance
Solved! Go to Solution.
06-30-2022 03:29 PM
Whatever you do, don't do that with sscanf !!!
Use an XML C library, there are many (I don't think there's one that comes with CVI): expat, libxml2...
07-01-2022 12:56 AM
Hi,
actually there is an instrument driver (library), you can find it in your CVI folder in toolslib\toolbox\cvixml.fp
Online help is here
07-01-2022 01:00 AM
Hello, Yes i used the CVIXML Functions but i could'nt find one to do what i want ...
07-01-2022 01:22 AM
Why I can't do with sscanf ?
07-01-2022 01:37 AM - edited 07-01-2022 01:38 AM
@estelle27 ha scritto:
Hello, Yes i used the CVIXML Functions but i could'nt find one to do what i want ...
Of course: XML (and CVIXML makes no exception) is intended to extract the information "Paris" from "city" tag. And when the XML file is a little more complex that the one you showed us, using the library is the better and fastest way to extract the exact information you need.
I mean, you could scan the file line by line and find <city> tag, but what happens if more records are present each with its proper <city> tag? You'd have to find the parent of each one and select the correct one to use... ultimately you'll be ending up in rebuilding your own XML parser!
Is there a specific reason for dealing with <city>Paris</city> instead of Paris?
07-01-2022 01:45 AM
Hello ! Yes there is a specific reason for that.
I have multiple XML files ( let's say that each XML file is for a country) they are like that :
<?xml version="1.0" encoding="UTF-8"?>
<root>
<city>Paris</city>
<weather>sunny</weather>
*other elements*
</root>
And i have to do a giant xml file with every country in it :
<?xml version="1.0" encoding="UTF-8"?>
<root>
<country>
<city>Paris</city>
<weather>sunny</weather>
*other elements*
</country>
<country>
<city>London</city>
<weather>cloudy</weather>
*other elements*
</country>
</root>
So what i wanted to do was going to a single country XML file, pick up what's inside the root element and create a new xmlfile and place it inside the "country" element
I don't know if it's understandable, I'm sorry for my english
07-01-2022 02:28 AM
Ok, you could do it using CVIXML library! Take a look at xmlTree.cws example: it will show you how to read a generic XML file and extract all tags and values in it. Starting from that, you can then open the destination xml file and insert those informations in that one.
07-01-2022 02:37 AM
Okay thanks a lot !