Hello all,
A website I am working on uses javascript to read 6 headlines from an XML file and then outputs them to a <p> element by simply referring to the element's ID and filling it with the XML content. I need to have the ability to easily support 12 headlines.
The requirement is for a vice president here (who knows little of html/javascript/XML) simply add headlines to the XML file and have them automatically show up in the web page.
Currently I am just stepping through the XML file and outputting which won't do the job. I need to have some type of loop and if statement, but I have limited skills with java/xml. My code below will help illustrate whats going on. Thanks so much for any help!!
Here is my html code, followed by Javascript, followed by XML:
HTML:
<p class="headline s" id="headline1"> </p>
<br class="altheigh t">
<p class="headline s" id="headline2"> </p>
<br class="altheigh t">
...etc through "headline 6"
Javascript:
var xmlDoc
function loadXML()
{
//load xml file
// code for IE
if (window.ActiveX Object)
{
xmlDoc = new ActiveXObject(" Microsoft.XMLDO M");
xmlDoc.async=fa lse;
xmlDoc.load("KD XHeadlines.xml" );
getmessage()
}
// code for Mozilla, etc.
else if (document.imple mentation && document.implem entation.create Document)
{
xmlDoc= document.implem entation.create Document("","", null);
xmlDoc.load("KD XHeadlines.xml" );
xmlDoc.onload=g etmessage
}
else
{
alert('Your browser cannot handle this script');
}
}
function getmessage()
{
document.getEle mentById("headl ine1").innerHTM L=xmlDoc.getEle mentsByTagName( "headline1" )[0].firstChild.nod eValue
document.getEle mentById("headl ine2").innerHTM L=xmlDoc.getEle mentsByTagName( "headline2" )[0].firstChild.nod eValue
...etc through "headline 6"
}
XML
<?xml version="1.0" encoding="ISO-8859-1" ?>
<headlines>
<headline1>Ou r team wins</headline1>
<headline2>Yadd a yadda</headline2>
...etc through <headline 6>
</headlines>
To summarize, I need the ability to simply add to the xml file and have it output to the html file. I have attempted to create blank XML tags (i.e.
<headline7></headline7> but they provoke an error.
Any help is much appreciated! I don't know where to go from here.
A website I am working on uses javascript to read 6 headlines from an XML file and then outputs them to a <p> element by simply referring to the element's ID and filling it with the XML content. I need to have the ability to easily support 12 headlines.
The requirement is for a vice president here (who knows little of html/javascript/XML) simply add headlines to the XML file and have them automatically show up in the web page.
Currently I am just stepping through the XML file and outputting which won't do the job. I need to have some type of loop and if statement, but I have limited skills with java/xml. My code below will help illustrate whats going on. Thanks so much for any help!!
Here is my html code, followed by Javascript, followed by XML:
HTML:
<p class="headline s" id="headline1"> </p>
<br class="altheigh t">
<p class="headline s" id="headline2"> </p>
<br class="altheigh t">
...etc through "headline 6"
Javascript:
var xmlDoc
function loadXML()
{
//load xml file
// code for IE
if (window.ActiveX Object)
{
xmlDoc = new ActiveXObject(" Microsoft.XMLDO M");
xmlDoc.async=fa lse;
xmlDoc.load("KD XHeadlines.xml" );
getmessage()
}
// code for Mozilla, etc.
else if (document.imple mentation && document.implem entation.create Document)
{
xmlDoc= document.implem entation.create Document("","", null);
xmlDoc.load("KD XHeadlines.xml" );
xmlDoc.onload=g etmessage
}
else
{
alert('Your browser cannot handle this script');
}
}
function getmessage()
{
document.getEle mentById("headl ine1").innerHTM L=xmlDoc.getEle mentsByTagName( "headline1" )[0].firstChild.nod eValue
document.getEle mentById("headl ine2").innerHTM L=xmlDoc.getEle mentsByTagName( "headline2" )[0].firstChild.nod eValue
...etc through "headline 6"
}
XML
<?xml version="1.0" encoding="ISO-8859-1" ?>
<headlines>
<headline1>Ou r team wins</headline1>
<headline2>Yadd a yadda</headline2>
...etc through <headline 6>
</headlines>
To summarize, I need the ability to simply add to the xml file and have it output to the html file. I have attempted to create blank XML tags (i.e.
<headline7></headline7> but they provoke an error.
Any help is much appreciated! I don't know where to go from here.
Comment