LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Extract a string from a string

Solved!
Go to solution

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

 

 

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

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...

0 Kudos
Message 2 of 9
(1,100 Views)

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

0 Kudos
Message 3 of 9
(1,095 Views)

Hello, Yes i used the CVIXML Functions but i could'nt find one to do what i want ...

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

Why I can't do with sscanf ?

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

@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?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 9
(1,078 Views)

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 

0 Kudos
Message 7 of 9
(1,073 Views)
Solution
Accepted by topic author estelle27

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 8 of 9
(1,067 Views)

Okay thanks a lot !

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