Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: XPath to get attributes


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Mar 23, 2018 9:59 AM Last Post By: Alejandro Castro Threads: [ Previous | Next ]
Alejandro Castro

Posts: 9
Registered: 2/19/07
XPath to get attributes  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 22, 2018 6:22 PM
<?xml version="1.0" encoding="UTF-8"?>
<cfdi:Comprobante xmlns:cfdi="http://www.sat.gob.mx/cfd/3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv33.xsd" 
      Version="3.3" Serie="PAGAA" Folio="16" Fecha="2017-12-19T23:33:12"
      Sello="qtMqROtw==" NoCertificado="30001000000300023708" Certificado="gY1TY86vL2o8gZ8r" SubTotal="0" Moneda="XXX" Total="0" TipoDeComprobante="P" LugarExpedicion="14643">
   <cfdi:Emisor *** *Rfc="BBB010101AAA"* *** Nombre="Empresa de prueba SA de CV" RegimenFiscal="601"/>
   <cfdi:Receptor Rfc="XAXX010101000" Nombre="Juan Perez" UsoCFDI="P01"/>
   <cfdi:Conceptos><cfdi:Concepto ClaveProdServ="84111506" Cantidad="1" ClaveUnidad="ACT" Descripcion="Pago" ValorUnitario="0" Importe="0">
      </cfdi:Concepto>
   </cfdi:Conceptos>
   <cfdi:Complemento>
      <tfd:TimbreFiscalDigital xmlns:tfd="http://www.sat.gob.mx/TimbreFiscalDigital" xsi:schemaLocation="http://www.sat.gob.mx/TimbreFiscalDigital http://www.sat.gob.mx/sitio_internet/cfd/TimbreFiscalDigital/TimbreFiscalDigitalv11.xsd" 
          Version="1.1" UUID="8B5F3A2C-77A6F4EDCE3D" FechaTimbrado="2017-12-19T23:34:43" RfcProvCertif="FEL100622S88" 
          SelloCFD="MGmY1chtVOYYBlfU005uVMLRMqROtw==" NoCertificadoSAT="20001000000300022323" SelloSAT="K6hVQCQhdLg=="/>
      <pago10:Pagos xmlns:pago10="http://www.sat.gob.mx/Pagos" xmlns:catPagos="http://www.sat.gob.mx/sitio_internet/cfd/catalogos/Pagos" xsi:schemaLocation="http://www.sat.gob.mx/Pagos http://www.sat.gob.mx/sitio_internet/cfd/catalogos/Pagos/catPagos.xsd"
          Version="1.0">
         <pago10:Pago FechaPago="2017-12-01T00:00:00" FormaDePagoP="01" MonedaP="MXN" Monto="1160.00" NumOperacion="0">
            <pago10:DoctoRelacionado IdDocumento="635A5A13-957FDC3717B3" Serie="AA" Folio="103" MonedaDR="MXN" MetodoDePagoDR="PPD" 
                NumParcialidad="1" *** *ImpSaldoAnt="11600.00"* *** ImpPagado="1160.00" ImpSaldoInsoluto="10440.00"/>
         </pago10:Pago>
      </pago10:Pagos>
   </cfdi:Complemento>
</cfdi:Comprobante>


How can I get the following attributes:
Rfc="BBB010101AAA"
ImpSaldoAnt="11600.00"

Using XPath?

Thank you

Alejandro Castro
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: XPath to get attributes  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 22, 2018 7:46 PM   in response to: Alejandro Castro in response to: Alejandro Castro
Alejandro Castro wrote:

How can I get the following attributes:
Rfc="BBB010101AAA"
ImpSaldoAnt="11600.00"

Using XPath?

Assuming you are using TXMLDocument's MSXML DOMVendor (which is the
default on Windows. The code will require some tweaking if you are
using a different DOMVendor):

uses
  ..., Xml.XmlIntf, Xml.XmlDom, Xml.XmlDoc, Xml.Win.msxmldom,
Winapi.msxml;
 
...
 
var
  Doc: IXMLDocument;
  doc2: IXMLDOMDocument2;
  ns: IDOMNodeSelect;
  nodes: IDOMNodeList;
  I: Integer;
begin
  ...
  Doc := ...; // load XML into Doc as needed...
 
  if Supports(Doc.DocumentElement.DOMNode, IDOMNodeSelect, ns) then
  begin
    if Supports((Doc.DOMDocument as TMSDOMDocument).MSDocument,
IXMLDOMDocument2, doc2) then
    begin
      doc2.setProperty('SelectionNamespaces',
        'xmlns:cfdi=''http://www.sat.gob.mx/cfd/3'' ' +
        'xmlns:pago10=''http://www.sat.gob.mx/Pagos'' ' +
 
'xmlns:catPagos=''http://www.sat.gob.mx/sitio_internet/cfd/catalogos/Pagos'''
      );
    end;
 
    nodes := ns.selectNodes('/cfdi:Comprobante/cfdi:Emisor/@Rfc');
    if nodes <> nil then
    begin
      for i := 0 to nodes.length-1 do
      begin
        // use nodes[i].nodeValue as needed...
      end;
    end;
 
    nodes :=
ns.selectNodes('/cfdi:Comprobante/cfdi:Complemento/pago10:Pagos/pago10:P
ago/pago10:DoctoRelacionado/@ImpSaldoAnt');
    if nodes <> nil then
    begin
      for i := 0 to nodes.length-1 do
      begin
        // use nodes[i].nodeValue as needed...
      end;
    end;
  end else
  begin
    // XPath not supported!
  end;
 
  ...
end;


--
Remy Lebeau (TeamB)
Alejandro Castro

Posts: 9
Registered: 2/19/07
Re: XPath to get attributes  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 23, 2018 9:59 AM   in response to: Alejandro Castro in response to: Alejandro Castro
Thank you
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02