-1

I have the following PHP which works exactly as it should and finds all 'Widgets' in my xml document:

  if($reader->nodeType == XMLREADER::ELEMENT && $reader->localName == 'manufacturer'){
     $reader->read();
       if($reader->value == 'Widget'){
          echo 'congrats you have found the widget';
       }

But when I try the following, I get no results, and I know "blue-widget" to exist several times in the xml document in the manufacturer node:

  if($reader->nodeType == XMLREADER::ELEMENT && $reader->localName == 'manufacturer'){
     $reader->read();
       if($reader->value == 'blue-widget'){
          echo 'congrats you have found the widget';
       }

Does this have something to do with the hyphen in the manufacturer name? I also cannot seem to find the "blue-widget" by any other attribute, yet any other named product I try to extract can be found just find. Its as if XML Reader is not seeing the product nodes that contain "blue-widget".

Here is the XML:

<?xml version="1.0" encoding="utf-8"?>
<catalog>
//I can find this one
<product>
<programname>Example</programname>
<programurl>http://www.example.com</programurl>
<catalogname>Product Catalog</catalogname>
<lastupdated>date</lastupdated>
<name>first widget</name>
<keywords>some stuff</keywords>
<description>Typical description</description>
<sku>20</sku>
<manufacturer>Widget</manufacturer>
<manufacturerid>63</manufacturerid>
<upc>2250</upc>
<currency>USD</currency>
<price>6.79</price>
<buyurl>a url</buyurl>
<impressionurl>another url</impressionurl>
<imageurl>yet another url</imageurl>
<advertisercategory>widgets</advertisercategory>
<format>clean</format>
<instock>yes</instock>
<condition>new</condition>
<standardshippingcost>free</standardshippingcost>
</product>

<product>
//I can't find this one
<programname>Example</programname>
<programurl>http://www.example.com</programurl>
<catalogname>Product Catalog</catalogname>
<lastupdated>date</lastupdated>
<name>first widget</name>
<keywords>some stuff</keywords>
<description>Typical description</description>
<sku>20</sku>
<manufacturer>blue-widget</manufacturer>
<manufacturerid>63</manufacturerid>
<upc>2199</upc>
<currency>USD</currency>
<price>6.79</price>
<buyurl>a url</buyurl>
<impressionurl>another url</impressionurl>
<imageurl>yet another url</imageurl>
<advertisercategory>widgets</advertisercategory>
<format>clean</format>
<instock>yes</instock>
<condition>new</condition>
<standardshippingcost>free</standardshippingcost>
</product>



</catalog>
absentx
  • 1,397
  • 4
  • 17
  • 31

1 Answers1

0

There were parsing errors in my xml script. When I eliminated the errors everything worked fine.

The reason I was not able to find "blue-widget" was because it occured in the XML doc after the errors.

So ultimately the answer to my post is:

Check thoroughly for errors first and isolate them! You might have an encoding issue and reference the following thread for a possible solution:

PHP generated XML shows invalid Char value 27 message

Community
  • 1
  • 1
absentx
  • 1,397
  • 4
  • 17
  • 31