1

I need XPath syntax (for use in simplexml) for searching the contents of the LayoutPosNo element that matches exactly, say, the number 1001 and returning the text in the sibling Descrip element. The LayoutPosNo's are all unique, so I only need the first match.

Here is the structure of the XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <record>
        <LayoutPosNo>10</LayoutPosNo>
        <Descrip>This is the red room</Descrip>
    </record>
    <record>
        <LayoutPosNo>993</LayoutPosNo>
        <Descrip>This is the yellow room</Descrip>
    </record>
    <record>
        <LayoutPosNo>1001</LayoutPosNo>
        <Descrip>This is the purple room</Descrip>
    </record>
</data-set>

1 Answer 1

1

The following XPath

/data-set/record[LayoutPosNo = 1001]/Descrip/text()

will select

This is the purple room

as requested.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.