ID:               29243
 Updated by:       [EMAIL PROTECTED]
-Summary:          SimpleXML additions
 Reported By:      jim-bugs dot php dot net at jimdabell dot com
 Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: FreeBSD
 PHP Version:      5.0.0
 New Comment:

rephrased summary


Previous Comments:
------------------------------------------------------------------------

[2004-07-18 17:22:50] [EMAIL PROTECTED]

Ok, it's nodeName or localName then, not ElementTypeName ;)

anyway, at the moment you have to convert a simplexml node to a dom
node if you want to have this info

in your example, this woudl look like the following:
***
$domelement = dom_import_simplexml($element);

return
$domelement->getAttributeNS("http://www.w3.org/XML/1998/namespace","lang";);
***

No idea, if and when your wishes will be implemented...



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

[2004-07-18 15:59:44] jim-bugs dot php dot net at jimdabell dot com

getElementTypeName() would return the name of the element type as a
string.  For instance, "p", "table", "h1", to use examples from XHTML.

I know about the DOM extension, but I would have thought that, at the
very least, getting the element type name and getting standard
attribute values would be both frequently used and simple enough to go
in.  They are the very first pair of problems I ran into when starting
with SimpleXML, so it's hardly an XML expert-only scenario - I'm merely
parsing a simple document, nothing advanced.

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

[2004-07-18 15:49:36] [EMAIL PROTECTED]

What's getElementTypeName() supposed to return? There's no equivalent
in DOM for that... 

If you need more powerful functions/methods/properties, you should
maybe use the DOM Extension (or at least convert the node in question
to a DOMNode, with dom_import_simplexml($node)). The SimpleXML
Extension won't be extended with a lot of new methods/properties,
AFAIK. It's supposed to be simple ;) 

chregu


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

[2004-07-18 12:54:14] jim-bugs dot php dot net at jimdabell dot com

Description:
------------
Right now, I don't think it's possible to retrieve the element type
name of a simplexml_element instance.  A getElementTypeName() method
would be useful.

It would also be useful to have an easier way of retrieving the XML
language information, as described in the XML 1.0 specification.


Reproduce code:
---------------
Right now I am using a helper function like this to get xml:lang
attributes:

function getLanguage($element)
{
        /* Returns the value of any xml:lang attribute when passed an element
or null if there isn't one. */
        $language = null;
        foreach($element->attributes('http://www.w3.org/XML/1998/namespace')
as $attributeName => $attribute) {
                if ($attributeName == 'lang') {
                        $language = (string)$attribute;
                }
        }

        return $language;
}

Obviously, that's a little unwieldy, and since the xml:lang attribute
is defined in the XML 1.0 specification, it would be nice to have
better support for it in PHP.  Right now, as long as they are in the
default namespace, it's much easier to get information about arbitrary,
undefined attributes than it is about XML 1.0 standard attributes!



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


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

Reply via email to