#33 DOMBuilder/DOMParser/NamespaceStrategy bug

closed
nobody
None
5
2012-09-14
2006-09-28
No

There is a bug in NamespaceStrategy that results in a
incorrect DOM tree being created if namespaces are used
(both FEATURE_NAMESPACES and FEATURE_NAMESPACE_PREFIXES
are set).
This results in wrong element names - the namespace
prefix is used instead of the qualified name.

Following is the fix for NamespaceStrategy.cpp

void NamespacePrefixesStrategy::startElement(const
XMLChar name, const XMLChar atts, int
specifiedCount, ContentHandler
pContentHandler)
{
poco_assert_dbg (name && atts && pContentHandler);

AttributesImpl attributes;
for (int i = 0; *atts; ++i)
{
    const XMLChar* attrName  = *atts++;
    const XMLChar* attrValue = *atts++;
    XMLString attrURI;
    XMLString attrLocal;
    XMLString attrPrefix;
    splitName(attrName, attrURI, attrLocal, attrPrefix);
    attributes.addAttribute(attrURI, attrLocal,

attrPrefix, CDATA, attrValue, i < specifiedCount);
}
XMLString uri;
XMLString local;
XMLString qname;
splitName(name, uri, local, qname);
qname.append(":");
qname.append(local);
pContentHandler->startElement(uri, local, qname,
attributes);
}

void NamespacePrefixesStrategy::endElement(const
XMLChar name, ContentHandler pContentHandler)
{
poco_assert_dbg (name && pContentHandler);

XMLString uri;
XMLString local;
XMLString qname;
splitName(name, uri, local, qname);
qname.append(":");
qname.append(local);
pContentHandler->endElement(uri, local, qname);

}

Discussion

  • Logged In: YES
    user_id=1148207

    fixed in 1.2.4

     
  • Logged In: YES
    user_id=1148207

    The first fix does not completely solve the bug. Here's
    another patch:

    void NamespacePrefixesStrategy::startElement(const XMLChar
    name, const XMLChar
    atts, int specifiedCount,
    ContentHandler
    pContentHandler)
    {
    poco_assert_dbg (name && atts && pContentHandler);

    AttributesImpl attributes;
    for (int i = 0; *atts; ++i)
    {
        const XMLChar* attrName  = *atts++;
        const XMLChar* attrValue = *atts++;
        XMLString attrURI;
        XMLString attrLocal;
        XMLString attrQName;
        splitName(attrName, attrURI, attrLocal, attrQName);
        if (!attrQName.empty()) attrQName.append(":");
        attrQName.append(attrLocal);
        attributes.addAttribute(attrURI, attrLocal, attrQName,
    

    CDATA, attrValue, i < specifiedCount);
    }
    XMLString uri;
    XMLString local;
    XMLString qname;
    splitName(name, uri, local, qname);
    if (!qname.empty()) qname.append(":");
    qname.append(local);
    pContentHandler->startElement(uri, local, qname, attributes);
    }

    void NamespacePrefixesStrategy::endElement(const XMLChar
    name, ContentHandler
    pContentHandler)
    {
    poco_assert_dbg (name && pContentHandler);

    XMLString uri;
    XMLString local;
    XMLString qname;
    splitName(name, uri, local, qname);
    if (!qname.empty()) qname.append(":");
    qname.append(local);
    pContentHandler->endElement(uri, local, qname);
    

    }