I have the following XML-structure in my XML file (it's not the whole XML-file, only a part of it):
<?xml version="1.0" encoding="utf-8"?>
<extensions>
<extension extensionkey="fp_product_features">
<downloadcounter>355</downloadcounter>
<version version="0.1.0">
<title>Product features</title>
<description/>
<downloadcounter>24</downloadcounter>
<state>beta</state>
<reviewstate>0</reviewstate>
<category>plugin</category>
<lastuploaddate>1142878270</lastuploaddate>
<uploadcomment> added related features</uploadcomment>
</version>
</extension>
</extensions>
The file is too big for SimpleXML, so I'm using XMLReader. I have a switch that checks for the XML-tags and their content:
while ($xmlReader->read()) {
if ($xmlReader->nodeType == XMLReader::ELEMENT) {
switch ($xmlReader->name) {
case "title" :
$xmlReader->read();
$foo = $xmlReader->value;
//Do stuff with the value
break;
case "description":
$xmlReader->read();
$bar = $xmlReader->value;
//Do stuff with the value
break;
case "downloadcounter" :
$xmlReader->read();
$foobar = $xmlReader->value;
//Do stuff with the value
break;
case "state" :
$xmlReader->read();
$barfoo = $xmlReader->value;
//Do stuff with the value
break;
//Repeat for other tags
}
}
}
The problem here is that there are two <downloadcounter>
tags. The one beneath <extension>
and the one beneath <version>
. I need the one beneath <version>
, but the code in my switch is giving me the one beneath <extension>
. All the other cases are giving me the right information.
I have thought about some solutions. Maybe there is a way where I can specify that XMLReader only reads the tag after <description>
? I've been using the $xmlReader->read()
function multiple times in one case, but that didn't help.
I'm very new to this, so maybe it is not the right the way to do it, but if anyone can point me in the right direction, it would be much appreciated.
Thanks in advance!