Click to See Complete Forum and Search --> : showing XML file in HTML


ambercelery
March 12th, 2006, 05:42 AM
Hi

Hope that someone can help me with the following.
I have an XML file that I want to display in on my index.html page and am having trouble getting it displayed like i want.
I have created a xsl file which works fine and shows the XML like i want.

I then want to have the contents of my index.html displayed on screen and below that have the contents of the xml/xsl file

I dont want frames, as i only want to view the xml contents at the bottom of the page (not have the top frame scrollable etc)

I tried using an iframe but u seem to need to mention how big the frame should be - and i am wanting to display a dynamic XML file.

How can i get it just to add the XML at the bottom of the page?

visualAd
March 12th, 2006, 03:18 PM
You have three options if you don't want to use frames.

Have index.html redirect to the XML file and add the index.html content to the template which matches the root xml element.
Use a server side scripting language with XSL support such as PHP and generate the transformed HTML on the server. This way you can send the HTML before the transformed content.
Use client side Javascript to transform the XML and append it to the DOM (only IE and Firefox have XSLT support at present).

Let me know which way you want to go and I'll be happy to assist further :)

ambercelery
March 12th, 2006, 03:33 PM
Many thanks for the reply

To be honest with you, I'm not sure which of the 3 options would be best for what i am trying to achieve.

The html page I have - already has javascript content on it.
The page uses the Google Maps API to display a map on the screen.

I currently have an XML file which contains the points i want to plot on the map. The method of doing this is as you mentioned in (3)

I am now trying to add the contents of another XML file to the bottom of this html page - so i have the map at the top , and a kind of blog representation at the bottom of the page (the blog contents will come from the XML file).

I tried to add the contents of the XML to the one containing the Google Map points and reading this the same way into the DOM - but kept getting an error (i guess its due to something to do with the google map schema used).

So, I would now like to keep the javascript/html i currently have for the map and just display the xml/xsl file to the bottom of the page

If you can help or provide advice as to what you would do it would be greatly appreciated.

visualAd
March 12th, 2006, 03:53 PM
Are you using XSLT on the client side already? If so then you should use it to transform the other XML too. What error do you get?

ambercelery
March 13th, 2006, 04:37 AM
hi again

Well i think my problem stems from the fact that I need to have some javascript methods in my page. I may be wrong but i didnt think that I could use Javascript in an XSLT page? is that correct?

(I have since been able to get all the info i need into one XML file - i was just doing something simple wrong).

Now I have the XML file i need, and an html file containing Javascript methods. I can parse the XML file - reading the info into the DOM - no problems. However, I think it would be much better if i could get rid of the html page altogether and just use the Xml with XSLT - but would need to be able to use Javascript in this. Is that possible?

If not, when reading an XML file in an HTML file, I am having trouble reading the tree I have. Basically , I am wanting to parse the following.

<section>
<title>Title</title>
<section2>Some txt here.</section2>
<time>10:10</time>
<date>10/09/2006</date>
<links>
<link>link</link>
</links>
</section>
<section>
<title>Title</title>
<section2>Some txt here.</section2>
<time>10:10</time>
<date>10/09/2006</date>
<links>
<link>link</link>
</links>
</section>

I have come across the :
var sections = xmlDoc.documentElement.getElementsByTagName("section");
which will return me an array of 2 elements.
How do i get to the contents of this data to parse it.
I know that if the section had an attribute I could use the call to :
sections[i].getAttribute("<attr name>")
but i cannot find out to get the contents of any of the sections sub-headings/contents.

visualAd
March 14th, 2006, 10:07 AM
You can embed Javascript inside XML as long as it is enclosed in a CDATA section as follows. THe CDATA section simply enables you to include characters such as left and right angle brackets and quotes without having to escape them manually using HTML entities.

<script type="text/javascript">
<![CDATA[
/* javascript code here */
]]>
</script>


In general, it is a better idea to move the Javascript to a separate file and link to it from the HTML in the relevant location. It may mean that you need to rearrange some of the script logic, but it makes a more robust, easily updatable script.