I'm very new to XML but even so I managed to get a working script thanks to w3school's site that loads in information from the file, here: http://www.w3schools.com/xml/xml_dom.asp . Unfortunately I've run into a little issue with a duplicate site and even though I've researched I haven't found an answer why.
The code is identical in a second site of mine besides the elementId names.
I'm using a wamp server, my XML file "PortfolioInfo.xml" is in the same directory as my index.html, I have a tag inside of a tag in my xml. I want to insert information from the tag in my XML into my HTML tag.
My Javascript is:
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","PortfolioInfo.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.getElementById("contactName").innerHTML=xmlDoc.getElementsByTagName("name")[0].childNodes[0].nodeValue;
if I comment out the document.getElementById line the rest of my Javascript code doesn't break if it's not commented out if breaks. I've tried placing it in the HTML file itself at the end of the body tag.
the full HTML is here:
<!DOCTYPE html>
<html>
<head>
<title>Portfolio: Darrell James</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<link href='http://fonts.googleapis.com/css?family=Aldrich' rel='stylesheet' type='text/css'>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
</head>
<body>
<div id="home">
</div>
<div id="about">
<div id="aboutHome"><span class="arrow"><<</span></div>
<div id="aboutSlide">
<div id="aboutText">
about
</div>
</div>
</div>
<div id="gallery">
<div id="galleryHome"><span class="arrow"><<</span></div>
<div id="gallerySlide">
<div id="galleryText">
gallery
</div>
</div>
</div>
<div id="contact">
<div id="contactHome"><span class="arrow"><<</span></div>
<div class="nobr" id="contactContent">
<span id="contactName">
</span>
</div>
<div id="contactSlide">
<div id="contactText">
contact
</div>
</div>
</div>
<script src="script.js"></script>
<script>
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","PortfolioInfo.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.getElementById("contactName").innerHTML=xmlDoc.getElementsByTagName("name")[0].childNodes[0].nodeValue;
</script>
</body>
It's not necessary I use XML but I'd appreciate any help.