0

if this code:

$s = 'BrowseNodes/BrowseNode';
$temp_bnid=$item->xpath($s);
echo '<pre>
Root Search:
';
print_r($temp_bnid);
echo '</pre>';
die('Halted for testing');

gives this output:

Root Search:
Array
(
    [0] => SimpleXMLElement Object
        (
            [BrowseNodeId] => 2522032011
            [Name] => Balls
            [Ancestors] => SimpleXMLElement Object
                (
                    [BrowseNode] => SimpleXMLElement Object
                        (
                            [BrowseNodeId] => 196601011
                            [Name] => Baby & Toddler Toys
                            [Ancestors] => SimpleXMLElement Object
                                (
                                    [BrowseNode] => SimpleXMLElement Object
                                        (
                                            [BrowseNodeId] => 165795011
                                            [Name] => Categories
                                            [IsCategoryRoot] => 1
                                            [Ancestors] => SimpleXMLElement Object
                                                (
                                                    [BrowseNode] => SimpleXMLElement Object
                                                        (
                                                            [BrowseNodeId] => 165793011
                                                            [Name] => Toys & Games
                                                    )

                                                )

                                        )

                                )

                        )

                )

        )

)

Halted for testing

and this code:

$s = 'BrowseNodes/BrowseNode[Name=Categories]';
// I also tried $s = 'BrowseNodes/BrowseNode[Name="Categories"]'; 
$temp_bnid=$item->xpath($s);
echo '<pre>
Root Search:
';
print_r($temp_bnid);
echo '</pre>';
die('Halted for testing');

gives this output:

Root Search:
Array
(
)

Halted for testing

What am I doing wrong, when I am trying to get the BrowseNode node that contains the "Name" node where the "Name" node value is "Categories"? An alternate solution for this issue would be to select the node on the existence of the "IsCategoryRoot" node, but I really want to learn how to do the other query as it might help me more in the future. Niether way worked with the queries I treid.

2
  • Posting the XML you're trying to search might be more helpful than the dump of the SimpleXML object. Commented Feb 8, 2012 at 16:57
  • Can you give a sample of XML input please ? It will be easier to help you. But given what i see : maybe Name is an attribute and if so, you can try : BrowseNodes/BrowseNode[@Name="Categories"]. Commented Feb 8, 2012 at 17:00

2 Answers 2

1

I'm not sure because I can't read the SimpleXML dump effectively, but I think what you have is an arbitrary descendant with a child called Name that contains "Categories". So something like:

BrowseNodes/BrowseNode//BrowseNode[Name="Categories"]

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

4 Comments

Thanks. That did the trick. So it was the double slash to indicate unknown depth and I did need the quotes for "Categories". I think I got it. I tried to click the up arrow to mark this answer helpful, but I don't have enough reputation.
Great! If it was correct, you can click the tick to accept the answer as correct.
Thanks. I thought that was what the up and down votes were for. (Brand new to actually posting in this forum, even though I've been getting answers from it for a couple of years.)
Up and Down are used to vote for useful answers - you can do that on anyones question/answer (once you have enough rep). If you ask a question, you choose which answer is correct.
1

did you try this ?

$s="BrowseNodes/BrowseNode/Name[text()='Categories']/..";

Which should select the parent node (ie: browseNode) for a Name node which text is Categories.

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.