Jump to content

Use XSD file and EasyXML to extract data from XML file


shabu

Recommended Posts

I have been provided with an XSD file and an XML file with the some Data that I am interested in. How do I use the XSD file with EasyXML toolkit to extract the data. The data is buried in various layers of the file so if I can use the XSD file somehow it will really help me out.

 

I am completely novice to XML so it may sound very basic.

 

Any help will be appreciated.

Link to comment
Share on other sites

I have been provided with an XSD file and an XML file with the some Data that I am interested in. How do I use the XSD file with EasyXML toolkit to extract the data. The data is buried in various layers of the file so if I can use the XSD file somehow it will really help me out.

 

I am completely novice to XML so it may sound very basic.

 

Any help will be appreciated.

 

You shouldn't need the XSD file to extract the data in the XML file. Can you post your XML file? That would make helping you out a lot easier :)

Link to comment
Share on other sites

You shouldn't need the XSD file to extract the data in the XML file. Can you post your XML file? That would make helping you out a lot easier :)

 

I did post it on NI's forum since they dont have a size limit. Here is another question: from the examples provided with JKI EasyXML it seems like that if I have a Cluster control setup in Labview that corresponds to the Data in XML then the JKI routines can populate that cluster.

Is that assumption correct. If it is, then how will a corresponding Cluster look like for following code?

 

<structure>

<field name="Header" datatype_id="5171" datatype_name="HistDataStreamHeaderT">

<structure>

<field name="StreamStartLRTS" datatype_id="3815" datatype_name="LowResSyncTimestamp">

<value alt_value="0x97C" value="2428"></value>

</field>

<field name="StreamEndLRTS" datatype_id="3815" datatype_name="LowResSyncTimestamp">

<value alt_value="0x9A0" value="2464"></value>

</field>

<field name="StreamDataType" datatype_id="4993" datatype_name="StreamDataTypeT">

<value alt_value="STREAM_ANALOG_DATA" value="0"></value>

</field>

<field name="NumberOfBlocks" datatype_id="3701" datatype_name="UnsignedInteger">

<value alt_value="0xB" value="11"></value>

</field>

<field name="StartBlockID" datatype_id="4066" datatype_name="MemoryBlockIDT">

<value alt_value="0" value="0"></value>

</field>

<field name="StreamRequestorList" datatype_id="4306" datatype_name="(UnsignedInteger)[1]">

<collection datatype_id="3701" datatype_name="UnsignedInteger">

<element index="0">

<value alt_value="0x1" value="1"></value>

</element>

</collection>

</field>

<field name="PrevStreamHeaderBlkID" datatype_id="4066" datatype_name="MemoryBlockIDT">

<value alt_value="0xFFFF" value="65535"></value>

</field>

<field name="NextStreamHeaderBlkID" datatype_id="4066" datatype_name="MemoryBlockIDT">

<value alt_value="0x1" value="1"></value>

</field>

<field name="SubHeader" datatype_id="5105" datatype_name="DataStreamSubHeaderT">

<structure>

<field name="AnalogStreamSubHeader" datatype_id="5037" datatype_name="AnalogStreamSubHeaderT">

<structure>

<field name="Channel" datatype_id="3726" datatype_name="AnalogDataChannelT">

<value alt_value="RA_200" value="0"></value>

</field>

<field name="NumberOfSamples" datatype_id="3701" datatype_name="UnsignedInteger">

<value alt_value="0x11F6" value="4598"></value>

</field>

<field name="SyncTimestamp" datatype_id="3847" datatype_name="SynchTimestamp">

<value alt_value="0x7C36" value="31798"></value>

</field>

<field name="BytesPerSample" datatype_id="3701" datatype_name="UnsignedInteger">

<value alt_value="0x1" value="1"></value>

</field>

<field name="TicsPerSample" datatype_id="3701" datatype_name="UnsignedInteger">

<value alt_value="0x2" value="2"></value>

</field>

<field name="CompressionScheme" datatype_id="4421" datatype_name="DataCompressionSchemeIDT">

<value alt_value="FIRST_ORDER_DIFF_AND_HUFFMAN" value="1"></value>

</field>

</structure>

</field>

</structure>

</field>

<field name="Crc" datatype_id="4059" datatype_name="CrcT">

<value alt_value="0xDFD277B3" value="3755112371"></value>

</field>

</structure>

</field>

Link to comment
Share on other sites

Hi Shabu,

 

This can be a complex problem, because your data structure is highly compound and recursive. What I mean is that you have structure elements which can contain one or more field elements, which can contain structure, value, or collection elements. A collection contains one or more ordered value elements (with the order defined by the index attribute).

 

The tricky part of this is that creating a tool for parsing this data in a generic way might be nearly as complex as the code under the hood of the EasyXML tool, itself (however, you might not need a generic parser, but a specific parser that expects files with certain fixed structure). What I mean, is this:

 

The XML format that you're trying to parse seems to be a schema for storing arbitrary data from some other programming environment (or data storage system) -- it's not really an application-specific XML schema.

 

For example, your XML format uses:

 

 

instead of:

 

2428

 

Bottom line: your XML format is designed for storing arbitrary field names and types.

 

Now, if you have a specific file or data structure that doesn't change, you can probably create a parser than can extract the data that you are looking for. For example, here is a VI that parses the XML that you posted (note that I had to add a trailing "" tag, in order to make the XML structure valid).

 

Parse_Example_XML.vi

 

1.png

 

What you'll then need to do is traverse this structure to find the fields with the names that you care about and then find the values of those fields.

 

Let me know if this helps you out.

 

Thanks,

 

-Jim

Link to comment
Share on other sites

It indeed is very complicated. In your example, the parsed cluster didnt capture

 

<field name="Channel" datatype_id="3726" datatype_name="AnalogDataChannelT">

<value alt_value="RA_200" value="0"></value>

</field>

 

Is there a method to this madness, how did you create the cluster by looking at the xml code. Is there somewhere I can read up on this stuff?

 

All I care for in the entire XML file is the Channel field and the analog data that comes with every channel. Were you able to look at the entire XML file? You can search for the tag <analog_data_samples> to find out where the raw data is stored in the file.

Link to comment
Share on other sites

Hi Shabu,

 

It indeed is very complicated. In your example, the parsed cluster didnt capture

 

 

Here is a version that fixes this:

 

Parse_Example_XML_2.vi

 

Is there a method to this madness, how did you create the cluster by looking at the xml code. Is there somewhere I can read up on this stuff?

 

Yes, the documentation for how to create the LabVIEW structures that map to XML data is here:

 

http://jkisoft.com/easyxml/docs/#Detailed_Documentation

 

All I care for in the entire XML file is the Channel field and the analog data that comes with every channel. Were you able to look at the entire XML file? You can search for the tag to find out where the raw data is stored in the file.

 

Yes, I have a copy of your XML file. Can you be more specific about your requirements? The "Channel" field does not seem to be directly associated with the "" tag. How are you intending to traverse the data?

 

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.