Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Embedding HTML in XML

Status
Not open for further replies.

HelloMike

MIS
Feb 14, 2003
210
GB
Pardon me if this is a bit of a dumb question, but my knowledge of XML, Javascript, etc is all a bit hazy - I'm more used to working with server-side stuff.

My application has a number of web services passing data from server to client in SOAP envelopes. The client part of the application extracts data from the XML and throws it onto an intranet browser page. One of my bits of data includes a large(ish) text field, and some of our users would like to "enhance" the appearance of some of this text, preferably by including HTML tags as an integral part of the text.

I know that these tags will be escaped before transmission from server to client, so are there any Javascript handlers available (or do any of you have any handy hints or tips) for treating such text as HTML and embedding it dynamically into the target browser page ?



Cheers, Mike.
 
Mike,

If you produce XHTML, there would be no reason for the anything to be escaped, because it would be XML!

Now I am not a DOM expert, but it would seem a reasonable thing to do to be able to insert a subtree. However a Google search turns up some controversy on how best to do this. However, your server can produce content that needs merely to be copied into the appropriate portion of the DOM.

Tom Morrison
 
You simply set up the message inside a cdata section and put the html styling/formatting tags inside. Suppose you send a uddi response xml containing
[tt]
<businessInfo businessKey="000XYZ-ABC0">
<name>
Tek-Tips is member supported.
</name>
</businessInfo>
[/tt]
and now you want html presentation info to go with it, you can make it like this.
[tt]
<businessInfo businessKey="000XYZ-ABC0">
<name>[blue]<![CDATA[
<div style="font:bold">Tek-Tips is member supported. <a href=" style="color:red;">Click here to Donate.</a></div>
]]>[/blue]</name>
</businessInfo>
[/tt]
 
Thanks guys, but I'm stuck with plain XML and a fixed DOM. It looks like we'll have to handle it entirely on the client-side, presumably with some sort of javascript handler. Does such a beastie exist?

Cheers, Mike.
 
This question seems most appropriate for forum1600.

Does such a beastie exist?

Clearly the infrastructure code to do the SOAP request and receive the SOAP response exists and is readily available at the price of a Google search.

As for the code to insert the data returned, you will need to author JavaScript specific to the problem, since there seems not to be any easy way of inserting a subtree from one DOM (the SOAP response) into another DOM (the document being rendered by the browser).

Your original post indicated you thought that there is some problem having HTML tags in the SOAP response. I indicated that, as long as you were obeying the rules of XML (i.e. using XHTML) there would be no theoretical problem in doing this. Now, there might be a practical problem in doing this, if you cannot change the WSDL for the web service. After all, an xs:string is not an xs:any.

Then tsuji showed a way that you may transmit unescaped XML-like data by means of CDATA. This would obviate the need for a WSDL change, but would put further custom requirements on the client-side JavaScript, namely taking the string which was protected by CDATA and placing it into its own DOM before inserting the data into the rendered document tree. Perhaps this might be helpful (look toward the bottom of the page).

Tom Morrison
 
Thanks for that, Tom. I think you might have provided a way forward here.

I can't change the WSDL unfortunately, but I may be able to do something with a CDATA section.

Cheers, Mike.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top