Jump to content

Receiving unknown xml data


Recommended Posts

(This question grew out of my question on this thread.)

I'm not all that familiar with XML so maybe this question is a little stupid...

When using the Unflatten From XML vi, why is there a requirement to define the type being received? The xml data already has the type information embedded in it. As near as I can tell this requirement means I must know what data I'm going to receive before actually receiving it.

Link to comment

QUOTE(Daklu @ Aug 23 2007, 04:05 AM)

(This question grew out of my question on http://forums.lavag.org/Connecting-Labview-and-Java-t8892.html' target="_blank">this thread.)

I'm not all that familiar with XML so maybe this question is a little stupid...

When using the Unflatten From XML vi, why is there a requirement to define the type being received? The xml data already has the type information embedded in it. As near as I can tell this requirement means I must know what data I'm going to receive before actually receiving it.

Well that's because LabVIEW is early binding, meaning that it needs to know every datatype before compiling.

And I believe XML doesn't store the datatype inside the XML file (it can sometimes, like NI does).

Ton

Link to comment

There is a nice library that works with the MSXML toolkit. It's called LabXML and is located at: http://labxml.sourceforge.net/. I've tried fooling around with it a bit and it does have all the functions necessary to navigate an xml document, even test it against a DTD or XML Schema.

I guess there's no way to get around the problem that Ton mentioned but if you were looking to extract a certain peice of information from an XML document of unknown structure you could search for it using this library (I think).

Link to comment

QUOTE

And I believe XML doesn't store the datatype inside the XML file

The xml doesn't know anything about the datatype, but the data is typed by the surrounding tags, yes?

QUOTE

even test it against a DTD or XML Schema.

*blink* *blink* [*Looks blankly at Jan silently wishing I understood XML better*]

The schema Labview uses is pre-defined and fixed. I assume it would pass (or fail) every time. How would I use the results of that test to figure out the data the xml document has?

Here's my problem in a nutshell. I have a Java app and Labview app communicating via network sockets and using xml fragments to pass the data. Every so often Labview requests a packet of data from Java but it doesn't know exactly what information will be coming. Maybe it will be a cluster of 3 DBL fp numbers, maybe it will be a single U8, maybe it will be a string and boolean. How can I unflatten the xml string without knowing beforehand what the data structure looks like? I could parse the string to figure out the datatypes inside but that defeats the whole purpose of using xml.

Link to comment

Hi Daklu,

I'm afraid I don't know a solution to that problem. It sounds like in the end you'd still be constrained by what Ton pointed out. I guess I haven't been using LabVIEW for as long as most of the people here. As to the LabXML package, if you don't want to have to parse the string you can actually read attributes of xml tags and then use a case select to unflatten the string inside the xml tag. Is that a step in the right direction?

Sorry, wish I could help more.

Link to comment
  • 4 months later...

QUOTE(Daklu @ Aug 23 2007, 04:00 PM)

The xml doesn't know anything about the datatype, but the data is typed by the surrounding tags, yes?

*blink* *blink* [*Looks blankly at Jan silently wishing I understood XML better*]

The schema Labview uses is pre-defined and fixed. I assume it would pass (or fail) every time. How would I use the results of that test to figure out the data the xml document has?

Here's my problem in a nutshell. I have a Java app and Labview app communicating via network sockets and using xml fragments to pass the data. Every so often Labview requests a packet of data from Java but it doesn't know exactly what information will be coming. Maybe it will be a cluster of 3 DBL fp numbers, maybe it will be a single U8, maybe it will be a string and boolean. How can I unflatten the xml string without knowing beforehand what the data structure looks like? I could parse the string to figure out the datatypes inside but that defeats the whole purpose of using xml.

An XML element has got the data type string (with some restrictions). So if you are exchanging data between application, you need to specify the datatype of the information in your packets. As far as I remember, there exist some documents describing common data types for data exchange (written in XML of course). Unfortunatly I don't remember any URLs. For getting into it, try out http://www.w3schools.com' target="_blank">www.w3schools.com and search the web.

If you exchange data your could simply give your XML-elements in your packets an additional attribute naming the appropriate LabView data type. In LabView you need to evaluate this attribute before reading the data of the XML-element. Within LabView "Flatten To String.VI" and "Unflatten from String.VI" or alternatively the variant data type to transport your bits of information from VI to VI in a general manner.

Writing a general application understanding any packets will be very difficult. But I guess that you have only a limited number of possible data packets. Then you just define adequate attributes. You are free to name XML elements and its attributes as you like. If you want to define the legal building blocks of an XML document you could to write a Document Type Definition (DTD). It defines the structure with a list of legal elements and attributes.

Link to comment

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...

Important Information

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