如何使用UFT 12.0获取xml标记值

时间:2015-04-01 05:42:13

标签: qtp

我有一个方案来读取uft

中的xml文件标记值
 <?xml version="1.0" encoding="ISO-8859-1" standalone="yes" ?> 
- <SUBCUSTBRK>
  <CONN NO="01415500228" /> 
  <AccNo NO="8500098" /> 
  <Site NAME="317009068" /> 
  <SiteLocDesc NAME="11098946" /> 
  <ServNumLable NAME="" /> 
  <Status /> 
  <Currency /> 
  <DOB>2015-03-26</DOB> 
  <InvNo /> 
  <DOBFrmt>2015 MAR</DOBFrmt> 
  <Month>March</Month> 
  <Week>2015 W13(MAR26)</Week> 
  <Day>Day 85</Day> 
  <Dur>1558</Dur> 
  <Calls>35</Calls> 
  <Amt>1.337</Amt> 
  <MinDate>2014-05-26</MinDate> 
  <MaxDate>2014-06-25</MaxDate> 
  <BS>SSBS</BS> 
  <ServInfo>1</ServInfo> 
  <ZeroCalls>0</ZeroCalls> 
+ <Country>
  <ROW Area="SPECIAL SERVICES (08)" ServType="PSTN" CallType="Unknown" AccessType="Indirect" Calls="35" Amt="1.337" Dur="1558" Int="0" Flag="1" StndCalls="35" StndDur="1558" StndAmt="1.337" EconCalls="0" EconDur="0" EconAmt="0.000" PrimCalls="0" PrimDur="0" PrimAmt="0.000" /> 
  </Country>
- <CalledNumbers>
  <ROW Num="08445768263" ServType="PSTN" CallType="Unknown" AccessType="Indirect" Calls="13" Amt="0.500" Dur="583" Area="SPECIAL SERVICES (08)" StndCalls="13" StndDur="583" StndAmt="0.500" EconCalls="0" EconDur="0" EconAmt="0.000" PrimCalls="0" PrimDur="0" PrimAmt="0.000" /> 
  <ROW Num="08445768260" ServType="PSTN" CallType="Unknown" AccessType="Indirect" Calls="2" Amt="0.106" Dur="125" Area="SPECIAL SERVICES (08)" StndCalls="2" StndDur="125" StndAmt="0.106" EconCalls="0" EconDur="0" EconAmt="0.000" PrimCalls="0" PrimDur="0" PrimAmt="0.000" /> 
  <ROW Num="08445768262" ServType="PSTN" CallType="Unknown" AccessType="Indirect" Calls="18" Amt="0.677" Dur="788" Area="SPECIAL SERVICES (08)" StndCalls="18" StndDur="788" StndAmt="0.677" EconCalls="0" EconDur="0" EconAmt="0.000" PrimCalls="0" PrimDur="0" PrimAmt="0.000" /> 
  <ROW Num="08445768261" ServType="PSTN" CallType="Unknown" AccessType="Indirect" Calls="2" Amt="0.054" Dur="62" Area="SPECIAL SERVICES (08)" StndCalls="2" StndDur="62" StndAmt="0.054" EconCalls="0" EconDur="0" EconAmt="0.000" PrimCalls="0" PrimDur="0" PrimAmt="0.000" /> 
  </CalledNumbers>
- <DETAIL>
+ <TRANSACTION Type="PSTN" ServiceType="PSTN" Calls="35" Units="0" Amt="1.337" Usage="usage" Duration="1558" DOB="2015-03-26" BS="SSBS" Acc="0" FileName="CMNP">
  <H1>PSTN</H1> 
- <H2>
  <C1 DT="Text">Call Charges</C1> 
  <C2 DT="Text">Rate Period</C2> 
  <C3 DT="Number">No.of Calls</C3> 
  <C4 DT="Number">Units</C4> 
  <C5 DT="Money">R.O</C5> 
  </H2>
  <SUB_SECTION Type="Unknown" CategoryType="Voice" RP="0" Calls="35" Units="0" Duration="1558" Amt="1.337" /> 
  </TRANSACTION>
  </DETAIL>

在这个xml中我需要Transaction标签ServiceType =&#34; PSTN&#34;呼叫=&#34; 35&#34; 那我该如何阅读这些值呢?任何人都可以帮助我吗? 提前完成。

1 个答案:

答案 0 :(得分:1)

这可以通过UFT中的XMLUTIL和创建XML DOM来完成。请在下面找一个例子。

XmlDom1 =CreateObject("Microsoft.XMLDOM")
XmlDom1.load(<xmlPath>)
Msgbox XMLDOM1.SelectSingleNode("//Transaction/@ServiceType").text
Msgbox XMLDOM1.SelectSingleNode("//Transaction/@Calls").text