thk thk Δευ. 14 Σεπ. 2009 14:02 tags javascript , madpy , προγραμματισμός , python 1 views
Forget all the rest.I did not know then or I have not figured .
use CDATA declarations if you want to include html in xml.
Its so simple..

On of the most common things xml is used today is in ajax. Ajax is a method to make a request to an http server through javascript and stands for Asychronous Javascript And Xml .
Madpy , kaotonik, openroom  make heavy use of ajax.
So furhermore , one of the most common things you may want to do with ajax is fetch html data from server.
And this is when some problems arise , with the main rule in xml that every tag (<>) must be properly closed. So there is problem  when you want to include data that includes tags ('<', '>') , like html data, inside an xml node.
Just google for "include html in xml" and you 'll notice many developers have the same problem every day.
So here i ll demonstrate one  approach I am using in madpy (server side programming is in python) to transfer html inside xml documents.

On server side when you create the xml document , escape the html data from any xml special characters like <,& and so on.
For this , you 'll need to import escape module from xml.sax.saxutils

from xml.sax.saxutils import escape
escapedHtml= escape(htmlData)

Now the html is ready to be included inside an xml node.
All tags and other special characters are properly escaped after this , for example < becomes &lt.

Now on client side (html, javascript) when you receive the xml document through the ajax call, and you finally want to add in your html document the escaped html data of an xml node, get the escaped html and assign it to the html element you want , through innerHTML attribute of the element.

myNewDiv.innerHTML = escapedHTMLData;

that's all..

θυμήσου με