Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xpath expressions

Tags:

xml

xpath

I am in need to get the value of <mathcolor> element for the element <colorvalue> has value 2. Please correct the Xpath expression given below:

Xpath Expression tried:

/colors/child::color/child::mathcolor[colorvalue='2']

Sample XML:

<?xml version="1.0"?>
<colors>
    <color>
        <mathcolor>#007dc5</mathcolor>
        <textcolor>C=100 M=40 Y=0 K=0</textcolor>
        <colorvalue>2</colorvalue>
    </color>
    <color>
        <mathcolor>#ed1b34</mathcolor>
        <textcolor>C=0 M=100 Y=85 K=0</textcolor>
        <colorvalue>3</colorvalue>
    </color>
</colors>
like image 464
siva2012 Avatar asked Oct 22 '22 13:10

siva2012


1 Answers

Almost, try that:

/colors/child::color[colorvalue='2']/child::mathcolor/text()

or simpler

/colors/color[colorvalue='2']/mathcolor/text()
like image 93
TheEwook Avatar answered Oct 28 '22 22:10

TheEwook