LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

regular expression for xml tags

Solved!
Go to solution

Dear clever people of the labview world,

 

I have a question regarding how to match element names in xml text.

 

Image I have some xml, for example:

 

<person name="Jeff">

 <son>Peter</son>

 <grandSon name="Alfred">

<age>13</age>

 </grandson>

</person> 

 

and I want to match all element names, i.e: person, son, grandSon, age, regardless of any attribute these elements have. Is there a regular expression, I can loop, that can do this? (Something like " \<.+\> ". This one is no good because it matches the whole xml string.) I would really like two different expressions, one for matching start elements, e.g. <person...> and one for matching end elements, e.g. </person>.

 

Thanks for your help in advance!

Paul. 

 

 

0 Kudos
Message 1 of 7
(14,269 Views)
p.s. I am using labview 8.5.
0 Kudos
Message 2 of 7
(14,267 Views)
Perhaps I'm misunderstanding your question, but you may just want to use a Read from XML File VI and use a For Loop to auto-index the elements to find what you're looking for. This would be similar to the Read Data from XML File example found in the example finder.
Will
CLA, CLED, CTD, CPI
LabVIEW Champion
Choose Movement Consulting
choose-mc.com
0 Kudos
Message 3 of 7
(14,237 Views)

Thanks for your reply!

 

It is not an xml file that follows the labview xml schema. So Read from xml file.vi does not work.

 

Paul. 

0 Kudos
Message 4 of 7
(14,228 Views)
Solution
Accepted by topic author labJunky

The site Regular-Expressions will be very handy.

They have some good tutorials on regexp, with a demo for XML tags:

 

Here's a little excerpt:

 

The regex <\i\c*\s*> matches an opening XML tag without any attributes. </\i\c*\s*> matches any closing tag. <\i\c*(\s+\i\c*\s*=\s*("[^"]*"|'[^']*'))*\s*> matches an opening tag with any number of attributes. Putting it all together, <(\i\c*(\s+\i\c*\s*=\s*("[^"]*"|'[^']*'))*|/\i\c*)\s*> matches either an opening tag with attributes or a closing tag.  (source)

 

If you want advanced XML parsing I suggest JKI XML toolkit.

 

Ton

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Message 5 of 7
(14,213 Views)

Thanks very much Ton, thats very useful!!!

 

0 Kudos
Message 6 of 7
(14,200 Views)

Hi Paul,

 

This is a perfect use case for EasyXML. It's a commercial product that I helped write.

 

Thanks,

 

-Jim 

0 Kudos
Message 7 of 7
(14,178 Views)