-/*
- * Copyright 2001-2010 Internet2
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * UCAID licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the
+ * License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
*/
/**
#ifndef __xmltooling_xmlhelper_h__
#define __xmltooling_xmlhelper_h__
-#include <xmltooling/base.h>
+#include <xmltooling/unicode.h>
-#include <set>
+#include <map>
#include <iostream>
#include <xercesc/dom/DOM.hpp>
/**
* Gets the XSI type for a given element if it has one.
+ * <p>The caller is responsible for freeing the result.
*
* @param e the element
* @return the type or null
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.
/**
* @deprecated
* Constructs a QName from an attribute's value.
+ * <p>The caller is responsible for freeing the result.
*
* @param attribute the attribute with a QName value
* @return a QName from an attribute's value, or null if the given attribute is null
/**
* Constructs a QName from a node's value.
+ * <p>The caller is responsible for freeing the result.
*
* @param domNode the DOM node with a QName value
* @return a QName from a node's value, or null if the given node has no value
static QName* getNodeValueAsQName(const xercesc::DOMNode* domNode);
/**
+ * Returns a boolean based on a node's value.
+ *
+ * @param domNode the DOM node with a boolean (1/0/true/false) value
+ * @param def value to return if the node is null/missing
+ * @return a bool value based on the node's value, or a default value
+ */
+ static bool getNodeValueAsBool(const xercesc::DOMNode* domNode, bool def);
+
+ /**
* Appends the child Element to the parent Element,
* importing the child Element into the parent's Document if needed.
*
/**
* 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
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.
*