Viewer Page

How to embed an XML file in HTML?

I am creating a simple web application for a comic using HTML and JavaScript. Because people that are not very technical should be able to add new comics, I thought about using an XML file as a configuration file. I thought about using JSON and decided against it, mainly because the way comma’s are used(no comma between two items breaks it, but a comma at the end of the list also breaks it.). However, my question is now: How can I embed this XML file? Do I use the tag, or something else like the tag? And how can I then read information from the XML nodes in JavaScript?

2 Answers 2

I would recommend loading a JavaScript library that makes this easy. jQuery is one. If you include jQuery in your page then you use it to load the document and get access to the browser’s XML parsing capabilities fairly easily.

http://api.jquery.com/jQuery.parseXML/ shows a simple example of finding values in an xml document once it’s loaded.

This site http://think2loud.com/224-reading-xml-with-jquery/ gives a good example of how to load XML from a remote site. The basic idea is to use AJAX: here’s a tiny snippet for posterity that will load foo.xml after the html document has loaded (relies on jQuery):

This indeed is a correct answer. However, are there no ways to (cross browser) load an XML file in an HTML file without having to rely on post-loading strategies such as AJAX? I am trying to simply include an XML file on the same server as my HTML file.

Читайте также:  Java длина массива байт

No that’s not really possible, I’m afraid, in any sensible way: you can’t just embed XML as markup in HTML and expect different browsers to handle it in the same way. You could try putting the XML in a TEXTAREA with style=»display:none», but you would still have to parse it I think. Interestingly: I did try embedding some random tags in a document and you can navigate them using firebug, so they must be in the DOM, but I suspect this is not reliable.

There is one last thing I’m wondering about. When using an XML file + AJAX to get it, how much slower is it than linking to a JSON file in the header?

I don’t know, but the basic task is the same: fetch the file from the server, parse it, and build the tree in memory. I’ve seen comparisons of XML and JSON parsing where XML wins, but YMMV

Источник

Can I embed xml into html?

We probably shan’t mix to put HTML in files or in the data layer since escape and double escape (JavaScript escape) rather keep distinct presentation (view) and persistence (storage) layers. Here is the xml file: ]]?> I excepted that I can find a way to put the data from the xml into the html or any html file.

Can I embed xml into html?

I have dynamic content that will grow and shrink in height that needs to be embedded into other sites that we do not host or have any control over. I was using an iframe to do this but after realizing that it is basically impossible to dynamically change the height of an iframe I started thinking about using xml. The only requirement I have is that the container MUST grow and shrink with the data being imported.

Can I use xml for this? What tag would I use to grab the data when the page loads? When the page loads, the data would need to be ready to show.

Copypasta’d at OP’s request:

You can embed XML into HTML (using a tag), but how would you expect it to render beyond showing the raw XML text? I also don’t see how XML has anything to do with the height of your «dynamic» content. What do you mean by «dynamic content,» anyway?

While you can associate stylesheets with XML documents that really just doesn’t sound like the right approach. Your problem is entirely CSS-related. You just want to be able to change the height of an iframe, right?

I think that the best you’ll be able to do is provide a little bit of JavaScript along with the iframe. An iframe is definitely the way to go when it comes to providing a component to be embedded in an arbitrary page, but that means the iframe is at the mercy of the parent page w/r/t placement, dimensions, etc.

which talks about «adding islands of more richly structured XML markup to existing HTML5 documents.»

XML introduction — XML: Extensible Markup Language, XML (Extensible Markup Language) is a markup language similar to HTML, but without predefined tags to use. Instead, you define your own tags designed specifically for your needs. This is a powerful way to store data in a format that can be stored, searched, and shared. Most importantly, since the fundamental format …

How can I insert XML data into HTML?

I am trying to grab data from an XML status file that is on VLC and I want to put it into an HTML so that when the status XML updates or is requested, the new information appears in the HTML.

Here is the XML information from the status.xml when its ran. OMFG — I can’t post images due to reputation yet. Here are the links to the images instead.

I want those fields in here:

I don’t have any knowledge of any direct programming. I have run some batch files and I have some python scripts I use and I edit but nothing else. I understand tags, functions and lists to a degree.

I have tried using «scr» to path out my xml file with «type:text/xml. — failed I have tried using a viewer.js file and editing that to point to the xml file I wanted. — failed. — I didn’t understand how to put the xml data into a javascript file that can then be referenced inside the html.

This is the html file; I got it from the rig-developer kit from twitch as there first extension.