Title: AtomParser::start_element
Published: April 25, 2014
Last modified: August 20, 2026

---

# AtomParser::start_element( $parser,  $name,  $attrs )

## In this article

 * [Source](https://developer.wordpress.org/reference/classes/atomparser/start_element/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/atomparser/start_element/?output_format=md#related)

[ Back to top](https://developer.wordpress.org/reference/classes/atomparser/start_element/?output_format=md#wp--skip-link--target)

## 󠀁[Source](https://developer.wordpress.org/reference/classes/atomparser/start_element/?output_format=md#source)󠁿

    ```php
    function start_element($parser, $name, $attrs) {

        $name_parts = explode(":", $name);
        $tag        = array_pop($name_parts);

        switch($name) {
            case $this->NS . ':feed':
                $this->current = $this->feed;
                break;
            case $this->NS . ':entry':
                $this->current = new AtomEntry();
                break;
        };

        $this->_p("start_element('$name')");
        #$this->_p(print_r($this->ns_contexts,true));
        #$this->_p('current(' . $this->current . ')');

        array_unshift($this->ns_contexts, $this->ns_decls);

        $this->depth++;

        if(!empty($this->in_content)) {

            $this->content_ns_decls = array();

            if($this->is_html || $this->is_text)
                trigger_error("Invalid content in element found. Content must not be of type text or html if it contains markup.");

            $attrs_prefix = array();

            // resolve prefixes for attributes
            foreach($attrs as $key => $value) {
                $with_prefix = $this->ns_to_prefix($key, true);
                $attrs_prefix[$with_prefix[1]] = $this->xml_escape($value);
            }

            $attrs_str = join(' ', array_map($this->map_attrs_func, array_keys($attrs_prefix), array_values($attrs_prefix)));
            if(strlen($attrs_str) > 0) {
                $attrs_str = " " . $attrs_str;
            }

            $with_prefix = $this->ns_to_prefix($name);

            if(!$this->is_declared_content_ns($with_prefix[0])) {
                array_push($this->content_ns_decls, $with_prefix[0]);
            }

            $xmlns_str = '';
            if(count($this->content_ns_decls) > 0) {
                array_unshift($this->content_ns_contexts, $this->content_ns_decls);
                $xmlns_str .= join(' ', array_map($this->map_xmlns_func, array_keys($this->content_ns_contexts[0]), array_values($this->content_ns_contexts[0])));
                if(strlen($xmlns_str) > 0) {
                    $xmlns_str = " " . $xmlns_str;
                }
            }

            array_push($this->in_content, array($tag, $this->depth, "<". $with_prefix[1] ."{$xmlns_str}{$attrs_str}" . ">"));

        } else if(in_array($tag, $this->ATOM_CONTENT_ELEMENTS) || in_array($tag, $this->ATOM_SIMPLE_ELEMENTS)) {
            $this->in_content = array();
            $this->is_xhtml = $attrs['type'] == 'xhtml';
            $this->is_html = $attrs['type'] == 'html' || $attrs['type'] == 'text/html';
            $this->is_text = !in_array('type',array_keys($attrs)) || $attrs['type'] == 'text';
            $type = $this->is_xhtml ? 'XHTML' : ($this->is_html ? 'HTML' : ($this->is_text ? 'TEXT' : $attrs['type']));

            if(in_array('src',array_keys($attrs))) {
                $this->current->$tag = $attrs;
            } else {
                array_push($this->in_content, array($tag,$this->depth, $type));
            }
        } else if($tag == 'link') {
            array_push($this->current->links, $attrs);
        } else if($tag == 'category') {
            array_push($this->current->categories, $attrs);
        }

        $this->ns_decls = array();
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/atomlib.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/atomlib.php#L198)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/atomlib.php#L198-L276)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/atomparser/start_element/?output_format=md#related)󠁿

| Uses | Description | 
| [AtomParser::ns_to_prefix()](https://developer.wordpress.org/reference/classes/atomparser/ns_to_prefix/)`wp-includes/atomlib.php` |  | 
| [AtomParser::xml_escape()](https://developer.wordpress.org/reference/classes/atomparser/xml_escape/)`wp-includes/atomlib.php` |  | 
| [AtomParser::is_declared_content_ns()](https://developer.wordpress.org/reference/classes/atomparser/is_declared_content_ns/)`wp-includes/atomlib.php` |  | 
| [AtomParser::_p()](https://developer.wordpress.org/reference/classes/atomparser/_p/)`wp-includes/atomlib.php` |  |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fatomparser%2Fstart_element%2F)
before being able to contribute a note or feedback.