QXmlStreamWriter ignores default namespace for attributes?
Unsolved
General and Desktop
-
Consider the following code:
const QString nsA( "namespaceA" ); const QString nsB( "namespaceB" ); QString out; QXmlStreamWriter writer( &out ); writer.setAutoFormatting( true ); writer.writeDefaultNamespace( nsA ); writer.writeNamespace( nsB, "nsb" ); writer.writeStartDocument(); writer.writeStartElement( nsA, "root" ); writer.writeEmptyElement( nsA, "element" ); writer.writeAttribute( nsA, "attribute", "value" ); writer.writeAttribute( nsB, "attribute", "value" ); writer.writeEndElement(); writer.writeEndDocument();
producing the following XML:
<?xml version="1.0"?> <root xmlns="namespaceA" xmlns:nsb="namespaceB"> <element xmlns:n1="namespaceA" n1:attribute="value" nsb:attribute="value"/> </root>
Obviously, the writer recognizes the namespace of
<element>
to be the previously declared default namespace. But this fails forattribute1
, which has the same namespace. Instead, the writer declares a new namespace prefix. In contrast, forattribute2
, the writer remembers that its namespace was declared earlier and uses the specified prefixnsb
.It seems that
QXmlStreamWriter::writeAttribute
is only considering prefixed namespaces, but not the default namespace. Is this a bug in Qt (5.15), or am I doing it wrong?