Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript - Display XML as table

Status
Not open for further replies.

sunsilk10

Programmer
Mar 4, 2008
1
Hi I am trying to display the following XML as an HTML table using javascript, but it comes up with error on page.

<Layers>
<Layer name="DB.SSSI_10K">NULL</Layer>
<Layer name="DB.RAMSAR_20K">NULL</Layer>
- <Layer name="DB.RIVERS_10K">
- <gml:FeatureMember>
- <Feature FID="233574" distance="0" Units="meters">
<Field name="RIVERS_ID">153389</Field>
<Field name="OS_NAME" />
</Feature>
- <Feature FID="233500" distance="20" Units="meters">
<Field name="RIVERS_ID">153456</Field>
<Field name="OS_NAME" />
</Feature>
</gml:FeatureMember>
</Layer>
</Layers>


I have started with this:
var layerNodes = xmlDoc.selectNodes("//Layers/*");

for (i=0; i<layerNodes.length; i++){

var tr1 = tb.appendChild(document.createElement("tr"));
var td1 = tr1.appendChild(document.createElement("td"));
td1.noWrap = true;
td1.appendChild(document.createTextNode(layerNodes.item(i).attributes.item(0).text));

var td2 = tr1.appendChild(document.createElement("td"));
td2.noWrap = true;
td2.appendChild(document.createTextNode(layerNodes.item(i).text));

var featureNode = layerNodes.item(i)
for (j=0; j<featureNode.childNodes.length; j++){

}
}
 
Everything seems come out of nowhere... Only I would say two things - if you are good at the subject matter you are treating, you should understand what I am talking about, - namely:
[1] you should, somewhere in the xml document, declare the namespace with prefix gml;
[2] even though the layerNodes.item(i).text would give you something in return, it is probably not what you think it is.
 
Also a description of the error would be useful.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top