web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Get Value from XML - PAD
Power Automate
Answered

Get Value from XML - PAD

(0) ShareShare
ReportReport
Posted on by 15

Hi everyone !

I hope someone help.

 

Here's the thing...

I triyng to get a value from XML, using XPath. But it dosen't work with this XML, i dont know why.

Jayme_0-1656883934673.png

 

I want the CNPJ from <emit>.

I using this syntax: cteProc/CTe/infCTe/emit/CNPJ

 

What i did wrong ?

 

Thx for now !

  • VJR Profile Picture
    7,635 on at

    Hello @Jayme 

    Doesn't look like your syntax is wrong.

     

    How and which actions are you using?

    Is this your sequence?

    - Read XML from file

    - Get Xml element value

     

    Are you able to post the xml text with some dummy data so as to take a look?

     

  • Jayme Profile Picture
    15 on at

    Hello @VJR 

     

    I did the actions inside a loop (for each) like the image below:

    Jayme_0-1656966114411.png 

    The sequence of the actions is:

    - Read XML from file

    - Get Xml element value

  • Jayme Profile Picture
    15 on at

    I'm trying to post the XML text, using the "code sample" but it's not working....

  • VJR Profile Picture
    7,635 on at

    You can also directly post it as text without using code sample.

  • Jayme Profile Picture
    15 on at

    Here it goes !!

     

    <?xml version="1.0" encoding="UTF-8"?>
    <cteProc xmlns="http://www.portalfiscal.inf.br/cte" versao="3.00">
    <CTe xmlns="http://www.portalfiscal.inf.br/cte">
    <infCte versao="3.00" Id="CTe35220604657635000702570010000191831002975423">
    <ide>
    <cUF>3225</cUF>
    <cCT>002987542</cCT>
    <CFOP>533552</CFOP>
    <natOp>A ESTABELECIMENTO INDUSTRIAL</natOp>
    <mod>557</mod>
    <serie>1</serie>
    <nCT>191883</nCT>
    <dhEmi>2022-06-27T10:29:11-03:00</dhEmi>
    <tpImp>1</tpImp>
    <tpEmis>1</tpEmis>
    <cDV>3</cDV>
    <tpAmb>1</tpAmb>
    <tpCTe>0</tpCTe>
    <procEmi>0</procEmi>
    <verProc>1099</verProc>
    <cMunEnv>3550308</cMunEnv>
    <xMunEnv>SAO PAULO</xMunEnv>
    <UFEnv>SP</UFEnv>
    <modal>01</modal>
    <tpServ>0</tpServ>
    <cMunIni>3530805</cMunIni>
    <xMunIni>MOGI MIRIM</xMunIni>
    <UFIni>SP</UFIni>
    <cMunFim>3550308</cMunFim>
    <xMunFim>SAO PAULO</xMunFim>
    <UFFim>SP</UFFim>
    <retira>0</retira>
    <indIEToma>1</indIEToma>
    <toma3>
    <toma>3</toma>
    </toma3>
    </ide>
    <compl>
    <xCaracAd>EMBARQUE</xCaracAd>
    <xCaracSer>HPAE</xCaracSer>
    <xEmi>GILBERTO DOS SANTOS</xEmi>
    <Entrega>
    <noPeriodo>
    <tpPer>4</tpPer>
    <dIni>2022-06-27</dIni>
    <dFim>2022-06-29</dFim>
    </noPeriodo>
    <comHora>
    <tpHor>2</tpHor>
    <hProg>18:00:00</hProg>
    </comHora>
    </Entrega>
    <xObs>KM 269/ CARRETA I0E6480</xObs>
    <ObsCont xCampo="LeiTransparencia">
    <xTexto>LEI DA TRANSPARENCIA 12.741/2012 VALOR APROXIMADO DE TRIBUTOS: R$394,03, (12,00%)</xTexto>
    </ObsCont>
    <ObsCont xCampo="Obs1">
    <xTexto>/ TRANSPORTE SUBCONTRATADO COM: HELIO FURTADO DE LACERDA - PORTADOR DO CPF: 593.105.379-49 E PROPRIETARIO DO VEICULO MARCA/MODELO: SCANIA/P340 - PLACA: EJZ5A54</xTexto>
    </ObsCont>
    <ObsCont xCampo="Obs2">
    <xTexto>- COM O MOTORISTA: ALEXANDRE HENRIQUE DE LACERDA - PORTADOR DO CPF: 394.376.258-71 / HPE / 27/06/2022</xTexto>
    </ObsCont>
    </compl>
    <emit>
    <CNPJ>04657635000702</CNPJ>
    <IE>128304316117</IE>
    <xNome>LOGISTICA DO BRAS LTDA.</xNome>
    <xFant>TK - HPAE CTC</xFant>
    <enderEmit>
    <xLgr>VIA ANHANGUERA</xLgr>
    <nro>S/N</nro>
    <xCpl>COND CE GWXEST</xCpl>
    <xBairro>JARDIM JARAGUA</xBairro>
    <cMun>3550308</cMun>
    <xMun>SAO PAULO</xMun>
    <CEP>05275000</CEP>
    <UF>SP</UF>
    <fone>11317815941131</fone>
    </enderEmit>
    </emit>
    </infCte>
    </CTe>
    </cteProc>
  • VJR Profile Picture
    7,635 on at

    1. Try the "Execute XPath expression" action too

    2. Also check it out at first on any of the free online XPath Tester

  • Jayme Profile Picture
    15 on at

    I already tried with the action "Execute XPath expression" but didn't work for me too.

    Also i've tested my syntax at some online XPath tester... didn't work too.

     

    My guess is... my XML's aren't compatible with XPath... But i don't know why...

  • Alexandre Profile Picture
    15 on at

    Jayme, I am also trying to do the same thing you are traying: read data from brazilian standard invoices xml. I am also strugling with the same problem you are.

    Alexandre_0-1669468127851.png

    I tried different xpath expressions, used help from online xpath editors and testers like xpather.com and nothing works! It returns an error message saying it did not return any value or saying wrong xpath syntax:

     

    Microsoft.Flow.RPA.Desktop.Modules.SDK.ActionException: Expressão XPath inválida fornecida ---> System.Exception: A expressão deve ser avaliada para um conjunto de nós. ---> System.Exception
    --- Fim do rastreamento de pilha de exceções internas ---
    --- Fim do rastreamento de pilha de exceções internas ---
    em Microsoft.Flow.RPA.Desktop.Modules.XML.Actions.Utilities.GetXmlElement(XmlNodeObject xmlNodeObject, String xpathQuery)
    em Microsoft.Flow.RPA.Desktop.Modules.XML.Actions.GetXmlElementValue.Execute(ActionContext context)
    em Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.ActionRunner.Run(IActionStatement statement, Dictionary`2 inputArguments, Dictionary`2 outputArguments)

     

    I looks like there is some issue with PAD and Brazilian standard xml invoices.

  • Verified answer
    VJR Profile Picture
    7,635 on at

    Hi @Jayme 

     

    I have seen issues while using PAD when there are namespaces in XMLs. But the same works when you temporarily remove the xmlns.

     

    For example: in your case the CNPJ is retrieved 

    VJR_6-1669519113332.png

     

    When I use this as the XML:

     

    <?xml version="1.0" encoding="UTF-8"?>
    <cteProc xmlns="http://www.portalfiscal.inf.br/cte" versao="3.00">
    <CTe xmlns="http://www.portalfiscal.inf.br/cte">
    <infCte versao="3.00" Id="CTe35220604657635000702570010000191831002975423">
    <ide>
    <cUF>3225</cUF>

    .

    .

     

     

    XPATH in Get XML Element Value:

    //cteProc/CTe/infCte/emit/CNPJ

     

     

    How to do this dynamically via PAD:

    By using the Replace text action you can remove and add back when necessary.

     

     

    @Alexandre, this could work with you as well.

  • Alexandre Profile Picture
    15 on at

    It worked! Thanks a lot!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 423

#2
11manish Profile Picture

11manish 308 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 177

Last 30 days Overall leaderboard