Jump to content

Passing Xml To Javascript


DKP

Recommended Posts

Is it possible to pass a generic resource like an XML file to an HTML page and access it via JavaScript? For example, can I specify this resource in the HTML, not effecting the rest of the web page, and then access the contents of the XML file in my JavaScript code? I tried just using the link tag in the header section of the my HTML like this

<link rel="bookmark" id="myid" href="mydata.xml" type="text/xml" media="all" charset="utf-8"/>

In can get the object in my JavaScript using getElementById(), but is there a way to get at the contents of the file (as opposed to just the url)? Are they already resident on the client and accessible in a character string somewhere?I was able to get this to work by making an XMLHttpRequest after the page loaded, but I'd rather have the resource loaded automatically w/ the rest of the page.

Link to comment
Share on other sites

As far as I know, there's no way to do it. You need to call the external file with Javascript.If you were using XHTML you possibly could assign a namespace to an element and have the XML inside it, hiding the element with CSS.

Link to comment
Share on other sites

There is no reason an HTTP request has to wait until after page load. You can create your request object and send it as the script loads. The request will be on its way before your first page element appears.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...