[xsd-users] bug fix in the streaming example

Boris Kolpackov boris at codesynthesis.com
Tue May 4 12:30:31 EDT 2010


Hi Erik,

Erik Sjölund <erik.sjolund at gmail.com> writes:

> There seems to be a problem with name spaces in the streaming example.
> The example program can't handle some valid input files.
>
> [...]
>
> -  <header>
> +  <header xmlns="">

It appears that Xerces-C++ SAX implementation has a bug/deficiency in
that it does not supply the proper namespace for the xmlns attributes
in the form xmlns="..." (i.e., when there is no prefix).


> -    cur_->setAttributeNS (attr.getURI (i),
> -                          attr.getQName (i),
> -                          attr.getValue (i));
> +    if (! XMLString::startsWith(attr.getQName(i), xmlnsStr)) { 
> +      cur_->setAttributeNS (attr.getURI (i),
> +                            attr.getQName (i),
> +                            attr.getValue (i));
> +    }

I instead fixed it like this:

    const XMLCh* qn (attr.getQName (i));
    const XMLCh* ns (attr.getURI (i));

    // When SAX2 reports the xmlns attribute, it does not include
    // the proper attribute namespace. So we have to detect and
    // handle this case.
    //
    if (XMLString::equals (qn, XMLUni::fgXMLNSString))
      ns = XMLUni::fgXMLNSURIName;

    cur_->setAttributeNS (ns, qn, attr.getValue (i));

Thanks for reporting this!

Boris



More information about the xsd-users mailing list