Read XML with XMLDocument in Delphi


I have this xml, I don't know how to read and get the values. can anybody help me?

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="" xmlns:xsd="" xmlns:xsi="">
  <ns1:WsobterdadoscolaboradorResponse soapenv:encodingStyle="" xmlns:ns1="http://DefaultNamespace">
   <WsobterdadoscolaboradorReturn href="#id0"/>
  <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="" xsi:type="ns2:Map" xmlns:soapenc="" xmlns:ns2="">
     <key xsi:type="soapenc:string">empresas</key>
     <value xsi:type="soapenc:string">1,2</value>
     <key xsi:type="soapenc:string">id</key>
     <value xsi:type="soapenc:string">2</value>
     <key xsi:type="soapenc:string">login</key>
     <value xsi:type="soapenc:string">andre</value>
     <key xsi:type="soapenc:string">nome</key>
     <value xsi:type="soapenc:string">Andr&#xE9; Fernando Rodrigues Lima</value>
     <key xsi:type="soapenc:string">senha</key>
     <value xsi:type="soapenc:string">376255bd8b21e8a66734694f5907a1d5</value>


Delphi, since ancient versions, provides two units:

XMLIntf.pas and XMLDoc.pas

To use it, just declare an IXMLDocument variable and use its methods, they are very intuitive:

  XML: IXMLDocument;
  XML:= TXMLDocument.Create(''); //Ou nome de um arquivo, se você for alterá-lo posteriormente
  XML.SaveToFile('Arquivo.xml'); //Ou '' se você especificar esse mesmo nome na construção do objeto

I used an IXMLDocument variable instead of TXMLDocument for the compiler to manage memory automatically. That way you don't need to destroy the component by calling the .Free method

Scroll to Top