Jump to content

extract the value of a xml field


odigele1

Recommended Posts

Hi! I've a xml file and I want to extract the value of a field.

I know make it if the tags don't have the namespace.

A extract of the file is:

 

Example xml

----------------------------------------------------

<?xml version="1.0"?>

<rdf:RDF

xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"

xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"

xmlns:owl="http://www.w3.org/2002/07/owl#"

>

<owl:Ontology rdf:about=""/>

<owl:Class rdf:ID="Insectivora">

  <rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string"

  >Insectivora</rdfs:comment>

</owl:Class>

</rdf:RDF>

----------------------------------------------------

 

I can select the element rdf:ID, but I cant't show it.

 

Example code:

----------------------------------------------------

$xml = simplexml_load_file('xml_little.owl');

$res2 = $xml->xpath("/rdf:RDF/owl:Class/@rdf:ID");

foreach ($res2 as $key => $value)

{

  echo "<p> -".$key." ".$value."</p>";

}

----------------------------------------------------

The elements number of $res2(array) is ok, but $value don't display anything. 

 

Thanks in advance, Juan

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.