Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QXmlStreamWriter ignores default namespace for attributes?

QXmlStreamWriter ignores default namespace for attributes?

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 101 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    David Lichti
    wrote on last edited by
    #1

    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 for attribute1, which has the same namespace. Instead, the writer declares a new namespace prefix. In contrast, for attribute2, the writer remembers that its namespace was declared earlier and uses the specified prefix nsb.

    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?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved