【发布时间】:2017-11-20 10:08:53
【问题描述】:
我的 javascript 代码有问题,我需要从特定节点获取所有数据。我需要将所有节点“ows_Person”显示到我的网站上。 我可以显示 1 'own_person' 但我需要遍历所有这些并显示它们。我不知道我应该怎么做,因为我是这类东西的初学者。我会appriciate一些帮助。
Javascript 代码:
var xmlhttp, xmlDoc;
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "test.xml", false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
//Zet de XML data in een lijst.
document.getElementById("Name").innerHTML=
xmlDoc.getElementsByTagName("z:row")[0].getAttribute('ows_Person');
//Zet de XML data in een lijst.
document.getElementById("ID").innerHTML=
xmlDoc.getElementsByTagName("z:row")[0].getAttribute('ows_ID');
//Zet de XML data in een lijst.
document.getElementById("Created").innerHTML=
xmlDoc.getElementsByTagName("z:row")[0].getAttribute('ows_Modified');
document.getElementById('users').innerHTML = output;
XML 代码:
<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-
microsoft-com:rowset" xmlns:z="#RowsetSchema">
<s:Schema id="RowsetSchema">
<s:ElementType name="row" content="eltOnly" rs:CommandTimeout="30">
<s:AttributeType name="ows_Attachments" rs:name="Attachments" rs:number="1">
<s:datatype dt:type="boolean" dt:maxLength="1" />
</s:AttributeType>
<s:AttributeType name="ows_LinkTitle" rs:name="Title" rs:number="2">
<s:datatype dt:type="string" dt:maxLength="512" />
</s:AttributeType>
<s:AttributeType name="ows_Person" rs:name="Person" rs:number="3">
<s:datatype dt:type="string" dt:lookup="true" dt:maxLength="512" />
</s:AttributeType>
<s:AttributeType name="ows_ID" rs:name="ID" rs:number="4">
<s:datatype dt:type="i4" dt:maxLength="4" />
</s:AttributeType>
<s:AttributeType name="ows_Modified" rs:name="Modified" rs:number="5">
<s:datatype dt:type="datetime" dt:maxLength="8" />
</s:AttributeType>
<s:AttributeType name="ows_DocIcon" rs:name="Type" rs:number="6">
<s:datatype dt:type="string" dt:maxLength="512" />
</s:AttributeType>
</s:ElementType>
</s:Schema>
<rs:data>
<z:row ows_Attachments="0" ows_LinkTitle="Test" ows_Person="1257;#Stefan de
Boer" ows_ID="1" ows_Modified="2017-11-15 15:00:22" />
<z:row ows_Attachments="0" ows_LinkTitle="testtesttesttest"
ows_Person="1256;#Kevin" ows_ID="2" ows_Modified="2017-11-16 10:46:07" />
<z:row ows_Attachments="0" ows_LinkTitle="nog een test"
ows_Person="1258;#Naomi" ows_ID="3" ows_Modified="2017-11-16 10:53:11" />
<z:row ows_Attachments="0" ows_LinkTitle="alweer een test"
ows_Person="1257;#Stefan" ows_ID="4" ows_Modified="2017-11-16 10:53:44" />
</rs:data>
</xml>
【问题讨论】:
标签: javascript node.js xml