Process the start tag.

@todo - XMLNS namespace handling (we need to parse, even if it's not valid)
- XLink, MathML and SVG namespace handling
- Omission rules: 8.1.2.4 Optional tags
493852
public function startTag($name, $attributes = array(), $selfClosing = false) {
        // fprintf(STDOUT, $name);
        $lname = $this->normalizeTagName($name);

        // Make sure we have an html element.
        if (!$this->doc->documentElement && $name !== 'html' && !$this->frag) {
            $this->startTag('html');
        }

        // Set quirks mode if we're at IM_INITIAL with no doctype.
        if ($this->insertMode == static::IM_INITIAL) {
            $this->quirks = true;
            $this->parseError("No DOCTYPE specified.");
        }

        // SPECIAL TAG HANDLING:
        // Spec says do this, and "don't ask."
        if ($name == 'image') {
            $name = 'img';
        }

        // Autoclose p tags where appropriate.
        if ($this->insertMode >= static::IM_IN_BODY && HTML5_Elements::isA($name, HTML5_Elements::AUTOCLOSE_P)) {
            $this->autoclose('p');
        }

        // Set insert mode:
        switch ($name) {
            case 'html':
                $this->insertMode = static::IM_BEFORE_HEAD;
                break;
            case 'head':
                if ($this->insertMode > static::IM_BEFORE_HEAD) {
                    $this->parseError("Unexpected head tag outside of head context.");
                } else {
                    $this->insertMode = static::IM_IN_HEAD;
                }
                break;
            case 'body':
                $this->insertMode = static::IM_IN_BODY;
                break;
            case 'svg':
                $this->insertMode = static::IM_IN_SVG;
                break;
            case 'math':
                $this->insertMode = static::IM_IN_MATHML;
                break;
            case 'noscript':
                if ($this->insertMode == static::IM_IN_HEAD) {
                    $this->insertMode = static::IM_IN_HEAD_NOSCRIPT;
                }
                break;
        }

        // Special case handling for SVG.
        if ($this->insertMode == static::IM_IN_SVG) {
            $lname = HTML5_Elements::normalizeSvgElement($lname);
        }

        $pushes = 0;
        // when we found a tag thats appears inside $nsRoots, we have to switch the defalut namespace
        if (isset($this->nsRoots[$lname]) && $this->nsStack[0][''] !== $this->nsRoots[$lname]) {
            array_unshift($this->nsStack, array(
                '' => $this->nsRoots[$lname]
                    ) + $this->nsStack[0]);
            $pushes ++;
        }
        $needsWorkaround = false;
        if (isset($this->options["xmlNamespaces"]) && $this->options["xmlNamespaces"]) {
            // when xmlNamespaces is true a and we found a 'xmlns' or 'xmlns:*' attribute, we should add a new item to the $nsStack
            foreach ($attributes as $aName => $aVal) {
                if ($aName === 'xmlns') {
                    $needsWorkaround = $aVal;
                    array_unshift($this->nsStack, array(
                        '' => $aVal
                            ) + $this->nsStack[0]);
                    $pushes ++;
                } elseif ((($pos = strpos($aName, ':')) ? substr($aName, 0, $pos) : '') === 'xmlns') {
                    array_unshift($this->nsStack, array(
                        substr($aName, $pos + 1) => $aVal
                            ) + $this->nsStack[0]);
                    $pushes ++;
                }
            }
        }

        try {
            $prefix = ($pos = strpos($lname, ':')) ? substr($lname, 0, $pos) : '';


            if ($needsWorkaround !== false) {

                $xml = "<$lname xmlns=\"$needsWorkaround\" " . (strlen($prefix) && isset($this->nsStack[0][$prefix]) ? ("xmlns:$prefix=\"" . $this->nsStack[0][$prefix] . "\"") : "") . "/>";

                $frag = new \DOMDocument('1.0', 'UTF-8');
                $frag->loadXML($xml);

                $ele = $this->doc->importNode($frag->documentElement, true);
            } else {
                if (!isset($this->nsStack[0][$prefix]) || ($prefix === "" && isset($this->options['disableHtmlNsInDom']) && $this->options['disableHtmlNsInDom'])) {
                    $ele = $this->doc->createElement($lname);
                } else {
                    $ele = $this->doc->createElementNS($this->nsStack[0][$prefix], $lname);
                }
            }
        } catch (\DOMException $e) {
            $this->parseError("Illegal tag name: <$lname>. Replaced with <invalid>.");
            $ele = $this->doc->createElement('invalid');
        }

        // When we add some namespacess, we have to track them. Later, when "endElement" is invoked, we have to remove them.
        // When we are on a void tag, we do not need to care about namesapce nesting.
        if ($pushes > 0 && !HTML5_Elements::isA($name, HTML5_Elements::VOID_TAG)) {
            // PHP tends to free the memory used by DOM,
            // to avoid spl_object_hash collisions whe have to avoid garbage collection of $ele storing it into $pushes
            // see https://bugs.php.net/bug.php?id=67459
            $this->pushes[spl_object_hash($ele)] = array($pushes, $ele);

            // SEE https://github.com/facebook/hhvm/issues/2962
            if (defined('HHVM_VERSION')) {
                $ele->setAttribute('html5-php-fake-id-attribute', spl_object_hash($ele));
            }
        }

        foreach ($attributes as $aName => $aVal) {
            // xmlns attributes can't be set
            if ($aName === 'xmlns') {
                continue;
            }

            if ($this->insertMode == static::IM_IN_SVG) {
                $aName = HTML5_Elements::normalizeSvgAttribute($aName);
            } elseif ($this->insertMode == static::IM_IN_MATHML) {
                $aName = HTML5_Elements::normalizeMathMlAttribute($aName);
            }

            try {
                $prefix = ($pos = strpos($aName, ':')) ? substr($aName, 0, $pos) : false;

                if ($prefix === 'xmlns') {
                    $ele->setAttributeNs(self::NAMESPACE_XMLNS, $aName, $aVal);
                } elseif ($prefix !== false && isset($this->nsStack[0][$prefix])) {
                    $ele->setAttributeNs($this->nsStack[0][$prefix], $aName, $aVal);
                } else {
                    $ele->setAttribute($aName, $aVal);
                }
            } catch (\DOMException $e) {
                $this->parseError("Illegal attribute name for tag $name. Ignoring: $aName");
                continue;
            }

            // This is necessary on a non-DTD schema, like HTML5.
            if ($aName == 'id') {
                $ele->setIdAttribute('id', true);
            }
        }

        // Some elements have special processing rules. Handle those separately.
        if ($this->rules->hasRules($name) && $this->frag !== $this->current) {
            $this->current = $this->rules->evaluate($ele, $this->current);
        }         // Otherwise, it's a standard element.
        else {
            $this->current->appendChild($ele);

            // XXX: Need to handle self-closing tags and unary tags.
            if (!HTML5_Elements::isA($name, HTML5_Elements::VOID_TAG)) {
                $this->current = $ele;
            }
        }

        // This is sort of a last-ditch attempt to correct for cases where no head/body
        // elements are provided.
        if ($this->insertMode <= static::IM_BEFORE_HEAD && $name != 'head' && $name != 'html') {
            $this->insertMode = static::IM_IN_BODY;
        }

        // When we are on a void tag, we do not need to care about namesapce nesting,
        // but we have to remove the namespaces pushed to $nsStack.
        if ($pushes > 0 && HTML5_Elements::isA($name, HTML5_Elements::VOID_TAG)) {
            // remove the namespaced definded by current node
            for ($i = 0; $i < $pushes; $i ++) {
                array_shift($this->nsStack);
            }
        }
        // Return the element mask, which the tokenizer can then use to set
        // various processing rules.
        return HTML5_Elements::element($name);
    }
730821
public function parseOutsideTag() : void
    {
        if (!count($this->stream->getTokens())) {
            return;
        }

        if ($this->accept(Token::T_TEXT)) {
            $this->insert(new TextNode($this->getCurrentToken()->getValue()));
            $this->advance();
        }

        if ($this->skip(Token::T_OPENING_TAG)) {
            $this->parseStatement();
        }
    }
393804
def handle_starttag(self, tag, attrs):
        
        self.log.debug( u'Encountered a start tag: {0} {1}'.format(tag, attrs) )
        if tag in self.sanitizelist:
            self.level += 1
            return
        if self.isNotPurify or tag in self.whitelist_keys:
            attrs = self.__attrs_str(tag, attrs)
            attrs = ' ' + attrs if attrs else ''
            tmpl = u'<%s%s />' if tag in self.unclosedTags and self.isStrictHtml else u'<%s%s>'
            self.data.append( tmpl % (tag, attrs,) )
1183431
def handle_startendtag(self, tag, attrs):
        """"""
        if tag.lower() in self.allowed_tag_whitelist:
            self.result += '<' + tag
            for (attr, value) in attrs:
                if attr.lower() in self.allowed_attribute_whitelist:
                    self.result += ' %s="%s"' % \
                        (attr, self.handle_attribute_value(value))
            self.result += ' />'
        else:
            if self.render_unallowed_tags:
                self.result += '&lt;' + cgi.escape(tag)
                for (attr, value) in attrs:
                    self.result += ' %s="%s"' % \
                        (attr, cgi.escape(value, True))
                self.result += ' /&gt;'
125509
public boolean nextStartElement() throws XMLException, IOException {
		try {
			do {
				next();
			} while (!Type.START_ELEMENT.equals(event.type));
			return true;
		} catch (EOFException e) {
			return false;
		}
	}
146873
private function initDOMXPath()
    {
        $this->xpath = new DOMXPath($this);

        $simpleXML = new \SimpleXMLElement($this->saveXML());
        $namespaces = $simpleXML->getNamespaces(true);

        foreach ($namespaces as $name => $uri) {
            $name = $name ?: self::ROOT_NAMESPACE_NAME;
            $this->namespaces[$name] = $uri;
            $this->xpath->registerNamespace($name, $uri);
        }

        return $this;
    }
194611
protected void processObjectTag(ObjectTag tag) {

        CmsRelationType type = CmsRelationType.valueOf(tag.getTagName());
        for (int i = 0; i < OBJECT_TAG_LINKED_ATTRIBS.length; i++) {
            String attr = OBJECT_TAG_LINKED_ATTRIBS[i];
            processLink(tag, attr, type);
            if ((i == 0) && (tag.getAttribute(attr) != null)) {
                // if code base is available, the other attributes are relative to it, so do not process them
                break;
            }
        }
        SimpleNodeIterator itChildren = tag.children();
        while (itChildren.hasMoreNodes()) {
            Node node = itChildren.nextNode();
            if (node instanceof Tag) {
                Tag childTag = (Tag)node;
                if (TAG_PARAM.equals(childTag.getTagName())) {
                    processLink(childTag, ATTRIBUTE_VALUE, type);
                }
            }
        }
    }
940800
function schemaStartElement($parser, $name, $attrs)
    {

        // position in the total number of elements, starting from 0
        $pos   = $this->position++;
        $depth = $this->depth++;
        // set self as current value for this depth
        $this->depth_array[$depth] = $pos;
        $this->message[$pos]       = ['cdata' => ''];
        if ($depth > 0) {
            $this->defaultNamespace[$pos] = $this->defaultNamespace[$this->depth_array[$depth - 1]];
        } else {
            $this->defaultNamespace[$pos] = FALSE;
        }

        // get element prefix
        if ($prefix = $this->getPrefix($name)) {
            // get unqualified name
            $name = $this->getLocalPart($name);
        } else {
            $prefix = '';
        }

        // loop thru attributes, expanding, and registering namespace declarations
        if (count($attrs) > 0) {
            foreach ($attrs as $k => $v) {
                // if ns declarations, add to class level array of valid namespaces
                if (preg_match('/^xmlns/', $k)) {
                    //$this->xdebug("$k: $v");
                    //$this->xdebug('ns_prefix: '.$this->getPrefix($k));
                    if ($ns_prefix = substr(strrchr($k, ':'), 1)) {
                        //$this->xdebug("Add namespace[$ns_prefix] = $v");
                        $this->namespaces[$ns_prefix] = $v;
                    } else {
                        $this->defaultNamespace[$pos] = $v;
                        if (!$this->getPrefixFromNamespace($v)) {
                            $this->namespaces['ns' . (count($this->namespaces) + 1)] = $v;
                        }
                    }
                    if ($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema') {
                        $this->XMLSchemaVersion  = $v;
                        $this->namespaces['xsi'] = $v . '-instance';
                    }
                }
            }
            foreach ($attrs as $k => $v) {
                // expand each attribute
                $k          = strpos($k, ':') ? $this->expandQname($k) : $k;
                $v          = strpos($v, ':') ? $this->expandQname($v) : $v;
                $eAttrs[$k] = $v;
            }
            $attrs = $eAttrs;
        } else {
            $attrs = [];
        }
        // find status, register data
        switch ($name) {
            case 'all':            // (optional) compositor content for a complexType
            case 'choice':
            case 'group':
            case 'sequence':
                //$this->xdebug("compositor $name for currentComplexType: $this->currentComplexType and currentElement: $this->currentElement");
                $this->complexTypes[$this->currentComplexType]['compositor'] = $name;
                //if($name == 'all' || $name == 'sequence'){
                //	$this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
                //}
                break;
            case 'attribute':    // complexType attribute
                //$this->xdebug("parsing attribute $attrs[name] $attrs[ref] of value: ".$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']);
                $this->xdebug("parsing attribute:");
                $this->appendDebug($this->varDump($attrs));
                if (!isset($attrs['form'])) {
                    // TODO: handle globals
                    $attrs['form'] = $this->schemaInfo['attributeFormDefault'];
                }
                if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
                    $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
                    if (!strpos($v, ':')) {
                        // no namespace in arrayType attribute value...
                        if ($this->defaultNamespace[$pos]) {
                            // ...so use the default
                            $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] = $this->defaultNamespace[$pos] . ':' . $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
                        }
                    }
                }
                if (isset($attrs['name'])) {
                    $this->attributes[$attrs['name']] = $attrs;
                    $aname                            = $attrs['name'];
                } elseif (isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType') {
                    if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
                        $aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
                    } else {
                        $aname = '';
                    }
                } elseif (isset($attrs['ref'])) {
                    $aname                           = $attrs['ref'];
                    $this->attributes[$attrs['ref']] = $attrs;
                }

                if ($this->currentComplexType) {    // This should *always* be
                    $this->complexTypes[$this->currentComplexType]['attrs'][$aname] = $attrs;
                }
                // arrayType attribute
                if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || $this->getLocalPart($aname) == 'arrayType') {
                    $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
                    $prefix                                                   = $this->getPrefix($aname);
                    if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) {
                        $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'];
                    } else {
                        $v = '';
                    }
                    if (strpos($v, '[,]')) {
                        $this->complexTypes[$this->currentComplexType]['multidimensional'] = TRUE;
                    }
                    $v = substr($v, 0, strpos($v, '[')); // clip the []
                    if (!strpos($v, ':') && isset($this->typemap[$this->XMLSchemaVersion][$v])) {
                        $v = $this->XMLSchemaVersion . ':' . $v;
                    }
                    $this->complexTypes[$this->currentComplexType]['arrayType'] = $v;
                }
                break;
            case 'complexContent':    // (optional) content for a complexType
                $this->xdebug("do nothing for element $name");
                break;
            case 'complexType':
                array_push($this->complexTypeStack, $this->currentComplexType);
                if (isset($attrs['name'])) {
                    // TODO: what is the scope of named complexTypes that appear
                    //       nested within other c complexTypes?
                    $this->xdebug('processing named complexType ' . $attrs['name']);
                    //$this->currentElement = false;
                    $this->currentComplexType                                   = $attrs['name'];
                    $this->complexTypes[$this->currentComplexType]              = $attrs;
                    $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType';
                    // This is for constructs like
                    //           <complexType name="ListOfString" base="soap:Array">
                    //                <sequence>
                    //                    <element name="string" type="xsd:string"
                    //                        minOccurs="0" maxOccurs="unbounded" />
                    //                </sequence>
                    //            </complexType>
                    if (isset($attrs['base']) && preg_match('/:Array$/', $attrs['base'])) {
                        $this->xdebug('complexType is unusual array');
                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
                    } else {
                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
                    }
                } else {
                    $name = $this->CreateTypeName($this->currentElement);
                    $this->xdebug('processing unnamed complexType for element ' . $this->currentElement . ' named ' . $name);
                    $this->currentComplexType = $name;
                    //$this->currentElement = false;
                    $this->complexTypes[$this->currentComplexType]              = $attrs;
                    $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType';
                    // This is for constructs like
                    //           <complexType name="ListOfString" base="soap:Array">
                    //                <sequence>
                    //                    <element name="string" type="xsd:string"
                    //                        minOccurs="0" maxOccurs="unbounded" />
                    //                </sequence>
                    //            </complexType>
                    if (isset($attrs['base']) && preg_match('/:Array$/', $attrs['base'])) {
                        $this->xdebug('complexType is unusual array');
                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
                    } else {
                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct';
                    }
                }
                $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'false';
                break;
            case 'element':
                array_push($this->elementStack, $this->currentElement);
                if (!isset($attrs['form'])) {
                    if ($this->currentComplexType) {
                        $attrs['form'] = $this->schemaInfo['elementFormDefault'];
                    } else {
                        // global
                        $attrs['form'] = 'qualified';
                    }
                }
                if (isset($attrs['type'])) {
                    $this->xdebug("processing typed element " . $attrs['name'] . " of type " . $attrs['type']);
                    if (!$this->getPrefix($attrs['type'])) {
                        if ($this->defaultNamespace[$pos]) {
                            $attrs['type'] = $this->defaultNamespace[$pos] . ':' . $attrs['type'];
                            $this->xdebug('used default namespace to make type ' . $attrs['type']);
                        }
                    }
                    // This is for constructs like
                    //           <complexType name="ListOfString" base="soap:Array">
                    //                <sequence>
                    //                    <element name="string" type="xsd:string"
                    //                        minOccurs="0" maxOccurs="unbounded" />
                    //                </sequence>
                    //            </complexType>
                    if ($this->currentComplexType && $this->complexTypes[$this->currentComplexType]['phpType'] == 'array') {
                        $this->xdebug('arrayType for unusual array is ' . $attrs['type']);
                        $this->complexTypes[$this->currentComplexType]['arrayType'] = $attrs['type'];
                    }
                    $this->currentElement = $attrs['name'];
                    $ename                = $attrs['name'];
                } elseif (isset($attrs['ref'])) {
                    $this->xdebug("processing element as ref to " . $attrs['ref']);
                    $this->currentElement = "ref to " . $attrs['ref'];
                    $ename                = $this->getLocalPart($attrs['ref']);
                } else {
                    $type = $this->CreateTypeName($this->currentComplexType . '_' . $attrs['name']);
                    $this->xdebug("processing untyped element " . $attrs['name'] . ' type ' . $type);
                    $this->currentElement = $attrs['name'];
                    $attrs['type']        = $this->schemaTargetNamespace . ':' . $type;
                    $ename                = $attrs['name'];
                }
                if (isset($ename) && $this->currentComplexType) {
                    $this->xdebug("add element $ename to complexType $this->currentComplexType");
                    $this->complexTypes[$this->currentComplexType]['elements'][$ename] = $attrs;
                } elseif (!isset($attrs['ref'])) {
                    $this->xdebug("add element $ename to elements array");
                    $this->elements[$attrs['name']]              = $attrs;
                    $this->elements[$attrs['name']]['typeClass'] = 'element';
                }
                break;
            case 'enumeration':    //	restriction value list member
                $this->xdebug('enumeration ' . $attrs['value']);
                if ($this->currentSimpleType) {
                    $this->simpleTypes[$this->currentSimpleType]['enumeration'][] = $attrs['value'];
                } elseif ($this->currentComplexType) {
                    $this->complexTypes[$this->currentComplexType]['enumeration'][] = $attrs['value'];
                }
                break;
            case 'extension':    // simpleContent or complexContent type extension
                $this->xdebug('extension ' . $attrs['base']);
                if ($this->currentComplexType) {
                    $ns = $this->getPrefix($attrs['base']);
                    if ($ns == '') {
                        $this->complexTypes[$this->currentComplexType]['extensionBase'] = $this->schemaTargetNamespace . ':' . $attrs['base'];
                    } else {
                        $this->complexTypes[$this->currentComplexType]['extensionBase'] = $attrs['base'];
                    }
                } else {
                    $this->xdebug('no current complexType to set extensionBase');
                }
                break;
            case 'import':
                if (isset($attrs['schemaLocation'])) {
                    $this->xdebug('import namespace ' . $attrs['namespace'] . ' from ' . $attrs['schemaLocation']);
                    $this->imports[$attrs['namespace']][] = ['location' => $attrs['schemaLocation'], 'loaded' => FALSE];
                } else {
                    $this->xdebug('import namespace ' . $attrs['namespace']);
                    $this->imports[$attrs['namespace']][] = ['location' => '', 'loaded' => TRUE];
                    if (!$this->getPrefixFromNamespace($attrs['namespace'])) {
                        $this->namespaces['ns' . (count($this->namespaces) + 1)] = $attrs['namespace'];
                    }
                }
                break;
            case 'include':
                if (isset($attrs['schemaLocation'])) {
                    $this->xdebug('include into namespace ' . $this->schemaTargetNamespace . ' from ' . $attrs['schemaLocation']);
                    $this->imports[$this->schemaTargetNamespace][] = ['location' => $attrs['schemaLocation'], 'loaded' => FALSE];
                } else {
                    $this->xdebug('ignoring invalid XML Schema construct: include without schemaLocation attribute');
                }
                break;
            case 'list':    // simpleType value list
                $this->xdebug("do nothing for element $name");
                break;
            case 'restriction':    // simpleType, simpleContent or complexContent value restriction
                $this->xdebug('restriction ' . $attrs['base']);
                if ($this->currentSimpleType) {
                    $this->simpleTypes[$this->currentSimpleType]['type'] = $attrs['base'];
                } elseif ($this->currentComplexType) {
                    $this->complexTypes[$this->currentComplexType]['restrictionBase'] = $attrs['base'];
                    if (strstr($attrs['base'], ':') == ':Array') {
                        $this->complexTypes[$this->currentComplexType]['phpType'] = 'array';
                    }
                }
                break;
            case 'schema':
                $this->schemaInfo                  = $attrs;
                $this->schemaInfo['schemaVersion'] = $this->getNamespaceFromPrefix($prefix);
                if (isset($attrs['targetNamespace'])) {
                    $this->schemaTargetNamespace = $attrs['targetNamespace'];
                }
                if (!isset($attrs['elementFormDefault'])) {
                    $this->schemaInfo['elementFormDefault'] = 'unqualified';
                }
                if (!isset($attrs['attributeFormDefault'])) {
                    $this->schemaInfo['attributeFormDefault'] = 'unqualified';
                }
                break;
            case 'simpleContent':    // (optional) content for a complexType
                if ($this->currentComplexType) {    // This should *always* be
                    $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'true';
                } else {
                    $this->xdebug("do nothing for element $name because there is no current complexType");
                }
                break;
            case 'simpleType':
                array_push($this->simpleTypeStack, $this->currentSimpleType);
                if (isset($attrs['name'])) {
                    $this->xdebug("processing simpleType for name " . $attrs['name']);
                    $this->currentSimpleType                        = $attrs['name'];
                    $this->simpleTypes[$attrs['name']]              = $attrs;
                    $this->simpleTypes[$attrs['name']]['typeClass'] = 'simpleType';
                    $this->simpleTypes[$attrs['name']]['phpType']   = 'scalar';
                } else {
                    $name = $this->CreateTypeName($this->currentComplexType . '_' . $this->currentElement);
                    $this->xdebug('processing unnamed simpleType for element ' . $this->currentElement . ' named ' . $name);
                    $this->currentSimpleType = $name;
                    //$this->currentElement = false;
                    $this->simpleTypes[$this->currentSimpleType]            = $attrs;
                    $this->simpleTypes[$this->currentSimpleType]['phpType'] = 'scalar';
                }
                break;
            case 'union':    // simpleType type list
                $this->xdebug("do nothing for element $name");
                break;
            default:
                $this->xdebug("do not have any logic to process element $name");
        }
    }
717246
@Override
    public void startOfProcess() {
        String previousBaseIndent = baseIndent.substring(INDENT_LENGTH);
        builder.append(previousBaseIndent).append("HierarchyWrapper{\n");
        processFirstOtherContent = true;
    }
20762
public void readWriteUpToStartElement(String startTag) throws XMLStreamException {
        boolean startTagIsNext = false;
        while (xmlEventReader.hasNext() && !startTagIsNext) {
            XMLEvent peekedEvent = xmlEventReader.peek();
            switch (peekedEvent.getEventType()) {
                case XMLStreamConstants.START_ELEMENT:
                    String elementName = peekedEvent.asStartElement().getName().getLocalPart();
                    if (elementName.equals(startTag)) {
                        startTagIsNext = true;
                    } else {
                        XMLEvent readEvent = xmlEventReader.nextEvent();
                        add(readEvent);
                    }
                    break;
                default:
                    XMLEvent readEvent = xmlEventReader.nextEvent();
                    add(readEvent);
                    break;
            }
        }
    }
1341245
function startTagToTokens(startTag) {
            const tokens = [startTag.tagOpen]

            for (const attr of startTag.attributes) {
                tokens.push(attr)
            }

            tokens.push(startTag.tagClose)

            return tokens
                .filter(t => Boolean(t))
                .sort((a, b) => a.range[0] - b.range[0])
        }
143214
def handle_starttag(self, tag, attrs):
        
        # Parse the tag attributes
        attrs_dict = dict(t for t in attrs)

        # If the tag is a predefined parent element
        if tag in PARENT_ELEMENTS:
            # If parser is parsing another parent element
            if self.current_parent_element['tag'] != '':
                # close the parent element
                self.cleaned_html += '</{}>'.format(self.current_parent_element['tag'])

            self.current_parent_element['tag'] = tag
            self.current_parent_element['attrs'] = {}

            self.cleaned_html += '<{}>'.format(tag)

        # If the tag is a list item
        elif tag == 'li':
            self.parsing_li = True

            # Parse the class name & subsequent type
            class_name = attrs_dict['class']
            list_type = class_name[10:]

            # Check if parsing a list
            if self.current_parent_element['tag'] == 'ul' or self.current_parent_element['tag'] == 'ol':
                cur_list_type = self.current_parent_element['attrs']['class']
                # Parsing a different list
                if cur_list_type != list_type:
                    # Close that list
                    self._close_list()

                    # Open new list
                    self._open_list(list_type)
            # Not parsing a list
            else:
                # if parsing some other parent
                if self.current_parent_element['tag'] != '':
                    self.cleaned_html += '</{}>'.format(self.current_parent_element['tag'])
                # Open new list
                self._open_list(list_type)

            self.cleaned_html += '<{}>'.format(tag)

        # If the tag is a line break
        elif tag == 'br':
            # If parsing a paragraph, close it
            if self.current_parent_element['tag'] == 'p':
                self.cleaned_html += '</p>'
                self.current_parent_element['tag'] = ''
                self.current_parent_element['attrs'] = {}
            # If parsing a list, close it
            elif self.current_parent_element['tag'] == 'ul' or self.current_parent_element['tag'] == 'ol':
                self._close_list()
            # If parsing any other parent element, keep it
            elif self.current_parent_element['tag'] in PARENT_ELEMENTS:
                self.cleaned_html += '<br />'
            # If not in any parent element, create an empty paragraph
            else:
                self.cleaned_html += '<p></p>'

        # If the tag is something else, like a <b> or <i> tag
        else:
            # If not parsing any parent element
            if self.current_parent_element['tag'] == '':
                self.cleaned_html += '<p>'
                self.current_parent_element['tag'] = 'p'
            self.cleaned_html += '<{}'.format(tag)

            for attr in sorted(attrs_dict.keys()):
                self.cleaned_html += ' {k}="{v}"'.format(
                    k=attr,
                    v=attrs_dict[attr]
                )

            self.cleaned_html += '>'
1285277
protected void startNode(Node node) throws org.xml.sax.SAXException
  {

//   TODO: <REVIEW>
//    A Serializer implements ContentHandler, but not NodeConsumer
//    so drop this reference to NodeConsumer which would otherwise
//    pull in all sorts of things
//    if (m_contentHandler instanceof NodeConsumer)
//    {
//      ((NodeConsumer) m_contentHandler).setOriginatingNode(node);
//    }
//    TODO: </REVIEW>
                
                if (node instanceof Locator)
                {
                        Locator loc = (Locator)node;
                        m_locator.setColumnNumber(loc.getColumnNumber());
                        m_locator.setLineNumber(loc.getLineNumber());
                        m_locator.setPublicId(loc.getPublicId());
                        m_locator.setSystemId(loc.getSystemId());
                }
                else
                {
                        m_locator.setColumnNumber(0);
      m_locator.setLineNumber(0);
                }

    switch (node.getNodeType())
    {
    case Node.COMMENT_NODE :
    {
      String data = ((Comment) node).getData();

      if (m_contentHandler instanceof LexicalHandler)
      {
        LexicalHandler lh = ((LexicalHandler) this.m_contentHandler);

        lh.comment(data.toCharArray(), 0, data.length());
      }
    }
    break;
    case Node.DOCUMENT_FRAGMENT_NODE :

      // ??;
      break;
    case Node.DOCUMENT_NODE :
    
      break;
    case Node.ELEMENT_NODE :
      Element elem_node = (Element) node;
      {
          // Make sure the namespace node
          // for the element itself is declared
          // to the ContentHandler
          String uri = elem_node.getNamespaceURI();
          if (uri != null) {
              String prefix = elem_node.getPrefix();
              if (prefix==null)
                prefix="";
              this.m_contentHandler.startPrefixMapping(prefix,uri);              
          }
      }
      NamedNodeMap atts = elem_node.getAttributes();
      int nAttrs = atts.getLength();
      // System.out.println("TreeWalker#startNode: "+node.getNodeName());

      
      // Make sure the namespace node of
      // each attribute is declared to the ContentHandler
      for (int i = 0; i < nAttrs; i++)
      {
        final Node attr = atts.item(i);
        final String attrName = attr.getNodeName();
        final int colon = attrName.indexOf(':');
        final String prefix;

        // System.out.println("TreeWalker#startNode: attr["+i+"] = "+attrName+", "+attr.getNodeValue());
        if (attrName.equals("xmlns") || attrName.startsWith("xmlns:"))
        {
          // Use "" instead of null, as Xerces likes "" for the 
          // name of the default namespace.  Fix attributed 
          // to "Steven Murray" <smurray@ebt.com>.
          if (colon < 0)
            prefix = "";
          else
            prefix = attrName.substring(colon + 1);

          this.m_contentHandler.startPrefixMapping(prefix,
                                                   attr.getNodeValue());
        }
        else if (colon > 0) {
            prefix = attrName.substring(0,colon);
            String uri = attr.getNamespaceURI();
            if (uri != null)
                this.m_contentHandler.startPrefixMapping(prefix,uri);
        }        
      }

      String ns = m_dh.getNamespaceOfNode(node);
      if(null == ns)
        ns = "";
      this.m_contentHandler.startElement(ns,
                                         m_dh.getLocalNameOfNode(node),
                                         node.getNodeName(),
                                         new AttList(atts, m_dh));
      break;
    case Node.PROCESSING_INSTRUCTION_NODE :
    {
      ProcessingInstruction pi = (ProcessingInstruction) node;
      String name = pi.getNodeName();

      // String data = pi.getData();
      if (name.equals("xslt-next-is-raw"))
      {
        nextIsRaw = true;
      }
      else
      {
        this.m_contentHandler.processingInstruction(pi.getNodeName(),
                                                    pi.getData());
      }
    }
    break;
    case Node.CDATA_SECTION_NODE :
    {
      boolean isLexH = (m_contentHandler instanceof LexicalHandler);
      LexicalHandler lh = isLexH
                          ? ((LexicalHandler) this.m_contentHandler) : null;

      if (isLexH)
      {
        lh.startCDATA();
      }
      
      dispatachChars(node);

      {
        if (isLexH)
        {
          lh.endCDATA();
        }
      }
    }
    break;
    case Node.TEXT_NODE :
    {
      //String data = ((Text) node).getData();

      if (nextIsRaw)
      {
        nextIsRaw = false;

        m_contentHandler.processingInstruction(javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, "");
        dispatachChars(node);
        m_contentHandler.processingInstruction(javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, "");
      }
      else
      {
        dispatachChars(node);
      }
    }
    break;
    case Node.ENTITY_REFERENCE_NODE :
    {
      EntityReference eref = (EntityReference) node;

      if (m_contentHandler instanceof LexicalHandler)
      {
        ((LexicalHandler) this.m_contentHandler).startEntity(
          eref.getNodeName());
      }
      else
      {

        // warning("Can not output entity to a pure SAX ContentHandler");
      }
    }
    break;
    default :
    }
  }
460762
public function onDocumentStart()
    {
        $this->documentElement = new PHPTAL_Dom_Element('documentElement', 'http://xml.zope.org/namespaces/tal', array(), $this->getXmlnsState());
        $this->documentElement->setSource($this->file, $this->line);
        $this->_current = $this->documentElement;
    }
823272
function Tag(page, startPosition, endPosition, attributes) {
        var self = this;
        self.childNodes = [];
        self.firstChild = null;
        self.lastChild = null;
        self.attributes = attributes || [];
        self.nodeType = 1;
        if (typeof page === 'string') {
            createTag.apply(null, [self].concat(util.makeArray(arguments)));
        } else {
            Tag.superclass.constructor.apply(self, arguments);
            attributes = self.attributes;    // first attribute is actually nodeName
            // first attribute is actually nodeName
            if (attributes[0]) {
                self.nodeName = attributes[0].name.toLowerCase();    // end tag (</div>) is a tag too in lexer , but not exist in parsed dom tree
                // end tag (</div>) is a tag too in lexer , but not exist in parsed dom tree
                self.tagName = self.nodeName.replace(/\//, '');
                self._updateSelfClosed();
                attributes.splice(0, 1);
            }
            var lastAttr = attributes[attributes.length - 1], lastSlash = !!(lastAttr && /\/$/.test(lastAttr.name));
            if (lastSlash) {
                attributes.length = attributes.length - 1;
            }    // self-closing flag
            // self-closing flag
            self.isSelfClosed = self.isSelfClosed || lastSlash;    // whether has been closed by its end tag
                                                                   // !TODO how to set closed position correctly
            // whether has been closed by its end tag
            // !TODO how to set closed position correctly
            self.closed = self.isSelfClosed;
        }
        self.closedStartPosition = -1;
        self.closedEndPosition = -1;
    }
113748
protected function processTags()
	{
		if (empty($this->tagStack))
		{
			return;
		}

		// Initialize the count tables
		foreach (array_keys($this->tagsConfig) as $tagName)
		{
			$this->cntOpen[$tagName]  = 0;
			$this->cntTotal[$tagName] = 0;
		}

		// Process the tag stack, close tags that were left open and repeat until done
		do
		{
			while (!empty($this->tagStack))
			{
				if (!$this->tagStackIsSorted)
				{
					$this->sortTags();
				}

				$this->currentTag = array_pop($this->tagStack);
				$this->processCurrentTag();
			}

			// Close tags that were left open
			foreach ($this->openTags as $startTag)
			{
				// NOTE: we add tags in hierarchical order (ancestors to descendants) but since
				//       the stack is processed in LIFO order, it means that tags get closed in
				//       the correct order, from descendants to ancestors
				$this->addMagicEndTag($startTag, $this->textLen);
			}
		}
		while (!empty($this->tagStack));
	}
429263
protected function xml_start(){
		$attributes = "";
		foreach($this->attributes as $k=>$v)
			$attributes .= " ".$k."='".$v."'";

		if ($this->dload){
			if ($pos=$this->request->get_start())
				return "<rows pos='".$pos."'".$attributes.">";
			else
				return "<rows total_count='".$this->sql->get_size($this->request)."'".$attributes.">";
		}
		else
			return "<rows".$attributes.">";
	}