588 ContainerNode* node = parentElement->parentNode();
589 if (!is<Element>(node))
590 break;
591 parentElement = downcast<Element>(node);
592 }
593
594 if (elemStack.isEmpty())
595 return;
596
597 // FIXME: Share code with isDefaultNamespace() per http://www.whatwg.org/specs/web-apps/current-work/multipage/the-xhtml-syntax.html#parsing-xhtml-fragments
598 for (; !elemStack.isEmpty(); elemStack.removeLast()) {
599 Element* element = elemStack.last();
600 if (element->hasAttributes()) {
601 for (const Attribute& attribute : element->attributesIterator()) {
602 if (attribute.localName() == xmlnsAtom())
603 m_defaultNamespaceURI = attribute.value();
604 else if (attribute.prefix() == xmlnsAtom())
605 m_prefixToNamespaceMap.set(attribute.localName(), attribute.value());
586 // Don't cross boundaries from HTML to SVG.
587 for (auto* ancestor = parentElement; ancestor && !is<SVGForeignObjectElement>(ancestor); ancestor = ancestor->parentElement()) {
588 defaultNamespaceURI = ancestor->namespaceURI();
589
590 if (!ancestor->hasAttributes())
591 continue;
592
593 for (const Attribute& attribute : ancestor->attributesIterator()) {
594 if (m_defaultNamespaceURI.isNull() && attribute.localName() == xmlnsAtom())
595 m_defaultNamespaceURI = attribute.value();
596 else if (attribute.prefix() == xmlnsAtom()) {
597 m_prefixToNamespaceMap.ensure(xmlnsAtom(), [&] {
598 return attribute.value();
599 });