Jump to content
Richard

Generate XML without empty elements

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

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