|
Тема |
XML parser problem |
|
Автор | XLiubitel (Нерегистриран) | |
Публикувано | 23.09.06 10:56 |
|
|
Zdraveite priateli.
Imam sledniqt problem.
Iskam da zaredq v browser daden XML document kato HTML.
Polzvam sledniqt script
<html>
<head>
<script type="text/javascript">
var xmlDoc
function loadXML()
{
//load xml file
// code for IE
if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("note2.xml");
getmessage()
}
// code for Mozilla, etc.
else if (document.implementation &&
document.implementation.createDocument)
{
xmlDoc= document.implementation.createDocument("","",null);
xmlDoc.load("note2.xml");
xmlDoc.onload=getmessage
}
else
{
alert('Your browser cannot handle this script');
}
}
function getmessage()
{
document.getElementById("first").innerHTML=
xmlDoc.getElementsByTagName("first")[0].firstChild.nodeValue
document.getElementById("middle").innerHTML=
xmlDoc.getElementsByTagName("middle")[0].firstChild.nodeValue
document.getElementById("last").innerHTML=
xmlDoc.getElementsByTagName("last")[0].firstChild.nodeValue
document.getElementById("role").innerHTML=
xmlDoc.getElementsByTagName("role")[0].firstChild.nodeValue
document.getElementById("nickname").innerHTML=
xmlDoc.getElementsByTagName("nickname")[0].firstChild.nodeValue
document.getElementById("first1").innerHTML=
xmlDoc.getElementsByTagName("first")[0].firstChild.nodeValue
}
</script>
</head>
<body onLoad="loadXML()" bgcolor="ffffff">
<!-- <h1>Haha</h1>
<p><b>Name:</b> <span id="first"></span><br />
<b>Middle Name:</b> <span id="middle"></span><br />
<b>Last Name:</b> <span id="last"></span><br />
<hr />
<b>Message:</b> <span id="role"></span>
</p> -->
<table border="0">
<tr>
<td><span id="first"></span></td>
<td><span id="middle"></span></td>
<td><span id="last"></span></td>
<td><span id="role"></span></td>
<td><span id="nickname"></span></td>
<td><span id="first1"></span></td>
</tr>
</table>
</body>
</html>
i tozi XML doc
<?xml version="1.0" encoding="ISO-8859-1"?>
<name>
<first>Bobby</first>
<middle>Bobson</middle>
<last>Bobson</last>
<role> - dude</role>
<nickname>
<first>Bob</first>
<middle>Bo</middle>
<last>B</last>
</nickname>
</name>
Vsi4ko raboti bez problem sus firstChild elementite, no kogato iskam da parsna second, kato
<nickname>
<first>Bob</first>
<middle>Bo</middle>
<last>B</last>
</nickname>
v sly4aia ne se poly4ava.
Veroiatno problema e s JavaScript sintaxisa no tai kato ne sum mnogo zapoznat s nego, 6te sum mnogo blagodaren ako niakoi me svetne kak triabva da stane.
Blagodaria predvaritelno.
|
| |
|
|
|