Solved

Working with xml on a web site.

Posted on 2014-12-08
4
119 Views
Last Modified: 2014-12-10
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
0
Comment
Question by:armasmike
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
nap0leon earned 500 total points
ID: 40487774
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
 
LVL 10

Expert Comment

by:Walter Padrón
ID: 40487860
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
 

Author Closing Comment

by:armasmike
ID: 40489357
thank you
0
 
LVL 18

Expert Comment

by:nap0leon
ID: 40491177
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Asp response.write to clients 6 33
Make check boxes work 8 41
Triple line in an alert message 4 20
toggle content 12 22
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question