XPath does not recognize XML elements

2

I have an XML. But something is happening that I do not understand.  When I try to use XPath to return the Author elements, using //Author (I tested it via link ) is only bringing only the ones contained in the SearchBookResponse tag:

<author>Robert Ludlum</author>
<author>Douglas Adams</author>
<author>Dr. Seuss (Theodor Seuss Geisel)</author>

How do I make it recognize the contents within the searchForBooksReturn tag?

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
       <LibrarySearchResponse xmlns="urn:soft.librarysearch" xmlns:tns="urn:soft.librarysearch">
           <tns:query />
           <tns:books xmlns:nl="http://library.be">
               <searchBooksResponse xmlns="urn:soft.vub.ac.be/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                   <book xmlns="">
                       <author>Robert Ludlum</author>
                       <year>2004</year>
                       <isbn>95248457</isbn>
                       <language>fr</language>
                       <publisher>Orion</publisher>
                       <title>La Mémoire dans la peau (SOFT Library)    </title>
                </book>
                <book xmlns="">
                    <author>Douglas Adams</author>
                    <year>2002</year>
                    <isbn>60184547</isbn>
                    <language>fr</language>
                    <publisher>Del Rey</publisher>
                    <title>Le Guide du Voyageur Galactique (SOFT Library)</title>
                </book>
                <book xmlns="">
                    <author>Dr. Seuss (Theodor Seuss Geisel)</author>
                    <year>2008</year>
                    <isbn>606559890</isbn>
                    <language>fr</language>
                    <publisher>Amulet Books</publisher>
                    <title>Horton Entend un Zou! (SOFT Library)</title>
                </book>
            </searchBooksResponse>
            <searchForBooksReturn xmlns="http://library.be" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <author>James, E. L.</author>
                <date>3914-01-10T23:00:00.000Z</date>
                <isbn>0345803485</isbn>
                <language>English</language>
                <publisher>Vintage Books</publisher>
                <title>50 Shades of Grey (National Library)</title>
            </searchForBooksReturn>
            <searchForBooksReturn xmlns="http://library.be" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <author>James Dashner</author>
                <date>3914-04-20T22:00:00.000Z</date>
                <isbn>0385388896</isbn>
                <language>English</language>
                <publisher>The Maze Runner Series</publisher>
                <title>The Maze Runner Series (National Library)</title>
            </searchForBooksReturn>
            <searchForBooksReturn xmlns="http://library.be" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <author>William Sleator</author>
                <date>3908-03-31T22:00:00.000Z</date>
                <isbn>0810993562</isbn>
                <language>English</language>
                <publisher>Amulet Books</publisher>
                <title>Test (National Library)</title>
            </searchForBooksReturn>
            <searchForBooksReturn xmlns="http://library.be" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <author>Michalewicz, Zbigniew  Fogel, David B.</author>
                <date>3912-10-31T23:00:00.000Z</date>
                <isbn>9783642061349</isbn>
                <language>English</language>
                <publisher>Del Rey</publisher>
                <title>How to Solve It: Modern Heuristics (National Library)</title>
            </searchForBooksReturn>
            <searchForBooksReturn xmlns="http://library.be" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <author>Ludlum, R</author>
                <date>3913-10-31T23:00:00.000Z</date>
                <isbn>9783642061149</isbn>
                <language>English</language>
                <publisher>Del Rey</publisher>
                <title>The Matarese Circle (National Library)</title>
            </searchForBooksReturn>
            <searchForBooksReturn xmlns="http://library.be" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <author>Ludlum, R</author>
                <date>3911-10-31T23:00:00.000Z</date>
                <isbn>9783642461149</isbn>
                <language>English</language>
                <publisher>Del Rey</publisher>
                <title>The Parsifal Mosaic (National Library)</title>
            </searchForBooksReturn>
        </tns:books>
    </LibrarySearchResponse>
</soapenv:Body>
</soapenv:Envelope>

Thank you in advance, thanks!

    
asked by anonymous 04.05.2016 / 01:47

1 answer

1

XPath is not working because XML namespaces are being used (namespaces serve to resolve name conflicts > between HTML tags). To solve the situation, what you can do, is to write the following expression:

//*[name()='author']

Using the name () function you are able to select all elements " <author> " equivalent to " </author> ".

    
30.05.2016 / 14:19