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

Doubt with XPath expression Using XML

former_member740482
Participant
0 Likes
887

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

Accepted Solutions (1)

Accepted Solutions (1)

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

Answers (3)

Answers (3)

Sriprasadsbhat
Active Contributor

Hello Party,

Below will give desired output.

/articles/article[1]/author[@id = '1']/firstname/text()

Regards,

Sriprasad Shivaram Bhat

former_member740482
Participant
0 Likes

Hi sriprasadshivaramabhat

  1. With source value: /articles/article[1]/author[@id = '1']/firstname/text()

Output.

2. With source value: /articles/article[1]/author[@id = '1']/text()

Output.

3. With source value: /articles/article[1]/author[@id = '1']

NameValue: author

value: Siena Kerr

How can get the value of the attribute id? ie 1 for this case

former_member740482
Participant
0 Likes

Thank you for all.

former_member190293
Active Contributor
0 Likes

Hi! If you want to use some data from first element with id=1, you can use:

/articles.article[author/@id="1"][1]/...

Regards, Evgeniy.