Entry
JavaScript: File: XML: Table: Operation: Load: Simple: How to: 2
Apr 15th, 2006 16:20
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 05 April 2021 - 00:10 am ----------------------
JavaScript: File: XML: Table: Operation: Load: Simple: How to: 2
===
Steps: Overview:
1. -Given the table
--- cut here: begin --------------------------------------------------
--------------------------------------------
columnheader1 columnheader2 columnheader3
--------------------------------------------
test11 test12 test13
test21 test22 test23
test31 test32 test33
--------------------------------------------
--- cut here: end ----------------------------------------------------
2. -You can convert this table to XML, by
wrapping each row between the tags <ROW> and </ROW>.
And inside this row, you wrap each column
between the tags <COLUMN> and </COLUMN>
--- cut here: begin --------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<TABLE>
<ROWHEADER>
<COLUMNHEADER>
columnheader1
</COLUMNHEADER>
<COLUMNHEADER>
columnheader2
</COLUMNHEADER>
<COLUMNHEADER>
columnheader3
</COLUMNHEADER>
</ROWHEADER>
<ROW>
<COLUMN>
test11
</COLUMN>
<COLUMN>
test12
</COLUMN>
<COLUMN>
test13
</COLUMN>
</ROW>
<ROW>
<COLUMN>
test21
</COLUMN>
<COLUMN>
test22
</COLUMN>
<COLUMN>
test23
</COLUMN>
</ROW>
<ROW>
<COLUMN>
test31
</COLUMN>
<COLUMN>
test32
</COLUMN>
<COLUMN>
test33
</COLUMN>
</ROW>
</TABLE>
--- cut here: end ----------------------------------------------------
3. -Save this e.g. as the file
table.xml
4. -To read this XML file data,
create e.g. the following file:
1. -It contains 2 nested next loops.
The outer loop goes through the rows.
The inner loop goes through the columns.
--- cut here: begin --------------------------------------------------
<!-------------------------------------------------------------------->
<HTML>
<!-------------------------------------------------------------------->
<SCRIPT>
var fileP = new ActiveXObject( "Microsoft.XMLDOM" );
var rootP = null;
var rowP = null;
var columnP = null;
var rowI = 0;
var columnI = 0;
fileP.load( "table.xml" );
rootP = fileP.documentElement;
rowP = rootP.childNodes;
for ( rowI = 0; rowI <= rowP.length - 1; rowI++ ) {
alert( "row = " + rowI );
//
columnP = rowP.item( rowI ).childNodes;
for ( columnI = 0; columnI <= columnP.length - 1; columnI++ ) {
alert( "column" + columnI + " = " + columnP.item( columnI ).text );
}
//
}
</SCRIPT>
<!-------------------------------------------------------------------->
</HTML>
<!-------------------------------------------------------------------->
--- cut here: end ----------------------------------------------------
5. -Save it e.g. as
table.htm
6. If you load this file
table.htm
in your browser, you will see
the row numbers, followed by
all the columns of that row, one after the other.
--- cut here: begin --------------------------------------------------
row = 0
---
column0 = columnheader1
column1 = columnheader1
column2 = columnheader1
---
row = 1
column0 = test11
column1 = test12
column2 = test13
---
row = 2
column0 = test21
column1 = test22
column2 = test23
---
row = 3
column0 = test31
column1 = test32
column2 = test33
===
Tested successfully on
Microsoft Windows XP Professional (service pack 2),
running
Microsoft Internet Explorer v6.x
===
--- cut here: end ----------------------------------------------------
===
Internet: see also:
---
JavaScript: XML: Link: Overview: Can you give an overview of links?
http://www.faqts.com/knowledge_base/view.phtml/aid/40517/fid/616
----------------------------------------------------------------------