Jump to content

XMLReader and attributes


ruttegar

Recommended Posts

Hey.

 

I have 6mb XML file to sort through, assign variables to certain data and insert into MySQL db. all the information is going in great apart from the following...

 

 

  1. 

  2. <descriptions>

  3.    <extra_description lang="es"><![CDATA[lots of spanish text]]></extra_description>

  4.    <long_description lang="es"><![CDATA[more spanish text and things]]></long_description>

  5. 

  6.    <extra_description lang="en"><![CDATA[English text and extra info]]></extra_description>

  7.    <long_description lang="en"><![CDATA[Lots more english text and writing]]></long_description>

  8.   

  9. </descriptions>

  10. </property>

  11. 

 

 

 

i have so far been using XMLreader and code like this for example:

 

 

  1. 

  2. if($reader->nodeType == 1) // XMLReader::ELEMENT

  3.    {

  4.        $name = $reader->name;

  5.    }

  6. if($reader->nodeType ==  4) // XMLReader::CDATA

  7.    {

  8.        $value = $reader->value;

  9.    }

  10. if($name == 'extra_description')    {  $extra = $value;    }

  11. if($name == 'long_description')    {  $description = $value;  }

  12. 

 

 

 

unfortunately there are two identical tags for the extra_description and only the "lang" attribute to differentiate them.

 

so my Q is...how do i isolate a tag by its name AND one of its attributes???? i only want the english.

 

in another part of the script i have used...

 

  1. 

  2. $reader->getAttribute("url");

  3. 

 

...to retrieve an attribute value but havent been able to figure out a way to make the same method work for this.

 

Many Thanks

 

Rutt

Link to comment
https://forums.phpfreaks.com/topic/169598-xmlreader-and-attributes/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.