Embedding XML in HTML Embedding XML in HTML xml xml

Embedding XML in HTML


As long as the XML doesn't contain </script> anywhere, you can put it inside the script tags with a custom type attribute (and no CDATA section). Give the script tag an id attribute so you can fetch the content.

<script id="myxml" type="text/xmldata">    <x>        <y z="foo">        </y>    </x></script>​... <script> alert(document.getElementById('myxml').innerHTML);​ </script>

http://jsfiddle.net/hJuPs/


How about:

<script>    var xml = '<element> \                 <childElement attr="value" /> \               </element>';</script>

That would enable you to easily embed the XML for later retrieval in javascript.


According to the tutorial here, you can use the 'xml' tag to embed XML data within an HTML document. However, this implicitly displays the XML data in the browser.

http://www.expertrating.com/courseware/XMLCourse/XML-Embedding-HTML-8.asp