Lee Barnett

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromLee Barnett
ToMe
SubjectExtracting single elements of data from an imported xml file
Date8 June 2005 15:35
Hi,

Hope you can help!  I've used your "importing xml files" tutorial and coding
to create a html timetable, based on data input into an xml file.  This
works perfectly and I am very happy with the results.  What I also want to
be able to is read single elements of xml data and be able to display them
in a html page within a div tag rather than a table.

Let me give you an example.  We have an xml file called moduledata.xml:

<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/css" href="blank.css"?>
<MODULEDATA>
	<TITLE>Computer Applications in Mathematics</TITLE>
	<ID>05MAA160</ID>
	<ACADEMIC>Tony Croft</ACADEMIC>
	<MAILTO>mailto:L.Barnett@lboro.ac.uk</MAILTO>
	<EMAIL>L.Barnett@lboro.ac.uk</EMAIL>
	<YEAR>2005/2006</YEAR>
</MODULEDATA>

>From this I want to pick out several discreet pieces of information to
display in different places within the html page. These elements I can then
format using a CSS.  The xml file will never have more than a single
<MODULEDATA> entry, so a loop is not really required to count the number of
them in the file.

The reason for doing this is as follows:  We have a data server where every
single course or module that runs here at the university has server space
for academics to place support files and html pages.  I am trying to create
a standardised front end for the look and feel of each of these module html
pages, to display administrative data.  We have hundreds of courses, so I
don't want to have to create separate pages for each module.  My idea was to
create a template html page, that never ever gets edited, and xml pages that
the academic fills in with the necessary data.  The html template then
automatically gets populated with the data when the xml file is loaded to
the server - this gives the academic direct control on changing the data.
At this point you are probably thinking that this could be done with
databases, ASP etc., well I don't have those skills, and I am not sure the
server technicians would be happy to let me loose trying that sort of thing
out - consequently the low tech approach.

I have tried editing your script to achieve the results, and have learnt a
lot about how JavaScript works, including how Firefox and IE seem to differ
in their understanding of array positions, but I still can't seem to figure
this out.

I really hope you can help, as I would be most grateful.

Cheers,

Lee.
FromMe
ToLee Barnett
SubjectRe: Extracting single elements of data from an imported xml file
Date10 June 2005 01:45
Lee,

> <?xml version="1.0" encoding="iso-8859-1"?>
> <?xml-stylesheet type="text/css" href="blank.css"?>
> <MODULEDATA>
>     <TITLE>Computer Applications in Mathematics</TITLE>

...

> From this I want to pick out several discreet pieces of information to
> display in different places within the html page.

assuming this is your function that is run after the import:

function foo(bar) {
  //XML is case sensitive - you should change to lower case if possible
  var oTtl = bar.getElementsByTagName('TITLE')[0].firstChild.nodeValue;
document.getElementByTagName('thetitle').appendChild(document.createTextNode(oTtl));
  ...do the same with the other elements...
}
...
<div id="thetitle"></div>

That should give you the basics of what you want to do.

Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.