[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    [Qt-4.2] QDomDocument writes out xmlns:prefix=namespaceuri for every
From:       David Faure <faure () kde ! org>
Date:       2006-11-07 20:49:23
Message-ID: 200611072149.25442.faure () kde ! org
[Download RAW message or body]

Loading an XML document with QDomDocument and namespace processing enabled (*) works,
but saving it back gives a bloated and redundant XML file with \
"xmlns:prefix=namespaceuri" added to each and every element.

<?xml version='1.0' encoding='UTF-8'?>
<office:document-content \
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0">  \
<office:font-face-decls \
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0">  <style:font-face \
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" \
svg:font-family="Bitstream Vera Sans" \
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" \
style:name="Bitstream Vera Sans" \
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" />  <style:font-face \
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" svg:font-family="DejaVu \
Sans" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" \
style:name="DejaVu Sans" \
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" />  \
</office:font-face-decls>  [...]

Redefining xmlns:office in every element other than the toplevel \
office:document-content is unnecessary since the definition in an element is \
applicable to any child element. The initial XML document simply defined all the \
namespaces in the <office:document-content> element.

Even worse, the <style:font-face> elements got xmlns:style defined twice.
Checking the validity of this document with jing and a relaxng schema shows that as \
an error: content.xml:4:234: fatal: Attribute "xmlns:style" was already specified for \
element "style:font-face".

The initial document was
<?xml version="1.0" encoding="UTF-8"?>
<office:document-content \
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" \
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0">  \
<office:font-face-decls>  <style:font-face style:name="Bitstream Vera Sans" \
svg:font-family="Bitstream Vera Sans"/>  <style:font-face style:name="DejaVu Sans" \
svg:font-family="DejaVu Sans"/>  </office:font-face-decls>
  [...]

QDomElementPrivate::save() has a TODO comment about this.
To "only declare namespaces that are not yet declared" should indeed be implemented.


(*)
    QXmlInputSource source( inputDevice );
    QXmlSimpleReader reader;
    reader.setFeature( "http://xml.org/sax/features/namespaces", true )
    reader.setFeature( "http://xml.org/sax/features/namespace-prefixes", false );
    QString errorMsg;
    int errorLine, errorColumn;
    bool ok = doc.setContent( &source, &reader, &errorMsg, &errorLine, &errorColumn \
);

    Then using doc.toByteArray() when saving.

-- 
David Faure, faure@kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).
_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic