xml - PHP xpath not able to find child node but finds parent

922

I am able to load an XML document and create a SimpleXMLElement - I am also able to query it using XPATH but I am perplexed by the behavior I am noticing. When I load the XML and create a SimpleXMLElement - it is of the below structure

XML is as below

 <StructuredXMLResume>
        <ContactInfo>
            <PersonName>
                <FullName>Tom Jones</FullName>
                <GivenName>Tom</GivenName>
                <MiddleName />
                <FamilyName>Jones</FamilyName>
            </PersonName>
       </ContactInfo>
 </StructuredXMLResume>


[0] => SimpleXMLElement Object
        (
            [PersonName] => SimpleXMLElement Object
                (
                    [FullName] => Tom Jones
                    [GivenName] => Tom
                    [MiddleName] => SimpleXMLElement Object
                        (
                        )

                    [FamilyName] => Jones
                )

When I execute$xml->xpath('//PersonName') I get the right result which is as below

[0] => SimpleXMLElement Object
        (
            [FullName] => Tom Jones
            [GivenName] => Tom
            [MiddleName] => SimpleXMLElement Object
                (
                )

            [FamilyName] => Jones
        )

But when I execute$xml->xpath('//GivenName') I get the below result - which I am unable to understand

[0] => SimpleXMLElement Object
        (
        )

Can someone please help me understand what my error is?

People are also looking for solutions to the problem: javascript - changing php variable on "scroll"

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.