extract the value of a xml field

Discussion in 'PHP' started by odigele1, Nov 28, 2007.

  1. #1
    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:eek:wl="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
     
    odigele1, Nov 28, 2007 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    Never used simplexml_load_file before, nor do I know the code of it.

    Peace,
     
    Barti1987, Nov 28, 2007 IP
  3. Big 'G'

    Big 'G' Member

    Messages:
    89
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    48
    #3
    try
    echo  htmlentities( (string) $value);
    PHP:
    or using the full object path
    htmlentities( (string) $res2->$key->$value);
    PHP:
    hope that what ur looking for
     
    Big 'G', Nov 28, 2007 IP