cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
RickMa
Regular Visitor

how to get XML element value with Name Space

Hi Team,

 

I have one user case to extract the error message from a SOAP web servie response.  The XML is below and my question is how to retrieve the error message from "<ns3:tt_msg_desc>ERROR: Invalid User ID/Password.</ns3:tt_msg_desc>"? I have tried the get XML element attribute and value, but I met problem with the name space in XPATH. Appreciate some one can shed some light. 

 

<?xml version="1.0" encoding="utf-8"?>

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<wsa:To xmlns:wsa="http://www.w3.org/2005/08/addressing" soapenv:actor="" soapenv:mustUnderstand="0">urn:services-qad-com:</wsa:To>
<wsa:Action xmlns:wsa="http://www.w3.org/2005/08/addressing" soapenv:actor="" soapenv:mustUnderstand="0"></wsa:Action>
<wsa:MessageID xmlns:wsa="http://www.w3.org/2005/08/addressing" soapenv:actor="" soapenv:mustUnderstand="0">urn:messages-qad-com:2022-10-09T22:45:17-0500</wsa:MessageID>
<wsa:RelatesTo xmlns:wsa="http://www.w3.org/2005/08/addressing" soapenv:actor="" soapenv:mustUnderstand="0">urn:services-qad-com::QADERP</wsa:RelatesTo>
</soapenv:Header>
<soapenv:Body>
<ns1:maintainDailyLeadPriceResponse xmlns:ns1="urn:schemas-qad-com:xml-services" xmlns="urn:schemas-qad-com:xml-services">
<ns1:result>error</ns1:result>
<ns2:dsSessionContext xmlns:ns2="urn:schemas-qad-com:xml-services:common">
<ns2:ttContext>
<ns2:propertyQualifier>QAD</ns2:propertyQualifier>
<ns2:propertyName>domain</ns2:propertyName>
<ns2:propertyValue>PSCN</ns2:propertyValue>
</ns2:ttContext>
<ns2:ttContext>
<ns2:propertyQualifier>QAD</ns2:propertyQualifier>
<ns2:propertyName>scopeTransaction</ns2:propertyName>
<ns2:propertyValue>false</ns2:propertyValue>
</ns2:ttContext>
<ns2:ttContext>
<ns2:propertyQualifier>QAD</ns2:propertyQualifier>
<ns2:propertyName>version</ns2:propertyName>
<ns2:propertyValue>ERP3_1x</ns2:propertyValue>
</ns2:ttContext>
<ns2:ttContext>
<ns2:propertyQualifier>QAD</ns2:propertyQualifier>
<ns2:propertyName>mnemonicsRaw</ns2:propertyName>
<ns2:propertyValue>false</ns2:propertyValue>
</ns2:ttContext>
<ns2:ttContext>
<ns2:propertyQualifier>QAD</ns2:propertyQualifier>
<ns2:propertyName>username</ns2:propertyName>
<ns2:propertyValue>xxxx</ns2:propertyValue>
</ns2:ttContext>
<ns2:ttContext>
<ns2:propertyQualifier>QAD</ns2:propertyQualifier>
<ns2:propertyName>password</ns2:propertyName>
<ns2:propertyValue>******</ns2:propertyValue>
</ns2:ttContext>
<ns2:ttContext>
<ns2:propertyQualifier>QAD</ns2:propertyQualifier>
<ns2:propertyName>action</ns2:propertyName>
<ns2:propertyValue/>
</ns2:ttContext>
<ns2:ttContext>
<ns2:propertyQualifier>QAD</ns2:propertyQualifier>
<ns2:propertyName>entity</ns2:propertyName>
<ns2:propertyValue/>
</ns2:ttContext>
<ns2:ttContext>
<ns2:propertyQualifier>QAD</ns2:propertyQualifier>
<ns2:propertyName>email</ns2:propertyName>
<ns2:propertyValue/>
</ns2:ttContext>
<ns2:ttContext>
<ns2:propertyQualifier>QAD</ns2:propertyQualifier>
<ns2:propertyName>emailLevel</ns2:propertyName>
<ns2:propertyValue/>
</ns2:ttContext>
</ns2:dsSessionContext>
<ns3:dsExceptions xmlns:ns3="urn:schemas-qad-com:xml-services:common">
<ns3:temp_err_msg>
<ns3:tt_level xsi:nil="true"/>
<ns3:tt_msg_context/>
<ns3:tt_msg_data/>
<ns3:tt_msg_datetime>2022-10-09T22:45:16-0500</ns3:tt_msg_datetime>
<ns3:tt_msg_desc>ERROR: Invalid User ID/Password.</ns3:tt_msg_desc>
<ns3:tt_msg_field/>
<ns3:tt_msg_index>0</ns3:tt_msg_index>
<ns3:tt_msg_keys/>
<ns3:tt_msg_keys/>
<ns3:tt_msg_keys/>
<ns3:tt_msg_keys/>
<ns3:tt_msg_keys/>
<ns3:tt_msg_keys/>
<ns3:tt_msg_nbr>MfgProErrorMessage</ns3:tt_msg_nbr>
<ns3:tt_msg_processed>false</ns3:tt_msg_processed>
<ns3:tt_msg_sev>error</ns3:tt_msg_sev>
</ns3:temp_err_msg>
<ns3:temp_err_msg>
<ns3:tt_level xsi:nil="true"/>
<ns3:tt_msg_context/>
<ns3:tt_msg_data/>
<ns3:tt_msg_datetime>2022-10-09T22:45:16-0500</ns3:tt_msg_datetime>
<ns3:tt_msg_desc>ERROR: Unable to initialize session.</ns3:tt_msg_desc>
<ns3:tt_msg_field/>
<ns3:tt_msg_index>1</ns3:tt_msg_index>
<ns3:tt_msg_keys/>
<ns3:tt_msg_keys/>
<ns3:tt_msg_keys/>
<ns3:tt_msg_keys/>
<ns3:tt_msg_keys/>
<ns3:tt_msg_keys/>
<ns3:tt_msg_nbr>MfgProErrorMessage</ns3:tt_msg_nbr>
<ns3:tt_msg_processed>false</ns3:tt_msg_processed>
<ns3:tt_msg_sev>error</ns3:tt_msg_sev>
</ns3:temp_err_msg>
</ns3:dsExceptions>
</ns1:maintainDailyLeadPriceResponse>
</soapenv:Body>
</soapenv:Envelope>

2 ACCEPTED SOLUTIONS

Accepted Solutions
kinuasa
Resolver IV
Resolver IV

Hi,
I recommend using the local-name function as follows.

 

//*[local-name()='tt_msg_desc']/text()

 

Regards,
kinuasa

 

Sample Flow:

XML.ReadFromFile File: $'''C:\\Test\\Sample.xml''' Encoding: XML.FileEncoding.UTF8 XmlDocument=> XmlDocument
XML.ExecuteXPathQuery.ExecuteXPath XmlDocument: XmlDocument XPathQuery: $'''//*[local-name()=\'tt_msg_desc\']/text()''' XPathResults=> XPathResults
LOOP FOREACH CurrentItem IN XPathResults
    Display.ShowMessageDialog.ShowMessage Message: CurrentItem Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: True ButtonPressed=> ButtonPressed
END

View solution in original post

Hi @RickMa 

 

The solution shared by @kinuasa  did work giving out a List of the values for the XML you shared.

Could you double check everything.

 

VJR_0-1665983523065.png

 

View solution in original post

4 REPLIES 4
kinuasa
Resolver IV
Resolver IV

Hi,
I recommend using the local-name function as follows.

 

//*[local-name()='tt_msg_desc']/text()

 

Regards,
kinuasa

 

Sample Flow:

XML.ReadFromFile File: $'''C:\\Test\\Sample.xml''' Encoding: XML.FileEncoding.UTF8 XmlDocument=> XmlDocument
XML.ExecuteXPathQuery.ExecuteXPath XmlDocument: XmlDocument XPathQuery: $'''//*[local-name()=\'tt_msg_desc\']/text()''' XPathResults=> XPathResults
LOOP FOREACH CurrentItem IN XPathResults
    Display.ShowMessageDialog.ShowMessage Message: CurrentItem Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: True ButtonPressed=> ButtonPressed
END
RickMa
Regular Visitor

Thanks for recommendation. The xpath query syntax works, but it is weird that it return me "No element". Do you have any idea about it? 

 

Microsoft.Flow.RPA.Desktop.Modules.SDK.ActionException: XPath expression returned no element. ---> System.ApplicationException: Error in the application.
--- End of inner exception stack trace ---
at Microsoft.Flow.RPA.Desktop.Modules.XML.Actions.Utilities.GetXmlElement(XmlNodeObject xmlNodeObject, String xpathQuery)
at Microsoft.Flow.RPA.Desktop.Modules.XML.Actions.GetXmlElementValue.Execute(ActionContext context)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.ActionRunner.Run(IActionStatement statement, Dictionary`2 inputArguments, Dictionary`2 outputArguments)

Hi @RickMa 

 

The solution shared by @kinuasa  did work giving out a List of the values for the XML you shared.

Could you double check everything.

 

VJR_0-1665983523065.png

 

RickMa
Regular Visitor

Hi, 

 

The reason is that I used xpath query in Get XML element value component which brought me the error message. It did work as it was mentioned in Execute Xpath expression. Thank you all for help. 

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (4,773)