I saw lots of tutorials here in overflow, but I could not understand what I am missing.. So I need some help..
I have an XML which it is online and I am trying to parse it like this:
<products>
<product>
<id>13389</id>
<name><![CDATA[ product name ]]></name>
<category id="14"><![CDATA[ Shoes > test1 ]]></category>
<price>41.30</price>
</products>
As far, I am reading the XML and parsing it like this:
$reader = new XMLReader();
$reader->open($product_xml_link);
while($reader->read()) {
if($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'product' ) {
$product = new SimpleXMLElement($reader->readOuterXml());
$pid = $product->id;
$name = $product->name;
$name = strtolower($name);
$link = $product->link;
$price = $product->Price;
...
...
}
} //end while loop
As you can see, there is an id in category tag.. This is the one I would like to grab and procceed to my code..
I did something like this:
echo "prodcut= " . (string)$product->category->getAttribute('id');
The error I am getting is: Call to undefined method SimpleXMLElement::getAttribute()
I need this id in order to test it before insert it in DB.. So,
if($id = 600) {
//insert DB
}