LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read/get xml data (string)

Hi
 
I have a XML string that I get from a TCP transfer, I have attached a received string.
I have no experience in reading XML data, I have tried looking in the forums and some of the examples in LV, but I cannot get it to work, so I hope that someone could help me out. All I need to get from the XML data are the names e.g. Station1 and Station2 perhaps putted into a string array. If so it wouldn't hurt to get all the rest parameters and attributes as well. I thought about doing some string searches to get what I need, but thought again that it might be easier/better in some way to take advantage of the data being arranged as XML.
 
Hope that someone can help.
Thanks in advance
 
Best regards
Simon
LabVIEW 8.6 / 2009 / 2010
Vision Development Module 8.6 / 2009 / 2010
VBAI 3.6 / 2010
0 Kudos
Message 1 of 13
(10,761 Views)

The easy way is if you know that this string is not changing much you treat it as a formated string and parse it using simple string functuions

ie first parse <Stations>%s<//Stations> and <Edges>%s<//Edges> The two slashes will cancle the escape clause of the string parser.  Repete this process to get each station and attributes.

 

The harder way is to use an activeX or .net XML parser.

 

Paul

 



Message Edited by falkpl on 03-04-2008 10:53 AM
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 2 of 13
(10,740 Views)
or you may try using this...looks like that exactly what you need
BR
0 Kudos
Message 3 of 13
(10,730 Views)
Hi Simon,

As A.K. mentioned, EasyXML is probably a great solution for your needs, as it's very easy to use and doesn't require much (if any) knowledge of XML.  Let me know if you have any questions.

A.K., Thanks for mentioning my blog post.  I'm glad to see that people are reading it 🙂

Thank you,

-Jim
0 Kudos
Message 4 of 13
(10,716 Views)
Hi all

falkpl wrote:

The easy way is if you know that this string is not changing much you treat it as a formated string and parse it using simple string functuions
ie first parse %s and %s The two slashes will cancle the escape clause of the string parser.  Repete this process to get each station and attributes.
The harder way is to use an activeX or .net XML parser.

Paul


I am not sure what you mean about the parser, well I get the concept, but is there a specific string function that can do that for me?
I got something working with the Match Pattern vi, please the attached. This actually works for my current needs, but I still would be able to get data from more complex XML data.
 
 
Hi A.K. and J.K.
 
Thank you for the link.
EasyXML looks like a nice and handy tool for handling XML data. I ran in too some problems though when running the VI Package Manger. When I check the network for new packages it says that there was an error, please check the network connection or settings. I have internet connection (I am writing this post 🙂 ) and I am not using a proxy server. What could be wrong and how do I install EasyXML then, is there another way?
 
Best regards
Simon
LabVIEW 8.6 / 2009 / 2010
Vision Development Module 8.6 / 2009 / 2010
VBAI 3.6 / 2010
0 Kudos
Message 5 of 13
(10,686 Views)
sorry I was a little tired yesterday.  Yes match pattern will make a simple XML parser.
 
Match the first <tag [optional attributes]>
Take string after match and match <\tag> then the string in the middle is the elements inner text.  XML is a well formatted language so parsing is easy.  I hav never used the easyXML toolkit so I cant vouch for it but know that Jim is very will respected in our community.  I have made a simple vi in the past that takes a string tag name and returns an array or string arguments and the inner text of element or nothing if the tag is not matched.  Parsing XML is not hard.  use scan from string to convert your attribute values to floats and ints or even enums, this is not a problem either.
 
paul
 
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 6 of 13
(10,665 Views)
Parsing XML easy? I don't think so. If you consider every aspect of XML, it
is in fact very difficult.

Nodes can be closed in two ways, they can be nested, have attributes, and
could have spaces in several unexpected places... And there is a lot more
than simple nodes (CDATA, entity references, processing instuctions,
comment, to name a few).

If parsing means finding some node's value in a XML string with known
format, then yes, it's not very difficult.

If you still think it's easy, post your VI. It is probably not very easy, or
it will not work correctly for every XML file.

Regards,

Wiebe.


0 Kudos
Message 7 of 13
(10,656 Views)
Simon,

I'm sorry to hear that you're having trouble getting VIPM to connect to the Internet.  One simple solution might be to check if you have firewall or Internet security software running on your machine -- if so, try turning that off.  If you are still having problems, please contact our customer support department here.  We'll help you get up and running, so that you can evaluate EasyXML.

Thanks,

-Jim Kring
0 Kudos
Message 8 of 13
(10,651 Views)

Parsing the complete XML is not easy I am talking about parsing a specific XML string that is known.  I am not saying that Writing a complete XML Parser is easy.  Sorry fpr the confusion.  I still think that parsing known simple XML string to extract a few predefined values and attributes is not hard to do such as the initial XML string posted in this thread.  This is what I based my answer on.  If you have a vary complex XML schema or doc then use a fullblown parser.

Paul

 

 

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 9 of 13
(10,644 Views)


@falkpl wrote:
sorry I was a little tired yesterday.  Yes match pattern will make a simple XML parser.
 
Match the first
Take string after match and match <\tag> then the string in the middle is the elements inner text.  XML is a well formatted language so parsing is easy.  I hav never used the easyXML toolkit so I cant vouch for it but know that Jim is very will respected in our community.  I have made a simple vi in the past that takes a string tag name and returns an array or string arguments and the inner text of element or nothing if the tag is not matched.  Parsing XML is not hard.  use scan from string to convert your attribute values to floats and ints or even enums, this is not a problem either.
 
paul
 



Hi Paul,

I agree with Wiebe -- parsing xml might seem relatively straight-forward at first, but beyond the trivial case, one will quickly find that there's a lot to consider and can become overwhelmed.

Also, I'd love it if you gave EasyXML a try and let us know what you think 🙂  We're looking to get feedback and would appreciate hearing your opinion.

Thanks,

-Jim
0 Kudos
Message 10 of 13
(10,643 Views)