30 #include "XMLHelpers.h"
36 string XMLUtil::xmlCharToString(
const xmlChar* theCharsOrNull)
38 const char* asChars = reinterpret_cast<const char*>(theCharsOrNull);
39 return ((asChars) ? (
string(asChars)) : (
string(
"")));
42 void XMLUtil::xmlCharToString(
string& stringToFill,
const xmlChar* pChars)
44 stringToFill = xmlCharToString(pChars);
49 string XMLUtil::xmlCharToStringFromIterators(
const xmlChar* startIter,
const xmlChar* endIter)
52 if (!startIter || !endIter || (startIter > endIter)) {
57 return string(reinterpret_cast<const char*>(startIter), reinterpret_cast<const char*>(endIter));
61 XMLAttribute::XMLAttribute(
const string& localNameA,
const string& valueA,
const string& prefixA,
const string& nsURIA) :
62 localname(localNameA), prefix(prefixA), nsURI(nsURIA), value(valueA)
69 XMLAttribute::XMLAttribute(
const xmlChar** chunkOfFivePointers)
71 fromSAX2NamespaceAttributes(chunkOfFivePointers);
75 localname(proto.localname), prefix(proto.prefix), nsURI(proto.nsURI), value(proto.value)
80 XMLAttribute::operator=(
const XMLAttribute& rhs)
85 localname = rhs.localname;
94 const xmlChar* xmlLocalName = (*chunkOfFivePointers++);
95 const xmlChar* xmlPrefix = (*chunkOfFivePointers++);
96 const xmlChar* xmlURI = (*chunkOfFivePointers++);
97 const xmlChar* xmlValueStart = (*chunkOfFivePointers++);
99 const xmlChar* xmlValueEnd = (*chunkOfFivePointers++);
102 localname = XMLUtil::xmlCharToString(xmlLocalName);
103 prefix = XMLUtil::xmlCharToString(xmlPrefix);
104 nsURI = XMLUtil::xmlCharToString(xmlURI);
105 value = XMLUtil::xmlCharToStringFromIterators(xmlValueStart, xmlValueEnd);
120 return getQName() +
"=\"" + value +
"\"";
126 if (prefix.empty()) {
130 return prefix +
":" + localname;
135 XMLAttributeMap::XMLAttributeMap() :
140 XMLAttributeMap::~XMLAttributeMap()
144 XMLAttributeMap::const_iterator XMLAttributeMap::begin()
const
146 return _attributes.begin();
149 XMLAttributeMap::const_iterator XMLAttributeMap::end()
const
151 return _attributes.end();
154 bool XMLAttributeMap::empty()
const
156 return _attributes.empty();
167 XMLAttributeMap::iterator foundIt = findByQName(attribute.
getQName());
169 if (foundIt != _attributes.end()) {
175 _attributes.push_back(attribute);
195 for (XMLAttributeMap::const_iterator it = begin(); it != end(); ++it) {
197 if (rAttr.localname == localname) {
206 XMLAttributeMap::getAttributeByQName(
const string& qname)
const
209 for (XMLAttributeMap::const_iterator it = begin(); it != end(); ++it) {
220 XMLAttributeMap::getAttributeByQName(
const string& prefix,
const string& localname)
const
229 XMLAttributeMap::const_iterator it;
230 for (it = begin(); it != end(); ++it) {
232 result += (attr.
getQName() +
"=\"" + attr.value +
"\" ");
237 XMLAttributeMap::iterator XMLAttributeMap::findByQName(
const string& qname)
239 XMLAttributeMap::iterator it;
240 for (it = _attributes.begin(); it != _attributes.end(); ++it) {
241 if (it->getQName() == qname) {
250 XMLNamespace::XMLNamespace(
const string& prefixArg,
const string& uriArg) :
251 prefix(prefixArg), uri(uriArg)
255 XMLNamespace::XMLNamespace(
const XMLNamespace& proto) :
256 prefix(proto.prefix), uri(proto.uri)
261 XMLNamespace::operator=(
const XMLNamespace& rhs)
274 prefix = XMLUtil::xmlCharToString(*pNamespace);
275 uri = XMLUtil::xmlCharToString(*(pNamespace + 1));
281 string attr(
"xmlns");
282 if (!prefix.empty()) {
283 attr += (string(
":") + prefix);
285 attr += string(
"=\"");
287 attr += string(
"\"");
293 XMLNamespaceMap::XMLNamespaceMap() :
298 XMLNamespaceMap::~XMLNamespaceMap()
303 XMLNamespaceMap::XMLNamespaceMap(
const XMLNamespaceMap& proto) :
304 _namespaces(proto._namespaces)
309 XMLNamespaceMap::operator=(
const XMLNamespaceMap& rhs)
314 _namespaces = rhs._namespaces;
321 for (
int i = 0; i < numNamespaces; ++i) {
332 for (XMLNamespaceMap::const_iterator it = begin(); it != end(); ++it) {
339 XMLNamespaceMap::const_iterator XMLNamespaceMap::begin()
const
341 return _namespaces.begin();
344 XMLNamespaceMap::const_iterator XMLNamespaceMap::end()
const
346 return _namespaces.end();
351 XMLNamespaceMap::const_iterator foundIt;
352 for (foundIt = begin(); foundIt != end(); ++foundIt) {
353 if (foundIt->prefix == prefix) {
360 bool XMLNamespaceMap::isInMap(
const string& prefix)
const
362 return (
find(prefix) != end());
367 XMLNamespaceMap::iterator foundIt = findNonConst(ns.prefix);
368 if (foundIt == _namespaces.end())
370 _namespaces.push_back(ns);
378 void XMLNamespaceMap::clear()
383 bool XMLNamespaceMap::empty()
const
385 return _namespaces.empty();
388 XMLNamespaceMap::iterator XMLNamespaceMap::findNonConst(
const string& prefix)
390 XMLNamespaceMap::iterator foundIt;
391 for (foundIt = _namespaces.begin(); foundIt != _namespaces.end(); ++foundIt) {
392 if (foundIt->prefix == prefix) {
401 XMLNamespaceStack::XMLNamespaceStack() :
406 XMLNamespaceStack::~XMLNamespaceStack()
412 XMLNamespaceStack::XMLNamespaceStack(
const XMLNamespaceStack& proto) :
418 XMLNamespaceStack::operator=(
const XMLNamespaceStack& rhs)
427 void XMLNamespaceStack::push(
const XMLNamespaceMap& nsMap)
429 _stack.push_back(nsMap);
432 void XMLNamespaceStack::pop()
437 const XMLNamespaceMap&
438 XMLNamespaceStack::top()
const
440 return _stack.back();
443 bool XMLNamespaceStack::empty()
const
445 return _stack.empty();
448 void XMLNamespaceStack::clear()
455 return _stack.rbegin();
458 XMLNamespaceStack::const_iterator XMLNamespaceStack::end()
const
460 return _stack.rend();
467 for (XMLNamespaceStack::const_iterator it =
begin(); it != end(); ++it) {
468 addMissingNamespaces(nsFlattened, *it);
475 for (XMLNamespaceMap::const_iterator it = fromMap.begin(); it != fromMap.end(); ++it) {
478 if (intoMap.
find(ns.prefix) == intoMap.end()) {