I am using jQuery, but this problem is not specific to jQuery as I have tried it using straight javascript and the problem still occurs. What I am trying to do is grab the contents of a DIV that contains XHTML. I am then taking that string of XHTML (The Contents of the DIV) and adding it to a textarea. This works just fine. The problem is that the selection of XHTML content appears to be converting it to HTML.
Example:<img /> becomes <img><br /> becomes <br>I need the HTML to be XHTML compliant. Has anyone ran into this before?
Thanks in Advanced!
Couto Solutions CEO4115 Broad Street, Suite B-5, San Luis Obispo, CA 93401Phone: (805) 540-3335 | Web: www.CoutoSolutions.com
I found this online but haven't tested it. Unfortunately I couldn't find any standards compliant way of doing this, but maybe the XMLSerializer object will become a standard. Of course, this works for any DOM element, including responseXML out of XmlHttpRequest.
function xml2Str(xmlNode) { try { // Gecko- and Webkit-based browsers (Firefox, Chrome), Opera. return (new XMLSerializer()).serializeToString(xmlNode); } catch (e) { try { // Internet Explorer. return xmlNode.xml; } catch (e) { //Other browsers without XML Serializer alert('Xmlserializer not supported'); } } return false; }
Source:http://stackoverflow.com/questions/43455/how-do-i-serialize-a-dom-to-xml-text-using-javascript-in-a-cross-browser-way
Couto Solutions Development Team4115 Broad Street, Suite B-5, San Luis Obispo, CA 93401Phone: (805) 540-3335 | Web: www.CoutoSolutions.com
I tired using this method and I was running into issue with it. I ended us using this script on codeplex that solved the problem for me. It was designed to do exactly what I need.
Here is a URL to the script:http://xhtmljs.codeplex.com/releases/view/12048
To use it with jQuery you simply do:var xhtmlContent = $("#content").xhtml();
The above example would return a string of the exact content you would expect.
Thanks for the help,