Edit report at http://bugs.php.net/bug.php?id=31846&edit=1

 ID:                 31846
 Comment by:         james at populiweb dot com
 Reported by:        andrew at shh dot fi
 Summary:            simplexml_load_string doesn't get root node
 Status:             Bogus
 Type:               Bug
 Package:            SimpleXML related
 Operating System:   win32
 PHP Version:        5.0.3
 Block user comment: N

 New Comment:

just in case it helps anyone, getting the name of the root node is
possible:



$xml = simplexml_load_string($xml_str);

$xml->getName();


Previous Comments:
------------------------------------------------------------------------
[2005-02-07 21:18:11] a...@php.net

No. SimpleXML is not about being able to do 100% of XML. It's about
doing 80% of XML with 20% of the effort.



Do this instead:



$rootTag = dom_import_simplexml($simple)->tagName;

------------------------------------------------------------------------
[2005-02-07 19:58:00] andrew at shh dot fi

Will simpleXML ever be changed to include root nodes?

------------------------------------------------------------------------
[2005-02-07 19:56:30] andrew at shh dot fi

So, using simpleXML, one can never know the root tag. Should we guess?
The idea of an XML parser is to return ALL the nodes and not some of
them. Take docbook - you have different root nodes depending on whether
its simple or full. My point is, if you are having an xml parser, then
it needs to read all nodes top-bottom, otherwise there is no point using
it - and as you say correctly - might as well use DOM.

------------------------------------------------------------------------
[2005-02-07 16:37:04] chr...@php.net

This is correct. print_r shows you the children nodes of the choosen
node. in your code, $simple *is* the root node. I don't see anything
wrong. There's no such thing as SimpleXMLDocument Object in SimpleXML.



And yes, there is no way of getting the name of the root tag. Use DOM if
you need that.



------------------------------------------------------------------------
[2005-02-04 16:28:06] andrew at shh dot fi

Description:
------------
$xml = simplexml_load_string($xml_str) returns all tags correctly except
the root node.



There appears to be NO WAY to get the the name of the root tag





Reproduce code:
---------------
$xml = '<?xml version="1.0"
encoding="ISO-8859-1"?><article><title>Hello</title></article>';



$simple = simplexml_load_string($xml);



print_r($simple);

Expected result:
----------------
The object should include the root tag, except it starts from child of
the root



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



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=31846&edit=1

Reply via email to