我在其中一个Lotus Notes字段中存储了一个XML值(将其视为普通XML)。
我的XML中有'row id',我想在javascript中读取它的值。在我的XML中,它出现了两次,我想要读取两个值
我的XML在下面给出
<rows>
<row id="1295627144000">
<cell>1</cell>
<cell>1134894</cell>
<cell>3000</cell>
<cell>0</cell>
<cell>hit</cell>
<cell>INR</cell>
<cell>CAP</cell>
<cell>
<IMG title="" src="http://localhost/test/preview/test.nsf/application_form_edit.png" />
</cell>
<cell>100%</cell>
<cell>S</cell>
<cell>3000000</cell>
<cell>No</cell>
<cell />
<cell>Standard Char</cell>
<cell>001</cell>
</row>
<row id="1312205523000">
<cell>2</cell>
<cell>1134894</cell>
<cell>400000000</cell>
<cell>3000000</cell>
<cell>hit</cell>
<cell>hit</cell>
<cell>CAP</cell>
<cell>
<IMG title="" src="http://localhost/test/preview/test.nsf/application_form_edit.png" />
</cell>
<cell>40%</cell>
<cell>S</cell>
<cell>160000000</cell>
<cell>Yes</cell>
<cell />
<cell>Hors Bourse</cell>
<cell>001</cell>
</row>
</rows>
答案 0 :(得分:0)
您可以创建一个元素并使用您的xml设置其内容。然后你可以在这个新元素上使用querySelectorAll来获取&#39; row&#39;要素:
var unknown = document.createElement('unknown');
unknown.innerHTML = `<rows>
<row id="1295627144000">
<cell>1</cell>
<cell>1134894</cell>
<cell>3000</cell>
<cell>0</cell>
<cell>hit</cell>
<cell>INR</cell>
<cell>CAP</cell>
<cell>
<IMG title="" src="http://localhost/test/preview/test.nsf/application_form_edit.png" />
</cell>
<cell>100%</cell>
<cell>S</cell>
<cell>3000000</cell>
<cell>No</cell>
<cell />
<cell>Standard Char</cell>
<cell>001</cell>
</row>
<row id="1312205523000">
<cell>2</cell>
<cell>1134894</cell>
<cell>400000000</cell>
<cell>3000000</cell>
<cell>hit</cell>
<cell>hit</cell>
<cell>CAP</cell>
<cell>
<IMG title="" src="http://localhost/test/preview/test.nsf/application_form_edit.png" />
</cell>
<cell>40%</cell>
<cell>S</cell>
<cell>160000000</cell>
<cell>Yes</cell>
<cell />
<cell>Hors Bourse</cell>
<cell>001</cell>
</row>
</rows>`;
console.log(unknown.querySelectorAll('row'));
&#13;