Jump to content
carri

use XML with XML Response of a web service

Recommended Posts

Hi, Im new with LabVIEW, and i have a problem using the web services. I want to have more information with the response of the web service, so I use XML to format the output (with "flatten to XML").

The problem is that i want to recieve the response in XML, and when i recieve the response, the symbols < and > of my XML tags had been modified.

For example, i want to recieve some code like this:

<Response>

<Terminal>

<Name>

example

</Name>

<Value>

<String>

<Val>

Example text

</Val>

</String>

</Value>

</Terminal>

</Response>

but i receive this:

<Response>

<Terminal>

<Name>

example

</Name>

<Value>

<String>

<Val>

Example text

</Val>

</String>

</Value>

</Terminal>

</Response>

PS: Sorry for my english it is very poor.

Share this post


Link to post
Share on other sites

thanks for the quick reply, but the change of the characters is in the response from the web service, not inside the VI, I don't know if i am explaining it well...

Share this post


Link to post
Share on other sites

The Webservice escapes it's response so it's easy to parse (and you cannot interfere between data and communication layer. You can use RegExes to find the Value and unescapes it to use it with XML functions:

ZLLdJ.png

Ton

Share this post


Link to post
Share on other sites

The idea is to use the web service with ajax, so i can parse the xml to load the result of the operation, so i can't use this solution. Can I configure the LabVIEW's response not to change that escapes characteres? or any similar solution?

thanks for all responses.

Share this post


Link to post
Share on other sites

You should not be seeing the & replacements when calling the web service. Try calling it from IE or Firefox and see if you still get them. I don't with any of my web services. This could be a problem with the tool you are using to call the web service and not LabVIEW.

Any decent XML parser should know to convert < to a < character.

Share this post


Link to post
Share on other sites

I'm using Firefox. I configure the output of the web service like a XML file, and I receive it well in my browser, but when I add some XML additional tags, the special characters of those tags were changed, so when i try to parse the XML response with javascript, it didn't recognize the < character like the < character.

Share this post


Link to post
Share on other sites

I'm using Firefox. I configure the output of the web service like a XML file, and I receive it well in my browser, but when I add some XML additional tags, the special characters of those tags were changed, so when i try to parse the XML response with javascript, it didn't recognize the < character like the < character.

Use the javascript "html_entity_decode" function.

html_entity_decode(string)

Normal chars will remain unaffected but   &alt etc will be converted.

Damn. Now I'm a text heretic biggrin.gif

Share this post


Link to post
Share on other sites

You can also prepare your own XML and send it through the "Write Response.vi". Just configure the method VI output type to Stream instead of Terminal. I think this is the best solution as you can format the XML just the way you need, and avoid all that "name - value" tags.

Saludos,

Aitor

Share this post


Link to post
Share on other sites

thanks for all responses!! I am thinking to try that two last solutions, that are just what i was looking for. Thanks!!

PS: Again, sorry for my poor english.

Share this post


Link to post
Share on other sites

In the end I used another different solution, it was with ESP, so the solution is as Aitor said, but cleaner, as the VI passes the variables to the ESP code, and this code formats the output to send to client

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.


×
×
  • Create New...

Important Information

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