Hey SPF Developers -
We’re migrating from SimpleXML to the SAX parser to handle larger files but running into issues properly retrieving attributes from nested elements within our xml feed.
I’m able to access attributes using the code below, but rather than trying to get it from the specific tag, my script seems to try on every tag. As such warnings are thrown and if the attribute name exists in multiple tags, it’s duplicated in our array.
Can anyone suggest a better way to get an element like Product->merchantListing->in_stock->type ?
function startElement($parser, $tag, $attributes) {
switch($tag) {
case 'product':
$this->product=array('id'=>$attributes['id'], manufacturerName'=>'','merchantProduct'=>'','price'=>'');
break;
case 'manufacturerName';
case 'merchantProduct':
if(isset($attributes['mid'])){ echo $attributes['mid']; }
case 'price':
if ($this->product) { $this->product_elem = $tag; }
break;
}
}
XML Sample:
<product category_id="5" id="123455">
<name>Some Amazing Product</name>
<manufacturerPartNumber>ABCD</manufacturerPartNumber>
<manufacturerName>Guys Who Make Stuff</manufacturerName>
<merchantListing included="1">
<merchantProduct mid="555555">
<in_stock type="stock-1"></in_stock>
<condition type="cond-0"></condition>
<price>19.89</price>
</merchantProduct>
</merchantListing>
</product>
Thanks