Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use JavaScript to post XML to HTML???

Status
Not open for further replies.

nleco

Programmer
Dec 10, 2003
5
US
I have several clients that hit my servers for xml files. The URL and variables determine what file each client gets. Some clients do not have any type of scripting on their websites (PHP, ASP, etc). They only have plain HTML.

My question is, I want to build an example of a static HTML page that fetches my XML file, and displays it in a simple table. I tried using MSXML parser with the ActiveXObject instructions, but that raised a problem due to the settings on my IE browser. I believe it has to do with fetching the XML file from a different domain.

I've been looking at JavaScript parsers and methods of doing this. Has anyone succeeded without using frames???

also, how can i load a remote XML file (generated through a webpage) into a javascript variable? thanks.
 
I'd like to add that using the activexobject works well if the xml file is local to the domain. However, this doesnt help me since the customers fetch the files from my domain to use in theirs. I noticed that using the activexoject method works if i enable the "access data sources across domains" option, but i am sure many people have this option turned off, myself included.
 
also, i am using the rdf model for my xml file.
 
Here goes an example ...

<HTML>
<HEAD>
<TITLE>Tabular Biding with XML Data Islands</TITLE>
</HEAD>

<BODY>
<CENTER>
<H1>Tabular Biding with XML Data Islands</H1>

<XML SRC="TestXML.xml" ID="customers"></XML>

<TABLE DATASRC="#customers" BORDER="1">
<TR>
<TD>
<TABLE DATASRC="#customers" DATAFLD="NAME">
<TR>
<TH>
<SPAN DATAFLD="FIRST_NAME"></SPAN>
<SPAN DATAFLD="LAST_NAME"></SPAN>
</TH>
<TD>
<TABLE DATASRC="#customers" CELLPADDING="3" DATAFLD="ORDERS">
<TR>
<TD>
<I>Date of order:</I>
<SPAN DATAFLD="DATE"></SPAN>
</TD>
</TR>
<TR>
<TD>
<TABLE WIDTH="100%" DATASRC="#customers" CELLPADDING="3" DATAFLD="ITEM" BORDER="1">
<TR ALIGN = "LEFT">
<TD>
<I>Product</I>
</TD>
<TD>
<I>Quantity</I>
</TD>
<TD>
<I>Price</I>
</TD>
</TR>
<TR>
<TD>
<SPAN DATAFLD="PRODUCT"></SPAN>
</TD>
<TD>
<SPAN DATAFLD="NUMBER"></SPAN>
</TD>
<TD>
<SPAN DATAFLD="PRICE"></SPAN>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</CENTER>
</BODY>
</HTML>


... and the XML file ...

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE DOCUMENT SYSTEM "TestXML.dtd">
<DOCUMENT>
<CUSTOMER>
<NAME>
<LAST_NAME> Simpson</LAST_NAME>
<FIRST_NAME>Homer</FIRST_NAME>
</NAME>
<ORDERS>
<DATE>03/03/2004</DATE>
<ITEM>
<PRODUCT>Beer</PRODUCT>
<NUMBER>10</NUMBER>
<PRICE>$50.00</PRICE>
</ITEM>
</ORDERS>
</CUSTOMER>
<CUSTOMER>
<NAME>
<LAST_NAME> Simpson</LAST_NAME>
<FIRST_NAME>Bart</FIRST_NAME>
</NAME>
<ORDERS>
<DATE>02/03/2004</DATE>
<ITEM>
<PRODUCT>TNT</PRODUCT>
<NUMBER>1</NUMBER>
<PRICE>$35.00</PRICE>
</ITEM>
<ITEM>
<PRODUCT>DVD</PRODUCT>
<NUMBER>2</NUMBER>
<PRICE>$45.00</PRICE>
</ITEM>
</ORDERS>
</CUSTOMER>
</DOCUMENT>

... and the DTD (I know... I should have used a schema)...

<!ELEMENT DOCUMENT (CUSTOMER)*>
<!ELEMENT CUSTOMER (NAME,ORDERS)>
<!ELEMENT NAME (LAST_NAME,FIRST_NAME)>
<!ELEMENT FIRST_NAME (#PCDATA)>
<!ELEMENT LAST_NAME (#PCDATA)>
<!ELEMENT ORDERS (DATE,ITEM*)>
<!ELEMENT DATE (#PCDATA)>
<!ELEMENT ITEM (PRODUCT,NUMBER,PRICE)>
<!ELEMENT PRODUCT (#PCDATA)>
<!ELEMENT NUMBER (#PCDATA)>
<!ELEMENT PRICE (#PCDATA)>


I think that might help you!!!
 
Thanks for the reply, I believe i tried this method, and realize it only works if the xml file is local on your servers... the problem is that the xml files are NOT local, they are on another server (mine) on a different domain... so it would be like yahoo.com trying to use the xml file stored on msn.com. the main reason it doesnt work is because of IE settings. tough luck for me.

any ideas to get around this??? plus, i believe the XML tag is only found in IE... i just love working with XML and browser parsing. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top