Summary: | Complex XML file is flagged as not wellformed | ||
---|---|---|---|
Product: | [Applications] konqueror | Reporter: | Frans Englich <frans.englich> |
Component: | khtml xml | Assignee: | Konqueror Developers <konq-bugs> |
Status: | RESOLVED FIXED | ||
Severity: | normal | ||
Priority: | NOR | ||
Version: | unspecified | ||
Target Milestone: | --- | ||
Platform: | Compiled Sources | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Attachments: | XML file flagged as not well-formed while it is |
Description
Frans Englich
2005-04-19 21:53:07 UTC
Created attachment 10710 [details]
XML file flagged as not well-formed while it is
It doesn't like the sodipodi:version before the xmlns declaration. SVN commit 587710 by orlovich: Workaround a bug in QXML where it doesn't properly resolve namespace of attrs preceeding the xmlns declaration. Makes photos on new.photos.yahoo.com show up (though page is still very buggy) and fixes #104236 BUG:104236 M +33 -2 xml_tokenizer.cpp M +8 -0 xml_tokenizer.h --- branches/KDE/3.5/kdelibs/khtml/xml/xml_tokenizer.cpp #587709:587710 @@ -135,7 +135,35 @@ return true; } +bool XMLHandler::startPrefixMapping(const QString& prefix, const QString& uri) +{ + namespaceInfo[prefix].push(uri); + return true; +} +bool XMLHandler::endPrefixMapping(const QString& prefix) +{ + QValueStack<QString>& stack = namespaceInfo[prefix]; + stack.pop(); + if (stack.isEmpty()) + namespaceInfo.remove(prefix); + return true; +} + +void XMLHandler::fixUpNSURI(QString& uri, const QString& qname) +{ + /* QXml does not resolve the namespaces of attributes in the same + tag that preceed the xmlns declaration. This fixes up that case */ + if (uri.isEmpty() && qname.find(':') != -1) { + QXmlNamespaceSupport ns; + QString localName, prefix; + ns.splitName(qname, prefix, localName); + if (namespaceInfo.contains(prefix)) { + uri = namespaceInfo[prefix].top(); + } + } +} + bool XMLHandler::startElement( const QString& namespaceURI, const QString& /*localName*/, const QString& qName, const QXmlAttributes& atts ) { @@ -154,8 +182,11 @@ int i; for (i = 0; i < atts.length(); i++) { int exceptioncode = 0; - DOMString uri(atts.uri(i)); - DOMString qn(atts.qName(i)); + QString uriString = atts.uri(i); + QString qnString = atts.qName(i); + fixUpNSURI(uriString, qnString); + DOMString uri(uriString); + DOMString qn(qnString); DOMString val(atts.value(i)); newElement->setAttributeNS(uri, qn, val, exceptioncode); if (exceptioncode) // exception setting attributes --- branches/KDE/3.5/kdelibs/khtml/xml/xml_tokenizer.h #587709:587710 @@ -26,6 +26,7 @@ #include <qxml.h> #include <qptrlist.h> #include <qptrstack.h> +#include <qvaluestack.h> #include <qobject.h> #include "misc/loader_client.h" #include "misc/stringit.h" @@ -65,6 +66,13 @@ bool characters(const QString& ch); bool comment(const QString & ch); bool processingInstruction(const QString &target, const QString &data); + + // namespace handling, to workaround problem in QXML where some attributes + // do not get the namespace resolved properly + bool startPrefixMapping(const QString& prefix, const QString& uri); + bool endPrefixMapping(const QString& prefix); + void fixUpNSURI(QString& uri, const QString& qname); + QMap<QString, QValueStack<QString> > namespaceInfo; // from QXmlDeclHandler |