问题
My XML file's structure is like this..
<?xml version="1.0" encoding="utf-8" ?>
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom"xmlns:core="http://x.y.com/xy/xyz">
<atom:title>TestTitle</atom:title>
<atom:link rel="a" href="$a_u"/>
<atom:link rel="ot" href="$ou"/>
<atom:link rel="db" type="app/c.d.p+xml" href="e.xml">
<atom:inline>
<payload xmlns="http://www.yyy.com/xxx" model="https://xxxx.yyy.com/api/te/db/et/r1">
<field name="asset.title">
<value>DP</value>
</field>
<field>
<value>xxx</value>
</field>
|
|
|
</atom:inline>
</atom:link>
</atom:entry>
I am trying to get the value DP
of filed whose name="asset.title"
Followed this Doc's and tried but no luck..
http://support.smartbear.com/viewarticle/57106/
http://support.smartbear.com/viewarticle/58850/
How can i get this value. Thanks in advance for any pointer or help.
回答1:
You need to specify selection namespaces when dealing with an XML that has namespaces defined. The following script should work for you.
function test()
{
var fileName = "c:\\test.xml";
var doc = Sys.OleObject("Msxml2.DOMDocument.6.0");
doc.setProperty("SelectionNamespaces", "xmlns:atom='http://www.w3.org/2005/Atom' xmlns:ns='http://www.yyy.com/xxx'");
doc.load(fileName);
var value = doc.selectSingleNode("/atom:entry/atom:inline/ns:payload/ns:field[@name='asset.title']/ns:value").text;
Log.Message(value);
}
来源:https://stackoverflow.com/questions/24138706/getting-a-nodes-value-from-xml-file-in-testcomplete