Handle empty path as relative.
[shibboleth/cpp-xmltooling.git] / xmltooling / util / XMLHelper.h
index c7f810f..284d5f0 100644 (file)
@@ -25,7 +25,7 @@
 
 #include <xmltooling/base.h>
 
-#include <set>
+#include <map>
 #include <iostream>
 #include <xercesc/dom/DOM.hpp>
 
@@ -135,12 +135,13 @@ namespace xmltooling {
         static XMLObject* getXMLObjectById(XMLObject& tree, const XMLCh* id);
 
         /**
-         * Returns a list of non-visibly-used namespace prefixes found in a tree.
+         * Returns the set of non-visibly-used namespace declarations found in a tree.
+         * <p>Each member of the set is a prefix/URI pair.
          *
          * @param tree      root of tree to search
-         * @param prefixes  container to store prefix list
+         * @param prefixes  container to store declarations
          */
-        static void getNonVisiblyUsedPrefixes(const XMLObject& tree, std::set<xstring>& prefixes);
+        static void getNonVisiblyUsedPrefixes(const XMLObject& tree, std::map<xstring,xstring>& prefixes);
 
         /**
          * Gets the QName for the given DOM node.
@@ -275,7 +276,7 @@ namespace xmltooling {
         /**
          * Returns the content of the first Text node found in the element, if any.
          * This is roughly similar to the DOM getTextContent function, but only
-         * examples the immediate children of the element.
+         * examines the immediate children of the element.
          *
          * @param e     element to examine
          * @return the content of the first Text node found, or nullptr
@@ -283,6 +284,48 @@ namespace xmltooling {
         static const XMLCh* getTextContent(const xercesc::DOMElement* e);
 
         /**
+         * Returns the content of the specified attribute node as a string,
+         * or the default value, if the attribute is not present.
+         *
+         * @param e         element to examine (may be nullptr)
+         * @param defValue  default value to return
+         * @param localName local name of attribute
+         * @param ns        namespace of attribute
+         * @return  the specified attribute's value, or the specified default
+         */
+        static std::string getAttrString(
+            const xercesc::DOMElement* e, const char* defValue, const XMLCh* localName, const XMLCh* ns=nullptr
+            );
+
+        /**
+         * Returns the content of the specified attribute node as an integer,
+         * or the default value, if the attribute is not present.
+         *
+         * @param e         element to examine (may be nullptr)
+         * @param defValue  default value to return
+         * @param localName local name of attribute
+         * @param ns        namespace of attribute
+         * @return  the specified attribute's value, or the specified default
+         */
+        static int getAttrInt(
+            const xercesc::DOMElement* e, int defValue, const XMLCh* localName, const XMLCh* ns=nullptr
+            );
+
+        /**
+         * Returns the content of the specified attribute node as a boolean,
+         * or the default value, if the attribute is not present.
+         *
+         * @param e         element to examine (may be nullptr)
+         * @param defValue  default value to return
+         * @param localName local name of attribute
+         * @param ns        namespace of attribute
+         * @return  the specified attribute's value, or the specified default
+         */
+        static bool getAttrBool(
+            const xercesc::DOMElement* e, bool defValue, const XMLCh* localName, const XMLCh* ns=nullptr
+            );
+
+        /**
          * Serializes the DOM node provided into a buffer using UTF-8 encoding and
          * the default XML serializer available. No manipulation or formatting is applied.
          *