How would one go about embedding XML in a HTML page?
I was thinking using CDDATA would be the best approach but I get errors in the HTML document when the page loads.
<script><![CDATA[ ... ]]></script>
I'm needing to embed a XML document for fetching later with JavaScript. I need to do this since when the user opens it, they might not have internet access.
To view raw XML source, try to select "View Page Source" or "View Source" from the browser menu. Note: In Safari 5 (and earlier), only the element text will be displayed. To view the raw XML, you must right click the page and select "View Source".
Embedded expressions enable you to create XML literals that contain expressions that are evaluated at run time. The syntax for an embedded expression is <%= expression %> , which is the same as the syntax used in ASP.NET.
Create a folder in your website called "XMLFiles". Create a file in that folder called "Videos. xml" and place your XML in the file.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With