30 #include "XMLHelpers.h"
38 string XMLUtil::xmlCharToString(
const xmlChar* theCharsOrNull)
40 const char* asChars =
reinterpret_cast<const char*
>(theCharsOrNull);
41 return ((asChars) ? (string(asChars)) : (
string(
"")));
44 void XMLUtil::xmlCharToString(
string& stringToFill,
const xmlChar* pChars)
46 stringToFill = xmlCharToString(pChars);
51 string XMLUtil::xmlCharToStringFromIterators(
const xmlChar* startIter,
const xmlChar* endIter)
54 if (!startIter || !endIter || (startIter > endIter)) {
59 return string(
reinterpret_cast<const char*
>(startIter),
reinterpret_cast<const char*
>(endIter));
63 XMLAttribute::XMLAttribute(
const string& localNameA,
const string& valueA,
const string& prefixA,
const string& nsURIA) :
64 localname(localNameA), prefix(prefixA), nsURI(nsURIA), value(valueA)
71 XMLAttribute::XMLAttribute(
const xmlChar** chunkOfFivePointers)
73 fromSAX2NamespaceAttributes(chunkOfFivePointers);
77 localname(proto.localname), prefix(proto.prefix), nsURI(proto.nsURI), value(proto.value)
82 XMLAttribute::operator=(
const XMLAttribute& rhs)
87 localname = rhs.localname;
96 const xmlChar* xmlLocalName = (*chunkOfFivePointers++);
97 const xmlChar* xmlPrefix = (*chunkOfFivePointers++);
98 const xmlChar* xmlURI = (*chunkOfFivePointers++);
99 const xmlChar* xmlValueStart = (*chunkOfFivePointers++);
101 const xmlChar* xmlValueEnd = (*chunkOfFivePointers++);
104 localname = XMLUtil::xmlCharToString(xmlLocalName);
105 prefix = XMLUtil::xmlCharToString(xmlPrefix);
106 nsURI = XMLUtil::xmlCharToString(xmlURI);
107 value = XMLUtil::xmlCharToStringFromIterators(xmlValueStart, xmlValueEnd);
122 return getQName() +
"=\"" + value +
"\"";
128 if (prefix.empty()) {
132 return prefix +
":" + localname;
137 XMLAttributeMap::XMLAttributeMap() :
142 XMLAttributeMap::~XMLAttributeMap()
146 XMLAttributeMap::const_iterator XMLAttributeMap::begin()
const
148 return _attributes.begin();
151 XMLAttributeMap::const_iterator XMLAttributeMap::end()
const
153 return _attributes.end();
156 bool XMLAttributeMap::empty()
const
158 return _attributes.empty();
169 XMLAttributeMap::iterator foundIt = findByQName(attribute.
getQName());
171 if (foundIt != _attributes.end()) {
177 _attributes.push_back(attribute);
197 for (XMLAttributeMap::const_iterator it = begin(); it != end(); ++it) {
199 if (rAttr.localname == localname) {
208 XMLAttributeMap::getAttributeByQName(
const string& qname)
const
211 for (XMLAttributeMap::const_iterator it = begin(); it != end(); ++it) {
222 XMLAttributeMap::getAttributeByQName(
const string& prefix,
const string& localname)
const
231 XMLAttributeMap::const_iterator it;
232 for (it = begin(); it != end(); ++it) {
234 result += (attr.
getQName() +
"=\"" + attr.value +
"\" ");
239 XMLAttributeMap::iterator XMLAttributeMap::findByQName(
const string& qname)
241 XMLAttributeMap::iterator it;
242 for (it = _attributes.begin(); it != _attributes.end(); ++it) {
243 if (it->getQName() == qname) {
252 XMLNamespace::XMLNamespace(
const string& prefixArg,
const string& uriArg) :
253 prefix(prefixArg), uri(uriArg)
257 XMLNamespace::XMLNamespace(
const XMLNamespace& proto) :
258 prefix(proto.prefix), uri(proto.uri)
263 XMLNamespace::operator=(
const XMLNamespace& rhs)
276 prefix = XMLUtil::xmlCharToString(*pNamespace);
277 uri = XMLUtil::xmlCharToString(*(pNamespace + 1));
283 string attr(
"xmlns");
284 if (!prefix.empty()) {
285 attr += (string(
":") + prefix);
287 attr += string(
"=\"");
289 attr += string(
"\"");
295 XMLNamespaceMap::XMLNamespaceMap() :
300 XMLNamespaceMap::~XMLNamespaceMap()
305 XMLNamespaceMap::XMLNamespaceMap(
const XMLNamespaceMap& proto) :
306 _namespaces(proto._namespaces)
311 XMLNamespaceMap::operator=(
const XMLNamespaceMap& rhs)
316 _namespaces = rhs._namespaces;
323 for (
int i = 0; i < numNamespaces; ++i) {
334 for (XMLNamespaceMap::const_iterator it = begin(); it != end(); ++it) {
341 XMLNamespaceMap::const_iterator XMLNamespaceMap::begin()
const
343 return _namespaces.begin();
346 XMLNamespaceMap::const_iterator XMLNamespaceMap::end()
const
348 return _namespaces.end();
353 XMLNamespaceMap::const_iterator foundIt;
354 for (foundIt = begin(); foundIt != end(); ++foundIt) {
355 if (foundIt->prefix == prefix) {
362 bool XMLNamespaceMap::isInMap(
const string& prefix)
const
364 return (
find(prefix) != end());
369 XMLNamespaceMap::iterator foundIt = findNonConst(ns.prefix);
370 if (foundIt == _namespaces.end())
372 _namespaces.push_back(ns);
380 void XMLNamespaceMap::clear()
385 bool XMLNamespaceMap::empty()
const
387 return _namespaces.empty();
390 XMLNamespaceMap::iterator XMLNamespaceMap::findNonConst(
const string& prefix)
392 XMLNamespaceMap::iterator foundIt;
393 for (foundIt = _namespaces.begin(); foundIt != _namespaces.end(); ++foundIt) {
394 if (foundIt->prefix == prefix) {
403 XMLNamespaceStack::XMLNamespaceStack() :
408 XMLNamespaceStack::~XMLNamespaceStack()
414 XMLNamespaceStack::XMLNamespaceStack(
const XMLNamespaceStack& proto) :
420 XMLNamespaceStack::operator=(
const XMLNamespaceStack& rhs)
429 void XMLNamespaceStack::push(
const XMLNamespaceMap& nsMap)
431 _stack.push_back(nsMap);
434 void XMLNamespaceStack::pop()
439 const XMLNamespaceMap&
440 XMLNamespaceStack::top()
const
442 return _stack.back();
445 bool XMLNamespaceStack::empty()
const
447 return _stack.empty();
450 void XMLNamespaceStack::clear()
457 return _stack.rbegin();
460 XMLNamespaceStack::const_iterator XMLNamespaceStack::end()
const
462 return _stack.rend();
469 for (XMLNamespaceStack::const_iterator it =
begin(); it != end(); ++it) {
470 addMissingNamespaces(nsFlattened, *it);
477 for (XMLNamespaceMap::const_iterator it = fromMap.begin(); it != fromMap.end(); ++it) {
480 if (intoMap.
find(ns.prefix) == intoMap.end()) {