在TestComplete得到一个节点的值从XML文件 [英] getting a node's value from XML file in TestComplete
问题描述
我的XML文件的结构是这样的..
<?XML版本=1.0编码=UTF-8&GT?;
<原子:入门的xmlns:原子=http://www.w3.org/2005/Atom的xmlns:核心=http://x.y.com/xy/xyz>
<原子:标题> TestTitle< /原子:标题>
<原子:链接rel =一个的href =$ a_u/>
<原子:链接rel =OT的href =$ OU/>
<原子:链接rel =DB类型=应用/ c.d.p + XMLHREF =e.xml>
<原子:直列>
<有效载荷的xmlns =http://www.yyy.com/xxx模式=https://xxxx.yyy.com/api/te/db/et/r1>
<字段名=asset.title>
< VALUE>&DP LT; /值>
< /场>
<场及GT;
< VALUE> XXX和LT; /值>
< /场>
|
|
|
< /原子:直列>
< /原子:链接>
< /原子:进入>
我想获得的申请 DP
的 NAME =asset.title
遵循了这一文件的,并试图,但没有运气..
http://support.smartbear.com/viewarticle/57106/
http://support.smartbear.com/viewarticle/58850/
我怎样才能得到这个值。预先感谢任何指针或帮助。
您需要指定选择命名空间与具有定义的命名空间的XML的时候。下面的脚本应该为你工作。
功能测试()
{
变种文件名=C:\\\\的test.xml
变种文档= Sys.OleObject(Msxml2.DOMDocument.6.0);
doc.setProperty(SelectionNamespaces,的xmlns:原子=HTTP://www.w3.org/2005/Atom'的xmlns:NS =的http://www.yyy.com/xxx');
doc.load(文件名); VAR值= doc.selectSingleNode(\"/atom:entry/atom:inline/ns:payload/ns:field[@name='asset.title']/ns:value\").text;
Log.Message(值);
}
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.
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);
}
这篇关于在TestComplete得到一个节点的值从XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!