gpt4 book ai didi

javascript - 无法为我的 XML 找到正确的节点值

转载 作者:行者123 更新时间:2023-11-28 17:43:40 24 4
gpt4 key购买 nike

我正在制作一个必须向我的网站显示 xml 数据的项目,但我卡住了。我需要弄清楚如何从“z:row”显示“ows_Person”。我不知道如何在 [0].ChildNodes[0].nodeValue 中定义它,我希望得到一些帮助。

Javascript代码:

<script>
var xmlhttp, xmlDoc;
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "test.xml", false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
document.getElementById("name").innerHTML=
xmlDoc.getElementsByTagName("z:row")[0].childNodes[0].nodeValue;
document.getElementById("ID").innerHTML=
xmlDoc.getElementsByTagName("z:row")[0].childNodes[0].nodeValue;
document.getElementById("Title").innerHTML=
xmlDoc.getElementsByTagName("z:row")[0].childNodes[0].nodeValue;
</script>

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>

最佳答案

只需尝试使用getAttribute:

xmlDoc.getElementsByTagName("z:row")[0].getAttribute('ows_person')

关于javascript - 无法为我的 XML 找到正确的节点值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47327105/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com