How to get the next element using XPath

Hi,

I'm trying to get the next element from the xml using the XPath from the Extract Variables. The element is dynamic. How to get the next element(not the value) after from the below xml.

For the below xml I should get as InvalidFault.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

<soap:Body>

<soap:Fault>

<faultcode>soap:Server</faultcode>

<faultstring>maximum length is 13</faultstring>

<detail>

<InvalidFault xmlns="http://abc.com/xyz.xsd">

<message>Incorrect</message>

</InvalidFault>

</detail>

</soap:Fault>

</soap:Body>

</soap:Envelope>

Thanks

Tiru

0 6 3,085
6 REPLIES 6

Hi @Tirumala Muddana

1st your xml is not valid so I have fixed the xml sample you have provided.

<soap:Envelope
	xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
	<soap:Body>
		<soap:Fault>
			<faultcode>soap:Server</faultcode>
			<faultstring>maximum length is 13</faultstring>
			<detail>


http://abc.com/xyz.xsd">
				<InvalidFault>
					<message>Incorrect</message>
				</InvalidFault>
			</detail>
		</soap:Fault>
	</soap:Body>
</soap:Envelope>

Now coming on your question -

are you asking the to get element after any xyz element for e.g in your xml <faultcode> is one element and you want to get <faultstring> as a dynamic element using xpath? it can be anything, right? if yes, you need to do some small calculation using javascript and extract variable polices. you need to calculate the position of current element the then increment for next element. take a ref here - https://www.w3schools.com/xml/xml_xpath.asp

Thank you Ravindra, is there anyway can we get the next element through XPath?

I am not clear with your question, please provide more information if above answer is not helping you out.

Instead of doing in javascript can we do directly in extract variables using the XPath to get the element name from the xml?

try /bookstore/book[position()+1] pattern. if this works for you.

Not sure if this is going to help you but i tried to get second custom attribute of api product using xpath which I was able to do it.if you need dynamic xpath based on position should go with JS policy definitely along with extract variable policy..

/ApiProduct/Attributes/Attribute[2]

screen-shot-2019-07-22-at-113217-pm.png