Jump to content

Generate XML without empty elements


Richard

Recommended Posts

I am new to easyXML. My general plan is to have a big cluster representing my XML schema then as data is acquired use bundle by name to build up the XML tree as in the attached example.

 

The problem with this is that (as with most XML schemas) some of the elements and attributes are optional. However easyXML will always generate an empty element/attribute, even if I have not set it specifically using bundle by name. This means that I have to make a custom big cluster (on the right in the attached example) for each application rather than a general one for the whole schema and also it is not possible to omit a particular element mid way through the acquisition.

 

One work around would be to post-process the generated XML, removing all empty elements and attributes but it seems there should be a better way.

 

Example output:

 

<instrument name="g">

<sensor name="0" domain="">

<measurement>

<value>69.552698</value>

<time format="">0</time>

</measurement>

<measurement>

<value>47.426282</value>

<time format="">1</time>

</measurement>

</sensor>

<sensor name="1" domain="">

<measurement>

<value>38.743544</value>

<time format="">0</time>

</measurement>

<measurement>

<value>88.500381</value>

<time format="">1</time>

</measurement>

</sensor>

</instrument>

post-2574-1239774276_thumb.png

Link to comment
Share on other sites

Hi Richard,

 

You're right, in that there isn't a way to specify a data structure in LabVIEW that generates XML data where empty elements are optional (and omitted from the XML). One way to achieve this would be to dynamically generate the variant input to Easy Generate XML function using the OpenG LabVIEW Data Tools library.

 

Another option might be to post-process the XML data (as you suggested). You can remove empty tags, fairly easily using the "Find and Replace String" function in regular expression mode, using a regular express for valid empty tags. Removing empty attributes would be a little bit more difficult.

 

Thanks,

 

-Jim

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.