04-06-2009 08:54 AM
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.
Solved! Go to Solution.
04-06-2009 08:55 AM
04-07-2009 10:54 PM
04-08-2009 02:41 AM
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.
04-08-2009 06:48 AM
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
04-08-2009 08:21 AM
Thanks very much Ton, thats very useful!!!
04-08-2009 08:57 PM
Hi Paul,
This is a perfect use case for EasyXML. It's a commercial product that I helped write.
Thanks,
-Jim