simplexml_load_string returning empty structure, no errors. why?

I have a string variable [tt]$xml[/tt] which contains this text:
[php]
<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:dc=“http://purl.org/dc/elements/1.1/
xmlns:foaf=“http://xmlns.com/foaf/0.1/
xmlns:sumo=“http://www.ontologyportal.org/translations/SUMO.owl.txt#
xmlns:dul=“http://www.loa-cnr.it/ontologies/DUL.owl
xmlns:owl=“http://www.w3.org/2002/07/owl
xmlns:top=“http://talkingowlproject.com/schemas/top-level-concepts-10/
xmlns:wps=“http://talkingowlproject.com/schemas/wordnet-parser-schema-10/”>
<rdf:Description rdf:id="#me">
rdfs:labelPigwidgeon</rdfs:label>
<rdf:type rdf:resource=“http://talkingowlproject.com/schemas/top-level-concepts-10/TalkingOwl” />
</rdf:Description>
<rdf:Description rdf:id="#you">
rdfs:labelgreg</rdfs:label>
<rdf:type rdf:resource=“http://talkingowlproject.com/schemas/top-level-concepts-10/User” />
</rdf:Description></rdf:rdf>
[/php]

I have the following code:
[php]$xmlobj = simplexml_load_string($xml);
if ($xmlobj===false) die(‘bad news’);
print_r($xmlobj);
[/php]

The result displayed is (appears to be?) an empty structure:

[php]SimpleXMLElement Object
(
)[/php]

And when I try to iterate over members of the object, it performs no iterations (confirming that the structure is empty).

Is there something wrong with the XML string? Is there a problem because of the namespace declarations or the use of namespaces on every tag? When I remove the namespace declarations in the root tag, I actually get a structure with contents … but then it doesn’t know the namespaces, so it can’t use them when I’m parsing the object. (I need to be able to identify namespaces with nodes.)

Thank you for your help.

–Greg

How did you use to make the xml file into a string?

The $xml string variable actually gets its value by combining text from a database text field with dynamic information from the user session. So it is a dynamically constructed string variable.

Sponsor our Newsletter | Privacy Policy | Terms of Service