Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 472
  • Last Modified:

How to get the value from a tag in XML?

Hello Guys

I have a xml that has two tags, and I need to get the value from them:

<nfeProc versao="1.10"><NFe><infNFe versao="1.10" Id="NFe35100144357085000720550010000026807193646051"><ide></ide><emit><CNPJ>44357085000720</CNPJ>

I need to get the information from <cnpj> that is in <emit>

I also need to get the information from <cnpj> that is in <dest>

Is there any function to get it? I use D7

I am sending the XML to get as an example.

Thanks
Alex
Nfev00000000000000-2680.xml
0
hidrau
Asked:
hidrau
  • 2
  • 2
1 Solution
 
ThommyCommented:
Address your required nodes and get node values...

var
  X: TXMLDocument;
  ANode : IXMLNode;
  s : WideString;


try
    X := TXMLDocument.Create(Application);

    X.FileName:='Nfev00000000000000-2680.xml';
    X.Active:=true;
    
    //Adress first node ..\emit\CNPJ
    ANode := X.DocumentElement.ChildNodes.FindNode('NFe').ChildNodes.FindNode('infNFe').ChildNodes.FindNode('emit').ChildNodes.FindNode('CNPJ');
    ShowMessage(ANode.NodeValue);

    //Adress second node ..\dest\CNPJ
    ANode := X.DocumentElement.ChildNodes.FindNode('NFe').ChildNodes.FindNode('infNFe').ChildNodes.FindNode('dest').ChildNodes.FindNode('CNPJ');
    ShowMessage(ANode.NodeValue);
finally
    X.Free;
end;

Open in new window


Have not yet tested but I feel very confident that it will work ... :o)))
0
 
ThommyCommented:
Have you already tried my solution???
0
 
hidrauAuthor Commented:
Thanks very much!!!
0
 
hidrauAuthor Commented:
thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now