Topic
  • 4 replies
  • Latest Post - ‏2012-02-23T15:09:36Z by SystemAdmin
Learn2012
Learn2012
3 Posts

Pinned topic xml file not working?

‏2012-02-17T21:56:25Z |
I dont know whats missing here. Need help

<html>
<head>
<script type="text/javascript">
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}
</script>
</head>
<body>

<script type="text/javascript">

xmlDoc=loadXMLDoc("1.xml");

x=xmlDoc.getElementsByTagName("name")[0]
y=x.childNodes[0];
document.write(y.nodeValue);

</script>
</body>
</html>
Updated on 2012-02-23T15:09:36Z at 2012-02-23T15:09:36Z by SystemAdmin
  • Learn2012
    Learn2012
    3 Posts

    Re: xml file not working?

    ‏2012-02-17T21:58:25Z  
    this is my xml file. When I open 1.html file nothing showed up.

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!-- Edited by XMLSpy? -->
    <breakfast_menu>
    <food>
    <name>Belgian Waffles</name>
    <price>$5.95</price>
    <description>two of our famous Belgian Waffles with plenty of real maple syrup</description>
    <calories>650</calories>
    </food>
    <food>
    <name>Strawberry Belgian Waffles</name>
    <price>$7.95</price>
    <description>light Belgian waffles covered with strawberries and whipped cream</description>
    <calories>900</calories>
    </food>
    <food>
    <name>Berry-Berry Belgian Waffles</name>
    <price>$8.95</price>
    <description>light Belgian waffles covered with an assortment of fresh berries and whipped cream</description>
    <calories>900</calories>
    </food>
    <food>
    <name>French Toast</name>
    <price>$4.50</price>
    <description>thick slices made from our homemade sourdough bread</description>
    <calories>600</calories>
    </food>
    <food>
    <name>Homestyle Breakfast</name>
    <price>$6.95</price>
    <description>two eggs, bacon or sausage, toast, and our ever-popular hash browns</description>
    <calories>950</calories>
    </food>
    </breakfast_menu>
  • SystemAdmin
    SystemAdmin
    1391 Posts

    Re: xml file not working?

    ‏2012-02-18T16:24:06Z  
    You have to put 1.html and 1.xml both on a website (including localhost) and serve the page 1.html through the web server. I wouldn't take the page too seriously and it spells a horror story of using document.write like that...
  • Learn2012
    Learn2012
    3 Posts

    Re: xml file not working?

    ‏2012-02-18T19:00:09Z  
    You have to put 1.html and 1.xml both on a website (including localhost) and serve the page 1.html through the web server. I wouldn't take the page too seriously and it spells a horror story of using document.write like that...
    I always have trouble about the localhost thing. Like in php I could use "include" in local host. But when I just click on it nothing happens and same as when I upload to my server. Do you have any website that can solve my problem?
  • SystemAdmin
    SystemAdmin
    1391 Posts

    Re: xml file not working?

    ‏2012-02-23T15:09:36Z  
    • Learn2012
    • ‏2012-02-18T19:00:09Z
    I always have trouble about the localhost thing. Like in php I could use "include" in local host. But when I just click on it nothing happens and same as when I upload to my server. Do you have any website that can solve my problem?
    >I always have trouble about the localhost thing.
    That does not seem to be a terribly convincing excuse... You still have to do it and ask appropriate forums for help if nobody near you can help.

    If you mean you want to test something like that out of the local file system, it is still marginally possible for learning purpose. [1] You've to stick to IE; then [2] you keep or force (if you use v7+ of) IE to use the activex block (because otherwise, ie7+ will opt for XMLHttpRequest); [3] you use only ResponseText because there won't be info on internet media type of the message content available and ResponseXml just go blank, therefore you've to pick up the ResponesText and [4] activate an xml parser like Msxml2.DomDocument to load it up. From thereon, you can exercise with dom-related methods for learning purpose...