|
|
|
| Нашел этот код на этом форуме, а нельзя ту информацию, которую он выводит "развернуть" на 90 градусов, т.е строки сделать колонками, а колонки - строками?
Или у кого-то есть скрипт разбора xml файла средствами JS.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<title>Untitled Document</title>
</head>
<body>
<div id='writeroot'></div>
<script type="text/javascript">
function importXML()
{
if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.onload = createTable;
}
else if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.onreadystatechange = function () {
if (xmlDoc.readyState == 4) createTable()
};
}
else
{
alert('Your browser can\'t handle this script');
return;
}
xmlDoc.load("http://www.site.ru/xml/privet.xml");
}
function createTable(){
var x = xmlDoc.getElementsByTagName('emperor');
var newEl = document.createElement('TABLE');
newEl.setAttribute('border',1);
newEl.setAttribute('cellspacing',0);
newEl.setAttribute('cellPadding',5);
newEl.setAttribute('class','blin');
newEl.setAttribute('width',700);
var tmp = document.createElement('TBODY');
newEl.appendChild(tmp);
var row = document.createElement('TR');
for (j=0;j<x[0].childNodes.length;j++){
if (x[0].childNodes[j].nodeType != 1) continue;
var container = document.createElement('TH');
var theData = document.createTextNode(x[0].childNodes[j].nodeName);
container.appendChild(theData);
row.appendChild(container);
}
tmp.appendChild(row);
for (i=0;i<x.length;i++){
var row = document.createElement('TR');
for (j=0;j<x[i].childNodes.length;j++){
if (x[i].childNodes[j].nodeType != 1) continue;
var container = document.createElement('TD');
var theData = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);
container.appendChild(theData);
row.appendChild(container);
}
tmp.appendChild(row);
}
document.getElementById('writeroot').appendChild(newEl);
}
importXML();
</script>
</body>
</html>
<!--http://softtime.ru/forum/read.php?id_forum=4&id_theme=22552-->
|
| |
|
|
|
|
|
|
|
для: ronin
(18.02.2009 в 17:06)
| | сформируй двумерный массив и потом делай таблицу, как угодно | |
|
|
|
|
|
|
|
для: GeorgeIV
(19.02.2009 в 10:19)
| | нашел js парсер.
xml:
<?xml version="1.0"?>
<BBLOCK>
<RENDER>
<A>Item 1 - Title Here</A>
<B>Item 1 - Description Here</B>
<C>Item 1 - Hyperlink Here</C>
<D>Item 1 - Image Link Here</D>
</RENDER>
<RENDER>
<A>Item 2 - Title Here</A>
<B>Item 2 - Description Here</B>
<C>Item 2 - Hyperlink Here</C>
<D>Item 2 - Image Link Here</D>
</RENDER>
</BBLOCK>
|
сам парсер:
*
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;
}
|
/вызов на html-странице:
...
<script language="javascript" src="js/xmlreader.js"></script>
</head>
<body>
<!-- XML LINKS INFORMATION PLACEMENT -->
<DIV ID="dlinksXML" style="position:relative;visibility:visible;"></DIV>
<XML ID="linksXML" src="xml/render.xml" ondatasetcomplete="getRecords('links','linksXML','dlinksXML');" />
</body>
|
| |
|
|
|