Working with xml on a web site.

I am working with xml file dump from are ad server.

<?xml version="1.0" encoding="UTF-8"?>

<Information Technology>
	<user>

    	<Name>Jim Lin</Name>
    	<Title>Application and Systems Supp. Spec.</Title>
    	<Department>Information Technology</Department>
    	<Extension>5555</Extension>
    	<Mobile Number>555-555-55555</Mobile Number>
    	<Office Location>Sylvan</Office Location>
    	<Email Address>jlin@google.com</Email Address>
    	<Username>jlin</username>
    	<Manager>Bob Arm</Manager>

	</user>

	<user>

    	<Name>John Smith</Name>
    	<Title>Network Admin.</Title>
    	<Department>Information Technology</Department>
    	<Extension>6666</Extension>
    	<Mobile Number>666-666-6666</Mobile Number>
    	<Office Location>Sylvan</Office Location>
    	<Email Address>jsmith@google.com</Email Address>
    	<Username>jsmith</username>
    	<Manager>Bob Arm</Manager>

	<user>

</Information Technology>

Open in new window


You get the idea I want to display this info on a web page that runs locally on the users laptop. There is no web server on the laptop and it's in not connect to the internet.

It does have java installed. How can i have this info displayed in a web browser
armasmikeAsked:
Who is Participating?
 
nap0leonConnect With a Mentor Commented:
Hopefully that is not the actual XML... way too many errors in it for it to work properly (mismatched case in the xml tags, spaces in the tag values, etc.).

To load the XML from a file:
http://www.w3schools.com/dom/dom_loadxmldoc.asp
function loadXMLDoc(filename)
{
if (window.XMLHttpRequest)
  {
  xhttp=new XMLHttpRequest();
  }
else // code for IE5 and IE6
  {
  xhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xhttp.open("GET",filename,false);
xhttp.send();
return xhttp.responseXML;
} 
var xmlDoc=loadXMLDoc("books.xml");

Open in new window


To load XML from a string (in case you are importing it as text)
http://www.w3schools.com/dom/dom_loadxmldoc.asp
function loadXMLString(txt)
{
if (window.DOMParser)
  {
  parser=new DOMParser();
  xmlDoc=parser.parseFromString(txt,"text/xml");
  }
else // code for IE
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async=false;
  xmlDoc.loadXML(txt);
  }
return xmlDoc;
}
var xmlDoc=loadXMLString(text);

Open in new window


To get values from the XML once you load it into a variable:
http://www.w3schools.com/dom/dom_methods.asp

Then you loop through it to get what you need.
e.g., to get the name of the first user:
function loadXMLString(txt)
{
if (window.DOMParser)
  {
  parser=new DOMParser();
  xmlDoc=parser.parseFromString(txt,"text/xml");
  }
else // code for IE
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async=false;
  xmlDoc.loadXML(txt);
  }
return xmlDoc;
}

text= "<InformationTechnology>"
text+= "<user>"
text+= "<Name>Jim Lin</Name>"
text+= "<Title>Application and Systems Supp. Spec.</Title>"
text+= "<Department>Information Technology</Department>"
text+= "<Extension>5555</Extension>"
text+= "<MobileNumber>555-555-55555</MobileNumber>"
text+= "<OfficeLocation>Sylvan</OfficeLocation>"
text+= "<EmailAddress>jlin@google.com</EmailAddress>"
text+= "<Username>jlin</Username>"
text+= "<Manager>Bob Arm</Manager>"
text+= "</user>"
text+= "<user>"
text+= "<Name>John Smith</Name>"
text+= "<Title>Network Admin.</Title>"
text+= "<Department>Information Technology</Department>"
text+= "<Extension>6666</Extension>"
text+= "<MobileNumber>666-666-6666</MobileNumber>"
text+= "<OfficeLocation>Sylvan</OfficeLocation>"
text+= "<EmailAddress>jsmith@google.com</EmailAddress>"
text+= "<Username>jsmith</Username>"
text+= "<Manager>Bob Arm</Manager>"
text+= "</user>"
text+= "</InformationTechnology>"

var xmlDoc=loadXMLString(text);


xmlDoc.getElementsByTagName("InformationTechnology")[0].getElementsByTagName("user")[0].getElementsByTagName("Name")[0].childNodes[0].nodeValue

Open in new window

0
 
Walter PadrónCommented:
With XSLT you can transform an XML document into HTML, no web server needed but some CSS knowledge is necessary.
see http://www.w3schools.com/xml/xml_xsl.asp for an example
0
 
armasmikeAuthor Commented:
thank you
0
 
nap0leonCommented:
armasmike - if you are not limited to using only JavaScript, you should definitely look into using XSLT as Walter suggested.  

There's a bit of a learning curve, especially if you want to do anything super fancy with it, but it may present additional flexibility in presenting the information on your page.
0
All Courses

From novice to tech pro — start learning today.