Read XML ASP Classico

0

How to redeem the value of the ValId field?

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <ns1:AbcResponse xmlns:ns1="http://esec.com.br/mss/ap">
         <SignatureResp xmlns:ns2="http://esec.com.br/mss/ap">
            <Status>
               <StatusCode>100</StatusCode>
               <Message>OK</StatusMessage>
            </Status>
            <DocumentStatus ValId="12345678">
               <DocumentN>Teste</DocumentN>
               <Status>
                  <StatusCode>123</StatusCode>
                  <Message>SIGNATURE_VALID</Message>
                  <Detail>tudo OK</Detail>
               </Status>
            </DocumentStatus>
         </SignatureResp>
      </ns1:AbcResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
    
asked by anonymous 11.08.2018 / 04:42

1 answer

0

As I explained in this answer link you can use the "synchronized" way (this is because it is a web application and not "Desktop"), for your case it should look like this:

Dim url

url = Server.MapPath("/pasta/aonde/esta/xml/exemplo.xml")

Set doc = CreateObject("MSXML2.DOMDocument")
doc.load url
doc.async = False

'Seleciona com XPATH
Set nodes = doc.SelectNodes("//DocumentStatus")

'Lê todos que encontrar
For Each node In nodes
    Response.Write "ValId:" & node.Attributes.getNamedItem("ValId").Text & "<br>"
Next

Now if you want to read from an external server you may have to use MSXML2.XMLHTTP , as in the other but simplified answer:

Dim xhr, url, doc

Set xhr = CreateObject("MSXML2.XMLHTTP")

url = "http://dominio/exemplo.xml" 'url da API

xhr.Open "GET", url, False

xhr.send

If xhr.status < 200 Or xhr.status >= 300 Then
    'Algo falhou, as vezes pode haver uma descrição em 'xhr.responseText' ou pode retornar vazio, o 'xhr.status' indica o tipo de erro
    MsgBox "Erro HTTP:" & xhr.status & " - Detalhes: " & xhr.responseText
Else
    'Faz o parse da String para XML
    Set doc = CreateObject("MSXML2.DOMDocument")
    doc.loadXML(xhr.responseText)

    'Seleciona com XPATH
    Set nodes = doc.SelectNodes("//DocumentStatus")

    'Lê todos que encontrar
    For Each node In nodes
        Response.Write "ValId:" & node.Attributes.getNamedItem("ValId").Text & "<br>"
    Next
End If

Of course I understand that this is SOAP, and probably the sending is done via POST, but if that is the case then I believe you have already done the HTTP request part and its only need to read as Xml, so if this is I think that maybe xhr.ResponseXML will already work (I will review the code for both responses), but if it does not work, then with SelectNodes within your response to SOAP sending execute this:

    'Faz o parse da String para XML
    Set doc = CreateObject("MSXML2.DOMDocument")
    doc.loadXML(<aqui vai o teu responseText>)

    'Seleciona com XPATH
    Set nodes = doc.SelectNodes("//DocumentStatus")

    'Lê todos que encontrar
    For Each node In nodes
        Response.Write "ValId:" & node.Attributes.getNamedItem("ValId").Text & "<br>"
    Next
  

I promise to see the possibility of simple codes

    
11.08.2018 / 06:15