cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Doubt with XPath expression Using XML

former_member740482
Participant
0 Likes
893

Dear experts,

I am creating the following iflow:

The iflow have the folling information:

<?xml version="1.0" encoding="UTF-8" ?>
<articles>
    <article>
        <title>First steps in Java</title>
        <author id="1">
            <firstname>Siena</firstname>
            <lastname>Kerr</lastname>
        </author>
        <release-date>2018-12-01</release-date>
    </article>
    <article>
        <title>Dockerize your SpringBoot application</title>
        <author id="2">
            <firstname>Jonas</firstname>
            <lastname>Lugo</lastname>
        </author>
        <release-date>2018-12-01</release-date>
    </article>
    <article>
        <title>SpringBoot tutorial</title>
        <author id="3">
            <firstname>Daniele</firstname>
            <lastname>Ferguson</lastname>
        </author>
        <release-date>2018-06-12</release-date>
    </article>
    <article>
        <title>Java 12 insights</title>
        <author id="1">
            <firstname>Siena</firstname>
            <lastname>Kerr</lastname>
        </author>
        <release-date>2018-07-22</release-date>
    </article>
</articles>

I want get the value of the first id of the Author with id = 1 .

For this I have created a step using content modififier and I am creating a property called author , source type XPATH and Source Value /articles.article[0].author.author

However this not work,

How can get this value and storage in the variable author and firstname?

Name: author

Source Type: XPath

Source Value : /articles.article[0].author.id

Name: firstname

Source Type: XPath

Source Value : /articles.article[0].author.firstname

Regards

View Entire Topic
PriyankaChak
SAP Champion
SAP Champion
0 Likes

Hi,

For id value, you can use string(/articles/article[1]/author[@id='1']/@id) or string(/articles/article[1]/author/@id). However, I did not understand the necessity of finding the id value from Xpath expression. If id value = 1 always, you can just hardcode it.

If you want to find id value based on first name and last name, use the below.

string(/articles/article[1]/author[./firstname[text() = 'Siena'] and ./lastname[text() = 'Kerr']]/@id)

Regards,

Priyanka