From 297b4bd2c5bd5ed5e62f560a8b60c1d04903455b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 4 May 2010 18:17:27 +0200 Subject: If attribute is xmlns, supply proper namespace to DOM Xerces-C++ SAX does not provide proper namespace for the xmlns attribute as in xmlns="foo" or xmlns="". --- examples/cxx/tree/streaming/parser.cxx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/examples/cxx/tree/streaming/parser.cxx b/examples/cxx/tree/streaming/parser.cxx index b0d9df7..f593a14 100644 --- a/examples/cxx/tree/streaming/parser.cxx +++ b/examples/cxx/tree/streaming/parser.cxx @@ -220,9 +220,17 @@ startElement (const XMLCh* const uri, for (unsigned int i (0), end (attr.getLength()); i < end; ++i) #endif { - cur_->setAttributeNS (attr.getURI (i), - attr.getQName (i), - attr.getValue (i)); + 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)); } depth_++; -- cgit v1.1