Question

How can I avoid the XPath element not found error/exception during calling XML Get single node action?

  • 13 March 2022
  • 4 replies
  • 11 views

Badge +2

How can I avoid the XPath element not found error/exception during calling XML Get single node action

XML Example:

<Xml>

<data>

<Name>name1</name>

<gender>femail</gender>

<data>

<data>

<Name>name2</name>

<data>

</Xml>

 

where XPath try to find gender


4 replies

Userlevel 3
Badge +7

Hi @Murad Mahmoud​ ,

 

The XML seems to have few issues, I've edited it:

<xml>

<data>

<name>name1</name>

<gender>femail</gender>

</data>

<data>

<name>name2</name>

</data>

</xml>

Now, with any XML its always a best practice to check if the XML is valid or not using the XML: Validate XML Document Action.

 

imageAnd the XPath which was able to successfully retrieve it is this:

 

//gender

 

image 

Now onto the concept of Error Handling, encase the entire set of Actions within a Try Catch like so:

 

image 

The errors are handled gracefully, and the error details are "caught" in the Catch Action.

 

Kind Regards,

Ashwin A.K

Badge +2

Thanks for answering, this is the requirements, the XML is dynamic and sometimes the gender element appears in the XML, and other time did not appear depending on the user answer to show or high the gender, I can not control the XML output

Userlevel 3
Badge +7

In that case, all we can do is encase our Actions within Try Catch and proceed with that.

 

Kind Regards,

Ashwin A.K

Badge +2

The other problem is that will result in performance issues since try-catch is RAM and Processor consumer for large XML file

Reply