RDF parsing with php ( simplexml ? )
am 15.10.2007 10:23:14 von mattelau
Hi all,
Here is an XML file I'd like to parse with php.
It's a mozilla install.rdf file.
xmlns:NC="http://home.netscape.com/NC-rdf#"
xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
em:id="id1"
em:name="name1"
em:version="v1"
em:creator="creator1"
em:description="desc1"
em:homepageURL="home1"
em:updateURL="update1"
em:iconURL="icon1">
em:id="id2"
em:minVersion="2.0"
em:maxVersion="2.0.0.*" />
How would you do that ?
( I'd like for example, to get the version associated with id1 )
Thanks in advance !
Re: RDF parsing with php ( simplexml ? )
am 15.10.2007 19:50:17 von nc
On Oct 15, 1:23 am, matte...@mattelau.net wrote:
>
> Here is an XML file I'd like to parse with php.
> It's a mozilla install.rdf file.
>
>
>
> xmlns:NC="http://home.netscape.com/NC-rdf#"
> xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
>
> em:id="id1"
> em:name="name1"
> em:version="v1"
> em:creator="creator1"
> em:description="desc1"
> em:homepageURL="home1"
> em:updateURL="update1"
> em:iconURL="icon1">
>
>
>
> em:id="id2"
> em:minVersion="2.0"
> em:maxVersion="2.0.0.*" />
>
>
> How would you do that ?
> ( I'd like for example, to get the version associated with id1 )
You wouldn't. Not with SimpleXML anyway. SimpleXML takes an XML file
or string and converts it into an object. In RDF, however, XML
entities' names contain colons, which are illegal in PHP variable
names. You could try and replace colons with underscores, so you
would get something like this:
$RDF = file_get_contents('install.rdf');
$RDF = str_replace('RDF:', 'RDF_', $RDF);
$RDF = str_replace('em:', 'em_', $RDF);
$XML = simplexml_load_string($RDF);
foreach ($XML->RDF_Description as $num => $description) {
$attributes = $description->attributes();
if (isset($attributes['em_id'])) {
echo "ID = {$attributes['em_id']}; version =
{$attributes['em_version']}";
}
}
Best regards,
NC