简体   繁体   English

UFT API测试如何从XML响应中提取并保存XLS值?

[英]UFT API Test How can I extract and save XLS values from the XML response?

I am new to the UFT API Test, and I need to extract certain values ​​from the XML response to be included in an existing XLS, which will serve as input data for another test. 我是UFT API测试的新手,我需要从XML响应中提取某些值以包含在现有XLS中,该值将用作另一个测试的输入数据。 This is my XML Response: 这是我的XML响应:

   <NS1:Body>
      <NS3:BuscaSaldosCaptacionOut xmlns:NS3="http://www.portal.com/ws/esb/ConsultaCuentasSaldos">
     <SaldosCaptacion>
        <NumeroCliente>51844068</NumeroCliente>
        <Cuenta>0201484326</Cuenta>
        <ProductoCuenta>01</ProductoCuenta>
        <SubProductoCuenta>0382</SubProductoCuenta>
        <Divisa>MXP</Divisa>
        <IdCuenta>0201484326</IdCuenta>
        <SaldoInicialDia>7062.42</SaldoInicialDia>
        <SaldoPromedio>30596.01</SaldoPromedio>
        <SaldoActual>17062.42</SaldoActual>
        <SaldoDisponible>17062.42</SaldoDisponible>
        <EstatusCuenta>A</EstatusCuenta>
     </SaldosCaptacion>
     <SaldosCaptacion>
        <NumeroCliente>51844068</NumeroCliente>
        <Cuenta>0201484371</Cuenta>
        <ProductoCuenta>01</ProductoCuenta>
        <SubProductoCuenta>0340</SubProductoCuenta>
        <Divisa>MXP</Divisa>
        <SaldoInicialDia>6825.11</SaldoInicialDia>
        <SaldoPromedio>8936.26</SaldoPromedio>
        <SaldoActual>6825.11</SaldoActual>
        <SaldoDisponible>6825.11</SaldoDisponible>
        <SaldoRetenido>0.00</SaldoRetenido>
        <EstatusCuenta>A</EstatusCuenta>
     </SaldosCaptacion>
     <SaldosCaptacion>
        <NumeroCliente>51844068</NumeroCliente>
        <Cuenta>0201533729</Cuenta>
        <ProductoCuenta>01</ProductoCuenta>
        <SubProductoCuenta>0363</SubProductoCuenta>
        <Divisa>MXP</Divisa>
        <SaldoInicialDia>28316.52</SaldoInicialDia>
        <SaldoPromedio>6230.52</SaldoPromedio>
        <SaldoActual>7374.52</SaldoActual>
        <SaldoDisponible>7374.52</SaldoDisponible>
        <SaldoRetenido>942.00</SaldoRetenido>
        <EstatusCuenta>A</EstatusCuenta>
     </SaldosCaptacion>
  </NS3:BuscaSaldosCaptacionOut>

I need save "Cuenta" and "SaldoActual" values. 我需要保存“ Cuenta”和“ SaldoActual”值。 (Everybody), and completely ignore how to parameterize them. (每个人),而完全忽略了如何对它们进行参数化。 The "Write to file" option does not work for me. “写入文件”选项对我不起作用。

Try following code. 尝试以下代码。 If it doesn't work then the namespace needs to be changed in code. 如果不起作用,则需要在代码中更改名称空间。 I can't tell the correct namespace because you did post the beginning of the xml file. 我不能告诉正确的名称空间,因为您确实发布了xml文件的开头。 I'm using xml linq which is a Net Library. 我正在使用xml linq,这是一个网络库。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            string xml = File.ReadAllText(FILENAME);

            XElement doc = XElement.Parse(xml);

            var results = doc.Descendants("SaldosCaptacion").Select(x => new {
                Cuenta = (string)x.Element("Cuenta"),
                SaldoActual = (decimal)x.Element("SaldoActual")
            }).ToList();

        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM