void XMLTreeBuilder::processStartTag(const AtomicXMLToken& token) { exitText(); bool isFirstElement = !m_sawFirstElement; m_sawFirstElement = true; NodeStackItem top = m_currentNodeStack.last(); processNamespaces(token, top); QualifiedName qName(token.prefix(), token.name(), top.namespaceForPrefix(token.prefix(), top.namespaceURI())); RefPtr<Element> newElement = m_document->createElement(qName, true); processAttributes(token, top, newElement); newElement->beginParsingChildren(); m_currentNodeStack.last().node()->parserAddChild(newElement.get()); top.setNode(newElement); pushCurrentNode(top); if (!newElement->attached()) newElement->attach(); if (isFirstElement && m_document->frame()) m_document->frame()->loader()->dispatchDocumentElementAvailable(); if (token.selfClosing()) closeElement(newElement); }
void XMLTreeBuilder::processNamespaces(const AtomicXMLToken& token, NodeStackItem& stackItem) { for (unsigned i = 0; i < token.attributes().size(); ++i) { const Attribute& tokenAttribute = token.attributes().at(i); if (tokenAttribute.name().prefix() == xmlnsAtom) stackItem.setNamespaceURI(tokenAttribute.name().localName(), tokenAttribute.value()); else if (tokenAttribute.name() == xmlnsAtom) stackItem.setNamespaceURI(tokenAttribute.value()); } }
void XMLTreeBuilder::processNamespaces(const AtomicXMLToken& token, NodeStackItem& stackItem) { if (!token.attributes()) return; for (size_t i = 0; i < token.attributes()->size(); ++i) { Attribute* attribute = token.attributes()->attributeItem(i); if (attribute->name().prefix() == xmlnsAtom) stackItem.setNamespaceURI(attribute->name().localName(), attribute->value()); else if (attribute->name() == xmlnsAtom) stackItem.setNamespaceURI(attribute->value()); } }
void XMLTreeBuilder::processAttributes(const AtomicXMLToken& token, NodeStackItem& stackItem, PassRefPtr<Element> newElement) { for (unsigned i = 0; i < token.attributes().size(); ++i) { const Attribute& tokenAttribute = token.attributes().at(i); ExceptionCode ec = 0; if (tokenAttribute.name().prefix() == xmlnsAtom) newElement->setAttributeNS(XMLNSNames::xmlnsNamespaceURI, "xmlns:" + tokenAttribute.name().localName(), tokenAttribute.value(), ec); else if (tokenAttribute.name() == xmlnsAtom) newElement->setAttributeNS(XMLNSNames::xmlnsNamespaceURI, xmlnsAtom, tokenAttribute.value(), ec); else { QualifiedName qName(tokenAttribute.prefix(), tokenAttribute.localName(), stackItem.namespaceForPrefix(tokenAttribute.prefix(), nullAtom)); newElement->setAttribute(qName, tokenAttribute.value()); } if (ec) { m_parser->stopParsing(); return; } } }
void XMLTreeBuilder::processAttributes(const AtomicXMLToken& token, NodeStackItem& stackItem, PassRefPtr<Element> newElement) { if (!token.attributes()) return; for (size_t i = 0; i < token.attributes()->size(); ++i) { Attribute* attribute = token.attributes()->attributeItem(i); ExceptionCode ec = 0; if (attribute->name().prefix() == xmlnsAtom) newElement->setAttributeNS(XMLNSNames::xmlnsNamespaceURI, "xmlns:" + attribute->name().localName(), attribute->value(), ec); else if (attribute->name() == xmlnsAtom) newElement->setAttributeNS(XMLNSNames::xmlnsNamespaceURI, xmlnsAtom, attribute->value(), ec); else { QualifiedName qName(attribute->prefix(), attribute->localName(), stackItem.namespaceForPrefix(attribute->prefix(), nullAtom)); newElement->setAttribute(qName, attribute->value()); } if (ec) { m_parser->stopParsing(); return; } } }
void XMLTreeBuilder::pushCurrentNode(const NodeStackItem& stackItem) { ASSERT(stackItem.node()); m_currentNodeStack.append(stackItem); // FIXME: is there a maximum DOM depth? }