summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-21 17:10:20 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-21 17:10:20 (GMT)
commitd0fdeeed970c8a60d3f07a7ac2f605e186b671ff (patch)
tree88945ac9d283974ac09969be711b848bcd8aa96a /Swiften/Parser
parent741ee27a2b851d76b33f0ee5accd51ff973aa955 (diff)
downloadswift-d0fdeeed970c8a60d3f07a7ac2f605e186b671ff.zip
swift-d0fdeeed970c8a60d3f07a7ac2f605e186b671ff.tar.bz2
Add namespace support to LibXML parser.
Diffstat (limited to 'Swiften/Parser')
-rw-r--r--Swiften/Parser/LibXMLParser.cpp20
-rw-r--r--Swiften/Parser/LibXMLParser.h5
2 files changed, 9 insertions, 16 deletions
diff --git a/Swiften/Parser/LibXMLParser.cpp b/Swiften/Parser/LibXMLParser.cpp
index 8f14f21..91ff72b 100644
--- a/Swiften/Parser/LibXMLParser.cpp
+++ b/Swiften/Parser/LibXMLParser.cpp
@@ -9,20 +9,16 @@
namespace Swift {
-static void handleStartElement(void *client, const xmlChar* name, const xmlChar** attributes) {
+static void handleStartElement(void *client, const xmlChar* name, const xmlChar*, const xmlChar* xmlns, int, const xmlChar**, int nbAttributes, int, const xmlChar ** attributes) {
AttributeMap attributeValues;
- const xmlChar** currentAttribute = attributes;
- if (currentAttribute) {
- while (*currentAttribute) {
- attributeValues[String(reinterpret_cast<const char*>(*currentAttribute))] = String(reinterpret_cast<const char*>(*(currentAttribute+1)));
- currentAttribute += 2;
- }
+ for (int i = 0; i < nbAttributes*5; i += 5) {
+ attributeValues[String(reinterpret_cast<const char*>(attributes[i]))] = String(reinterpret_cast<const char*>(attributes[i+3]), attributes[i+4]-attributes[i+3]);
}
- static_cast<XMLParserClient*>(client)->handleStartElement(reinterpret_cast<const char*>(name), attributeValues);
+ static_cast<XMLParserClient*>(client)->handleStartElement(reinterpret_cast<const char*>(name), (xmlns ? reinterpret_cast<const char*>(xmlns) : String()), attributeValues);
}
-static void handleEndElement(void *client, const xmlChar* name) {
- static_cast<XMLParserClient*>(client)->handleEndElement(reinterpret_cast<const char*>(name));
+static void handleEndElement(void *client, const xmlChar* name, const xmlChar*, const xmlChar* xmlns) {
+ static_cast<XMLParserClient*>(client)->handleEndElement(reinterpret_cast<const char*>(name), (xmlns ? reinterpret_cast<const char*>(xmlns) : String()));
}
static void handleCharacterData(void* client, const xmlChar* data, int len) {
@@ -40,8 +36,8 @@ static void handleWarning(void*, const char*, ... ) {
LibXMLParser::LibXMLParser(XMLParserClient* client) : XMLParser(client) {
memset(&handler_, 0, sizeof(handler_) );
handler_.initialized = XML_SAX2_MAGIC;
- handler_.startElement = &handleStartElement;
- handler_.endElement = &handleEndElement;
+ handler_.startElementNs = &handleStartElement;
+ handler_.endElementNs = &handleEndElement;
handler_.characters = &handleCharacterData;
handler_.warning = &handleWarning;
handler_.error = &handleError;
diff --git a/Swiften/Parser/LibXMLParser.h b/Swiften/Parser/LibXMLParser.h
index f8faef6..58a65f1 100644
--- a/Swiften/Parser/LibXMLParser.h
+++ b/Swiften/Parser/LibXMLParser.h
@@ -1,5 +1,4 @@
-#ifndef SWIFTEN_LibXMLParser_H
-#define SWIFTEN_LibXMLParser_H
+#pragma once
#include <libxml/parser.h>
#include <boost/noncopyable.hpp>
@@ -19,5 +18,3 @@ namespace Swift {
xmlParserCtxtPtr context_;
};
}
-
-#endif