[英]Getting textContent of XML node in Javascript
I have XML:我有 XML:
let rowTest = <?xml version="1.0" encoding="UTF-8"?>
<queryResponse Name="Checked In Guests">
<rows>
<row>
<fields>
<field name="PartyName" />
<Notes>Rosen bestellen.</Notes>
<field name="AccompanyingGuest" name1="Test" name2="" name3="test" BedGuestNum="82259">1418</field>
</fields>
</row>
</rows>
</queryResponse>
I want to get the text in the Notes Tag.我想获取 Notes 标签中的文本。 But somehow I am able to do that.但不知何故,我能够做到这一点。 My try:我的尝试:
row = parser.parseFromString(rowTest, "text/xml");
let notes = row.getElementsByTagName("Notes");
let noteText = notes.textContent;
console.log(noteText);
undefined不明确的
Try this code.试试这个代码。
let rowTest = '<?xml version="1.0" encoding="UTF-8"?> <queryResponse Name="Checked In Guests"> <rows> <row> <fields> <field name="PartyName" /> <Notes>Rosen bestellen.</Notes> <field name="AccompanyingGuest" name1="Test" name2="" name3="test" BedGuestNum="82259">1418</field> </fields> </row> </rows> </queryResponse></xml>';
parser = new DOMParser();
row = parser.parseFromString(rowTest, "text/xml");
let notes = row.getElementsByTagName("Notes")[0];
let noteText = notes.textContent;
console.log(noteText);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.