| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2005-10-12 19:58 UTC] stochnagara at hotmail dot com
 Description: ------------ The class SimpleXMLElement is wonderful and provides a great functionality. But I need to extend it and I don't have a way to determine whether a given SimpleXMLElement is an attribute, an element, a CDATA section and so on. So I suggest adding methods getName() and getType(). getName() returns element's name for elements, attribute's name for attributes and so on. getType() returns SimpleXMLElement::ELEMENT and so on. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 03:00:01 2025 UTC | 
Hey There!!! Here is a solution to your issue: To determine whether a given SimpleXMLElement is an attribute, an element, a CDATA section, etc., you can use the following methods: Check if it’s an Attribute: Use the attributes() method to check if the SimpleXMLElement object has any attributes. If the method returns a non-empty result, it’s likely an attribute. PHP $element = new SimpleXMLElement($xmlString); if ($element->attributes()) { // It's an attribute } AI-generated code. Review and use carefully. More info on FAQ. Check for CDATA: When you cast a SimpleXMLElement to a string, it automatically returns the CDATA content. If you need to preserve CDATA when loading the XML, use the LIBXML_NOCDATA option with simplexml_load_string. PHP $xml = simplexml_load_string($xmlString, 'SimpleXMLElement', LIBXML_NOCDATA); $content = (string) $xml; // This will be the CDATA content AI-generated code. Review and use carefully. More info on FAQ. Get Element Name: (https://github.com)(https://www-lhiproviderportal.com) Use the getName() method to get the name of the element. PHP $elementName = $element->getName(); AI-generated code. Review and use carefully. More info on FAQ. Determine Element Type: PHP does not have a built-in method like getType() for SimpleXMLElement. However, you can infer the type based on the context and the methods used. For example, to check if a SimpleXMLElement is a CDATA section, you can compare the string cast of the element with its asXML() output. If they differ, and the asXML() contains <![CDATA[, it’s a CDATA section. Best Regards Rena Carper