swiftaxe Posted December 11, 2006 Share Posted December 11, 2006 I'm storing html-code in a database. I use an Ajax request to fetch the code.Then I return the data using xml.The problem occurs when the XML is created.If there is a tag without an endtag, like <img>, in the html code to be returned, then an xml error occurs.[b]The html tags within the code is interpreted as xml tags[/b], and thus requires that all tags have an end tag. :-\[b]Example:[/b][code]<?xml version="1.0" encoding="UTF-8" ?><data> <code><p>Example</p><img src="anything"></code></data>[/code]Is there an easy way around this problem?Thanks Link to comment https://forums.phpfreaks.com/topic/30227-error-when-sending-html-code-using-xml/ Share on other sites More sharing options...
irken Posted January 4, 2007 Share Posted January 4, 2007 Hi.Yes, "<" and "&" are illegal in XML. You'll need to make use of the CDATA tag in order to use HTML and such inside an XML section. Everything inside a CDATA tag is ignored by the parser.For example:[code]<?xml version="1.0" encoding="UTF-8" ?><data> <code> <![CDATA[<p>Example</p><img src="anything" />]]> </code></data>[/code]You should also be aware that you can't actually put "]]>" inside a CDATA tag for obvious reaons.The CDATA tag starts with <![CDATA[ and ends with ]]> Link to comment https://forums.phpfreaks.com/topic/30227-error-when-sending-html-code-using-xml/#findComment-152841 Share on other sites More sharing options...
swiftaxe Posted January 13, 2007 Author Share Posted January 13, 2007 Thanks, that works great.Thank you Link to comment https://forums.phpfreaks.com/topic/30227-error-when-sending-html-code-using-xml/#findComment-160073 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.