XMLReader and attributes
Posted: Sat Aug 08, 2009 10:55 am
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...
i have so far been using XMLreader and code like this for example:
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...
...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
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...
Code: Select all
<descriptions>
<extra_description lang="es"><![CDATA[lots of spanish text]]></extra_description>
<long_description lang="es"><![CDATA[more spanish text and things]]></long_description>
<extra_description lang="en"><![CDATA[English text and extra info]]></extra_description>
<long_description lang="en"><![CDATA[Lots more english text and writing]]></long_description>
</descriptions>
</property>
Code: Select all
if($reader->nodeType == 1) // XMLReader::ELEMENT
{
$name = $reader->name;
}
if($reader->nodeType == 4) // XMLReader::CDATA
{
$value = $reader->value;
}
if($name == 'extra_description') { $extra = $value; }
if($name == 'long_description') { $description = $value; }
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...
Code: Select all
$reader->getAttribute("url");
Many Thanks
Rutt