andyfarang Posted May 24, 2016 Share Posted May 24, 2016 I couldn't find any example at google. Let's say, that I have some generic XML file, feed of products from eshop. And I want to get value of <price> of product, which has <product_id> equal to 9631. How do I get it's price? Quote Link to comment https://forums.phpfreaks.com/topic/301243-how-to-search-xml-and-get-specific-value/ Share on other sites More sharing options...
PravinS Posted May 24, 2016 Share Posted May 24, 2016 Try using SimpleXMLElement::xpath http://php.net/manual/en/simplexmlelement.xpath.php Quote Link to comment https://forums.phpfreaks.com/topic/301243-how-to-search-xml-and-get-specific-value/#findComment-1533184 Share on other sites More sharing options...
requinix Posted May 24, 2016 Share Posted May 24, 2016 You can also do plain -> and loops on SimpleXMLElement objects. Exactly what you do depends on the structure of the XML. Quote Link to comment https://forums.phpfreaks.com/topic/301243-how-to-search-xml-and-get-specific-value/#findComment-1533185 Share on other sites More sharing options...
andyfarang Posted May 24, 2016 Author Share Posted May 24, 2016 (edited) <SHOP> <SHOPITEM> <PRODUCT></PRODUCT> <PRODUCT_SKU></PRODUCT_SKU> <CATEGORYTEXT></CATEGORYTEXT> <CATEGORIES> <CATEGORY</CATEGORY> <CATEGORY></CATEGORY> </CATEGORIES> <URL></URL> <IN_STOCK></IN_STOCK> <IMGURL></IMGURL> <IMGURL_FULL></IMGURL_FULL> <PRICE_VAT></PRICE_VAT> </SHOPITEM> <PRODUCT_SKU> is ID of product and I want to get <PRICE_VAT>. XML has about 1000 products, I have to get price of about 200 products (and then save it to MySQL - which I know how to do, but I don't know how to get a price of product by ID) Edited May 24, 2016 by andyfarang Quote Link to comment https://forums.phpfreaks.com/topic/301243-how-to-search-xml-and-get-specific-value/#findComment-1533186 Share on other sites More sharing options...
requinix Posted May 24, 2016 Share Posted May 24, 2016 That's only partial so "/???/SHOP/SHOPITEM/PRICE_VAT" $???->SHOPITEM->PRICE_VAT Quote Link to comment https://forums.phpfreaks.com/topic/301243-how-to-search-xml-and-get-specific-value/#findComment-1533189 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.