I am using xml data using a url & because the xml is too long I just want to check condition to get particular node values only :-
Here is my code :-
<?php
$doc = new DOMDocument('1.0', 'utf-8');
$doc->load("https://retailapi.apparel21.com/RetailAPI/products?countrycode=au");
$xpath = new DOMXpath($doc);
/*foreach ($xpath->query("/Products/Product[Code='00122']") as $node)
{
echo $node->nodeValue;
echo "Hi<br>";
}*/
echo $xpath->query("/Products/Product[Code='00122']")->item(0)->nodeValue;
?>
As you can see that I already used foreach loop & successfully executed the condition but.....the thing is inside it, it prints whole data of that all the nodes of it's parent node.
Confused? :)
Ok no worries, just execute this url: https://retailapi.apparel21.com/RetailAPI/products?countrycode=au; please click on Proceed anyway button then wait for some time.
There are many Product tags...now I want the data of the following nodes :- Id Code Name Description
whose code=00122 that's the first product's data.
I applied foreach then it printed all node's data of that product. I applied simple single statement but then also it printed all node's data :(
And one more thing is can't it be done by simplexml_load_file function?
One more thing :- You can see I am loading url, so the thing is it will read the whole xml first. Can't we query in this itself so that it will only take only related product tags so the loading time can be reduced.
Can anyone please help?