/*
- * Copyright 2001-2009 Internet2
+ * Copyright 2001-2010 Internet2
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
return ret;
}
else {
- return new xmltooling::QName(e->lookupNamespaceURI(NULL), attributeValue);
+ return new xmltooling::QName(e->lookupNamespaceURI(nullptr), attributeValue);
}
}
}
- return NULL;
+ return nullptr;
}
DOMAttr* XMLHelper::getIdAttribute(const DOMElement* domElement)
{
if(!domElement->hasAttributes()) {
- return NULL;
+ return nullptr;
}
DOMNamedNodeMap* attributes = domElement->getAttributes();
}
}
- return NULL;
+ return nullptr;
}
const XMLObject* XMLHelper::getXMLObjectById(const XMLObject& tree, const XMLCh* id)
}
}
- return NULL;
+ return nullptr;
}
XMLObject* XMLHelper::getXMLObjectById(XMLObject& tree, const XMLCh* id)
}
}
- return NULL;
+ return nullptr;
}
-void XMLHelper::getNonVisiblyUsedPrefixes(const XMLObject& tree, set<xstring>& prefixes)
+void XMLHelper::getNonVisiblyUsedPrefixes(const XMLObject& tree, map<xstring,xstring>& prefixes)
{
- set<xstring> child_prefixes;
+ map<xstring,xstring> child_prefixes;
const list<XMLObject*>& children = tree.getOrderedChildren();
for (list<XMLObject*>::const_iterator i = children.begin(); i != children.end(); ++i) {
if (*i)
case Namespace::Indeterminate:
break;
case Namespace::VisiblyUsed:
- child_prefixes.erase(ns->getNamespacePrefix() ? ns->getNamespacePrefix() : &chNull);
+ {
+ // See if the prefix was noted as non-visible below.
+ const XMLCh* p = ns->getNamespacePrefix() ? ns->getNamespacePrefix() : &chNull;
+ map<xstring,xstring>::iterator decl = child_prefixes.find(p);
+ if (decl != child_prefixes.end()) {
+ // It's declared below, see if it's the same namespace. If so, pull it from the set,
+ // otherwise leave it in the set.
+ if (decl->second == (ns->getNamespaceURI() ? ns->getNamespaceURI() : &chNull))
+ child_prefixes.erase(decl);
+ }
break;
+ }
case Namespace::NonVisiblyUsed:
- prefixes.insert(ns->getNamespacePrefix() ? ns->getNamespacePrefix() : &chNull);
+ // It may already be in the map from another branch of the tree, but as long
+ // as it's set to something so the parent knows about it, we're good.
+ prefixes[ns->getNamespacePrefix() ? ns->getNamespacePrefix() : &chNull] = (ns->getNamespaceURI() ? ns->getNamespaceURI() : &chNull);
break;
}
}
+
prefixes.insert(child_prefixes.begin(), child_prefixes.end());
}
{
if (domNode)
return new xmltooling::QName(domNode->getNamespaceURI(), domNode->getLocalName(), domNode->getPrefix());
- return NULL;
+ return nullptr;
}
xmltooling::QName* XMLHelper::getAttributeValueAsQName(const DOMAttr* attribute)
xmltooling::QName* XMLHelper::getNodeValueAsQName(const DOMNode* domNode)
{
if (!domNode)
- return NULL;
+ return nullptr;
int i;
const XMLCh* value=domNode->getTextContent();
return ret;
}
- return new xmltooling::QName(domNode->lookupNamespaceURI(NULL), value);
+ return new xmltooling::QName(domNode->lookupNamespaceURI(nullptr), value);
+}
+
+bool XMLHelper::getNodeValueAsBool(const xercesc::DOMNode* domNode, bool def)
+{
+ if (!domNode)
+ return def;
+ const XMLCh* value = domNode->getNodeValue();
+ if (!value || !*value)
+ return def;
+ if (*value == chLatin_t || *value == chDigit_1)
+ return true;
+ else if (*value == chLatin_f || *value == chDigit_0)
+ return false;
+ return def;
}
DOMElement* XMLHelper::appendChildElement(DOMElement* parentElement, DOMElement* childElement)
const XMLCh* XMLHelper::getTextContent(const DOMElement* e)
{
- DOMNode* child=e->getFirstChild();
+ DOMNode* child = e ? e->getFirstChild() : nullptr;
while (child) {
- if (child->getNodeType()==DOMNode::TEXT_NODE)
+ if (child->getNodeType() == DOMNode::TEXT_NODE)
return child->getNodeValue();
- child=child->getNextSibling();
+ child = child->getNextSibling();
}
- return NULL;
+ return nullptr;
}
DOMElement* XMLHelper::getFirstChildElement(const DOMNode* n, const XMLCh* localName)
{
- DOMNode* child = n->getFirstChild();
+ DOMNode* child = n ? n->getFirstChild() : nullptr;
while (child && child->getNodeType() != DOMNode::ELEMENT_NODE)
child = child->getNextSibling();
if (child && localName) {
DOMElement* XMLHelper::getLastChildElement(const DOMNode* n, const XMLCh* localName)
{
- DOMNode* child = n->getLastChild();
+ DOMNode* child = n ? n->getLastChild() : nullptr;
while (child && child->getNodeType() != DOMNode::ELEMENT_NODE)
child = child->getPreviousSibling();
if (child && localName) {
DOMElement* XMLHelper::getNextSiblingElement(const DOMNode* n, const XMLCh* localName)
{
- DOMNode* sib = n->getNextSibling();
+ DOMNode* sib = n ? n->getNextSibling() : nullptr;
while (sib && sib->getNodeType() != DOMNode::ELEMENT_NODE)
sib = sib->getNextSibling();
if (sib && localName) {
DOMElement* XMLHelper::getPreviousSiblingElement(const DOMNode* n, const XMLCh* localName)
{
- DOMNode* sib = n->getPreviousSibling();
+ DOMNode* sib = n ? n->getPreviousSibling() : nullptr;
while (sib && sib->getNodeType() != DOMNode::ELEMENT_NODE)
sib = sib->getPreviousSibling();
if (sib && localName) {
return e;
}
+string XMLHelper::getAttrString(const DOMElement* e, const char* defValue, const XMLCh* localName, const XMLCh* ns)
+{
+ if (e) {
+ auto_ptr_char val(e->getAttributeNS(ns, localName));
+ if (val.get() && *val.get())
+ return val.get();
+ }
+ return defValue ? defValue : "";
+}
+
+int XMLHelper::getAttrInt(const DOMElement* e, int defValue, const XMLCh* localName, const XMLCh* ns)
+{
+ if (e) {
+ const XMLCh* val = e->getAttributeNS(ns, localName);
+ if (val && *val) {
+ int i = XMLString::parseInt(val);
+ if (i)
+ return i;
+ }
+ }
+ return defValue;
+}
+
+bool XMLHelper::getAttrBool(const DOMElement* e, bool defValue, const XMLCh* localName, const XMLCh* ns)
+{
+ if (e) {
+ const XMLCh* val = e->getAttributeNS(ns, localName);
+ if (val) {
+ if (*val == chLatin_t || *val == chDigit_1)
+ return true;
+ if (*val == chLatin_f || *val == chDigit_0)
+ return false;
+ }
+ }
+ return defValue;
+}
+
void XMLHelper::serialize(const DOMNode* n, std::string& buf, bool pretty)
{
static const XMLCh impltype[] = { chLatin_L, chLatin_S, chNull };