Rianneke
Gebruiker
- Lid geworden
- 10 apr 2008
- Berichten
- 30
Ik ben op zoek naar javascript die een xml-file kan lezen en presenteren, die echter niet alleen werkt in IE maar ook in FireFox.
Via internet vond ik een goed werkend script echter alleen voor IE. Weet iemand wat ik moet aanpassen om het ook te laten werken onder FireFox.
Bij voorbaat "mijn dank is groot".
---- voorbeeld import.xml --------------------------
[xml]
<?xml version="1.0"?>
<BBLOCK>
<RENDER>
<A>NaamItem_1</A>
<B>Omschrijving</B>
<C>Item1.html</C>
<D>image1.jpg</D>
</RENDER>
<RENDER>
<A>NaamItem_2</A>
<B>Omschrijving</B>
<C>Item2.html</C>
<D>Image2.jpg</D>
</RENDER>
</BBLOCK>
[/xml]
-----------------------------------------
-------- xmlreader.js -----------------
[js]
/*
JS XML Document Reader. Author Joe McCormack. Copyright 2003. All Rights Reserved.
www.geocities.com/code_stratos/
*/
function getRecords(locale,docid,place) {
var plate = new String();
var lemme = new String(docid);
var dest = new String(place);
var recordSet = window.document.getElementById(lemme).recordset;
while(!recordSet.EOF) {
plate += "<table border=\"0\" width=\"100%\" cellpadding=\"5\" cellspacing=\"0\"><tr>";
if (recordSet("D").value.length > 0) {
plate += "<td valign=\"top\"><center>";
if (locale == "links") {
if (recordSet("C").value.length > 0) { plate += "<a href=\"http://"+recordSet("C")+"\">"; }
plate += "<img src=\""+recordSet("D")+"\" border=0 alt=\""+recordSet("A")+"\" />";
if (recordSet("C").value.length > 0) { plate += "</a>"; }
}
if (locale == "email") {
if (recordSet("C").value.length > 0) { plate += "<a href=\"mailto:"+recordSet("C")+"\">"; }
plate += "<img src=\""+recordSet("D")+"\" border=0 alt=\""+recordSet("A")+"\" />";
if (recordSet("C").value.length > 0) { plate += "</a>"; }
}
plate += "</center></td>";
}
plate += "<td valign=\"top\">";
if (recordSet("C").value.length > 0) {
if (locale == "links") { plate += "<a href=\"http://"+recordSet("C")+"\">"; }
if (locale == "email") { plate += "<a href=\"mailto:"+recordSet("C")+"\">"; }
}
plate += recordSet("A"); if (recordSet("C").value.length > 0) { plate += "</a>"; }
plate += " "+recordSet("B")+"</td></tr></table>";
recordSet.moveNext();
}
window.document.getElementById(dest).innerHTML = plate;
}
[/js]
---------------------------------------------------
----------------- HTML-code -------------------
-----------------------------------------------------
Via internet vond ik een goed werkend script echter alleen voor IE. Weet iemand wat ik moet aanpassen om het ook te laten werken onder FireFox.
Bij voorbaat "mijn dank is groot".
---- voorbeeld import.xml --------------------------
[xml]
<?xml version="1.0"?>
<BBLOCK>
<RENDER>
<A>NaamItem_1</A>
<B>Omschrijving</B>
<C>Item1.html</C>
<D>image1.jpg</D>
</RENDER>
<RENDER>
<A>NaamItem_2</A>
<B>Omschrijving</B>
<C>Item2.html</C>
<D>Image2.jpg</D>
</RENDER>
</BBLOCK>
[/xml]
-----------------------------------------
-------- xmlreader.js -----------------
[js]
/*
JS XML Document Reader. Author Joe McCormack. Copyright 2003. All Rights Reserved.
www.geocities.com/code_stratos/
*/
function getRecords(locale,docid,place) {
var plate = new String();
var lemme = new String(docid);
var dest = new String(place);
var recordSet = window.document.getElementById(lemme).recordset;
while(!recordSet.EOF) {
plate += "<table border=\"0\" width=\"100%\" cellpadding=\"5\" cellspacing=\"0\"><tr>";
if (recordSet("D").value.length > 0) {
plate += "<td valign=\"top\"><center>";
if (locale == "links") {
if (recordSet("C").value.length > 0) { plate += "<a href=\"http://"+recordSet("C")+"\">"; }
plate += "<img src=\""+recordSet("D")+"\" border=0 alt=\""+recordSet("A")+"\" />";
if (recordSet("C").value.length > 0) { plate += "</a>"; }
}
if (locale == "email") {
if (recordSet("C").value.length > 0) { plate += "<a href=\"mailto:"+recordSet("C")+"\">"; }
plate += "<img src=\""+recordSet("D")+"\" border=0 alt=\""+recordSet("A")+"\" />";
if (recordSet("C").value.length > 0) { plate += "</a>"; }
}
plate += "</center></td>";
}
plate += "<td valign=\"top\">";
if (recordSet("C").value.length > 0) {
if (locale == "links") { plate += "<a href=\"http://"+recordSet("C")+"\">"; }
if (locale == "email") { plate += "<a href=\"mailto:"+recordSet("C")+"\">"; }
}
plate += recordSet("A"); if (recordSet("C").value.length > 0) { plate += "</a>"; }
plate += " "+recordSet("B")+"</td></tr></table>";
recordSet.moveNext();
}
window.document.getElementById(dest).innerHTML = plate;
}
[/js]
---------------------------------------------------
----------------- HTML-code -------------------
HTML:
<script language="javascript" src="xmlreader.js">
</script>
<!-- XML Announcement Placement -->
<DIV ID="dannouncexml" style="position:relative;visibility:visible;"></DIV>
<XML ID="announceXML" src="import.xml" ondatasetcomplete="getRecords('links','announceXML','dannouncexml');" />
Laatst bewerkt door een moderator: