RDF parsing with php ( simplexml ? )

This is a discussion on RDF parsing with php ( simplexml ? ) within the PHP Language forums, part of the PHP Programming Forums category; Hi all, Here is an XML file I'd like to parse with php. It's a mozilla install.rdf ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-15-2007
mattelau@mattelau.net
 
Posts: n/a
Default RDF parsing with php ( simplexml ? )

Hi all,

Here is an XML file I'd like to parse with php.
It's a mozilla install.rdf file.

<?xml version="1.0"?>
<RDF:RDF xmlns:em="http://www.mozilla.org/2004/em-rdf#"
xmlns:NC="http://home.netscape.com/NC-rdf#"
xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<RDF:Description RDF:about="urn:mozilla:install-manifest"
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:targetApplication RDF:resource="rdf:#$b0tbb"/>
</RDF:Description>
<RDF:Description RDF:about="rdf:#$b0tbb"
em:id="id2"
em:minVersion="2.0"
em:maxVersion="2.0.0.*" />
</RDF:RDF>


How would you do that ?
( I'd like for example, to get the version associated with id1 )

Thanks in advance !

Reply With Quote
  #2 (permalink)  
Old 10-15-2007
NC
 
Posts: n/a
Default Re: RDF parsing with php ( simplexml ? )

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.
>
> <?xml version="1.0"?>
> <RDF:RDF xmlns:em="http://www.mozilla.org/2004/em-rdf#"
> xmlns:NC="http://home.netscape.com/NC-rdf#"
> xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
> <RDF:Description RDF:about="urn:mozilla:install-manifest"
> 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:targetApplication RDF:resource="rdf:#$b0tbb"/>
> </RDF:Description>
> <RDF:Description RDF:about="rdf:#$b0tbb"
> em:id="id2"
> em:minVersion="2.0"
> em:maxVersion="2.0.0.*" />
> </RDF:RDF>
>
> 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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:02 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0