A helper class for working with W3C DOM objects. More...
#include <xmltooling/util/XMLHelper.h>
Static Public Member Functions | |
static bool | hasXSIType (const xercesc::DOMElement *e) |
Checks if the given element has an xsi:type defined for it. | |
static QName * | getXSIType (const xercesc::DOMElement *e) |
Gets the XSI type for a given element if it has one. | |
static xercesc::DOMAttr * | getIdAttribute (const xercesc::DOMElement *domElement) |
Gets the ID attribute of a DOM element. | |
static const XMLObject * | getXMLObjectById (const XMLObject &tree, const XMLCh *id) |
Attempts to locate an XMLObject from this point downward in the tree whose XML ID matches the supplied value. | |
static XMLObject * | getXMLObjectById (XMLObject &tree, const XMLCh *id) |
Attempts to locate an XMLObject from this point downward in the tree whose XML ID matches the supplied value. | |
static void | getNonVisiblyUsedPrefixes (const XMLObject &tree, std::map< xstring, xstring > &prefixes) |
Returns the set of non-visibly-used namespace declarations found in a tree. | |
static QName * | getNodeQName (const xercesc::DOMNode *domNode) |
Gets the QName for the given DOM node. | |
static QName * | getNodeValueAsQName (const xercesc::DOMNode *domNode) |
Constructs a QName from a node's value. | |
static bool | getNodeValueAsBool (const xercesc::DOMNode *domNode, bool def) |
Returns a boolean based on a node's value. | |
static xercesc::DOMElement * | appendChildElement (xercesc::DOMElement *parentElement, xercesc::DOMElement *childElement) |
Appends the child Element to the parent Element, importing the child Element into the parent's Document if needed. | |
static bool | isNodeNamed (const xercesc::DOMNode *n, const XMLCh *ns, const XMLCh *local) |
Checks the qualified name of a node. | |
static xercesc::DOMElement * | getFirstChildElement (const xercesc::DOMNode *n, const XMLCh *localName=0) |
Returns the first matching child element of the node if any. | |
static xercesc::DOMElement * | getLastChildElement (const xercesc::DOMNode *n, const XMLCh *localName=0) |
Returns the last matching child element of the node if any. | |
static xercesc::DOMElement * | getNextSiblingElement (const xercesc::DOMNode *n, const XMLCh *localName=0) |
Returns the next matching sibling element of the node if any. | |
static xercesc::DOMElement * | getPreviousSiblingElement (const xercesc::DOMNode *n, const XMLCh *localName=0) |
Returns the previous matching sibling element of the node if any. | |
static xercesc::DOMElement * | getFirstChildElement (const xercesc::DOMNode *n, const XMLCh *ns, const XMLCh *localName) |
Returns the first matching child element of the node if any. | |
static xercesc::DOMElement * | getLastChildElement (const xercesc::DOMNode *n, const XMLCh *ns, const XMLCh *localName) |
Returns the last matching child element of the node if any. | |
static xercesc::DOMElement * | getNextSiblingElement (const xercesc::DOMNode *n, const XMLCh *ns, const XMLCh *localName) |
Returns the next matching sibling element of the node if any. | |
static xercesc::DOMElement * | getPreviousSiblingElement (const xercesc::DOMNode *n, const XMLCh *ns, const XMLCh *localName) |
Returns the previous matching sibling element of the node if any. | |
static XMLCh * | getWholeTextContent (const xercesc::DOMElement *e) |
Returns all text content inside an element, regardless of the number of child nodes involved, up to the first child element encountered if any. | |
static const XMLCh * | getTextContent (const xercesc::DOMElement *e) |
Returns the content of the first Text node found in the element, if any, acting on the assumption there can be no embedded comment, CDATA, or other interfering node types interrupting the text. | |
static std::string | getAttrString (const xercesc::DOMElement *e, const char *defValue, const XMLCh *localName, const XMLCh *ns=0) |
Returns the content of the specified attribute node as a string, or the default value, if the attribute is not present. | |
static int | getAttrInt (const xercesc::DOMElement *e, int defValue, const XMLCh *localName, const XMLCh *ns=0) |
Returns the content of the specified attribute node as an integer, or the default value, if the attribute is not present. | |
static bool | getAttrBool (const xercesc::DOMElement *e, bool defValue, const XMLCh *localName, const XMLCh *ns=0) |
Returns the content of the specified attribute node as a boolean, or the default value, if the attribute is not present. | |
static bool | getCaseSensitive (const xercesc::DOMElement *e, bool defValue, const XMLCh *ns=0) |
Returns the value of the attribute "caseSensitive" (if present). | |
static void | encode (std::ostream &os, const char *str) |
Perform XMLEncoding on the input string into the provided stream. | |
static std::string | encode (const char *str) |
Perform XMLEncoding on the input string. | |
static void | serialize (const xercesc::DOMNode *n, std::string &buf, bool pretty=false) |
Serializes the DOM node provided into a buffer using UTF-8 encoding and the default XML serializer available. | |
static std::ostream & | serialize (const xercesc::DOMNode *n, std::ostream &out, bool pretty=false) |
Serializes the DOM node provided to a stream using UTF-8 encoding and the default XML serializer available. | |
static char * | deflate (char *in, unsigned int in_len, unsigned int *out_len) |
Deflates data in accordance with RFC1951. | |
static unsigned int | inflate (char *in, unsigned int in_len, std::ostream &out) |
Inflates data compressed in accordance with RFC1951 and sends the results to an output stream. |
A helper class for working with W3C DOM objects.
static xercesc::DOMElement* xmltooling::XMLHelper::appendChildElement | ( | xercesc::DOMElement * | parentElement, | |
xercesc::DOMElement * | childElement | |||
) | [static] |
Appends the child Element to the parent Element, importing the child Element into the parent's Document if needed.
parentElement | the parent Element | |
childElement | the child Element |
static char* xmltooling::XMLHelper::deflate | ( | char * | in, | |
unsigned int | in_len, | |||
unsigned int * | out_len | |||
) | [static] |
Deflates data in accordance with RFC1951.
The caller must free the resulting buffer using delete[]
in | the data to compress | |
in_len | length of input data | |
out_len | will contain the length of the resulting data |
static std::string xmltooling::XMLHelper::encode | ( | const char * | str | ) | [static] |
Perform XMLEncoding on the input string.
Symbols handled: (") < (<) > (>) & (&)
str | what to encode |
static void xmltooling::XMLHelper::encode | ( | std::ostream & | os, | |
const char * | str | |||
) | [static] |
Perform XMLEncoding on the input string into the provided stream.
Symbols handled: (") < (<) > (>) & (&)
os | where to put the encoded string | |
str | what to encode |
static bool xmltooling::XMLHelper::getAttrBool | ( | const xercesc::DOMElement * | e, | |
bool | defValue, | |||
const XMLCh * | localName, | |||
const XMLCh * | ns = 0 | |||
) | [static] |
Returns the content of the specified attribute node as a boolean, or the default value, if the attribute is not present.
e | element to examine (may be nullptr) | |
defValue | default value to return | |
localName | local name of attribute | |
ns | namespace of attribute |
static int xmltooling::XMLHelper::getAttrInt | ( | const xercesc::DOMElement * | e, | |
int | defValue, | |||
const XMLCh * | localName, | |||
const XMLCh * | ns = 0 | |||
) | [static] |
Returns the content of the specified attribute node as an integer, or the default value, if the attribute is not present.
e | element to examine (may be nullptr) | |
defValue | default value to return | |
localName | local name of attribute | |
ns | namespace of attribute |
static std::string xmltooling::XMLHelper::getAttrString | ( | const xercesc::DOMElement * | e, | |
const char * | defValue, | |||
const XMLCh * | localName, | |||
const XMLCh * | ns = 0 | |||
) | [static] |
Returns the content of the specified attribute node as a string, or the default value, if the attribute is not present.
e | element to examine (may be nullptr) | |
defValue | default value to return | |
localName | local name of attribute | |
ns | namespace of attribute |
static bool xmltooling::XMLHelper::getCaseSensitive | ( | const xercesc::DOMElement * | e, | |
bool | defValue, | |||
const XMLCh * | ns = 0 | |||
) | [static] |
Returns the value of the attribute "caseSensitive" (if present).
Also interogates the (deprecated) "ignoreCase" attribute, warning if it is encountered.
e | element to examine (may be nullptr) | |
defValue | default value to return | |
ns | namespace of attribute |
static xercesc::DOMElement* xmltooling::XMLHelper::getFirstChildElement | ( | const xercesc::DOMNode * | n, | |
const XMLCh * | ns, | |||
const XMLCh * | localName | |||
) | [static] |
Returns the first matching child element of the node if any.
n | node to check | |
ns | namespace to compare with | |
localName | local name to compare with |
static xercesc::DOMElement* xmltooling::XMLHelper::getFirstChildElement | ( | const xercesc::DOMNode * | n, | |
const XMLCh * | localName = 0 | |||
) | [static] |
Returns the first matching child element of the node if any.
n | node to check | |
localName | local name to compare with or nullptr for any match |
static xercesc::DOMAttr* xmltooling::XMLHelper::getIdAttribute | ( | const xercesc::DOMElement * | domElement | ) | [static] |
Gets the ID attribute of a DOM element.
domElement | the DOM element |
static xercesc::DOMElement* xmltooling::XMLHelper::getLastChildElement | ( | const xercesc::DOMNode * | n, | |
const XMLCh * | ns, | |||
const XMLCh * | localName | |||
) | [static] |
Returns the last matching child element of the node if any.
n | node to check | |
ns | namespace to compare with | |
localName | local name to compare with |
static xercesc::DOMElement* xmltooling::XMLHelper::getLastChildElement | ( | const xercesc::DOMNode * | n, | |
const XMLCh * | localName = 0 | |||
) | [static] |
Returns the last matching child element of the node if any.
n | node to check | |
localName | local name to compare with or nullptr for any match |
static xercesc::DOMElement* xmltooling::XMLHelper::getNextSiblingElement | ( | const xercesc::DOMNode * | n, | |
const XMLCh * | ns, | |||
const XMLCh * | localName | |||
) | [static] |
Returns the next matching sibling element of the node if any.
n | node to check | |
ns | namespace to compare with | |
localName | local name to compare with |
static xercesc::DOMElement* xmltooling::XMLHelper::getNextSiblingElement | ( | const xercesc::DOMNode * | n, | |
const XMLCh * | localName = 0 | |||
) | [static] |
Returns the next matching sibling element of the node if any.
n | node to check | |
localName | local name to compare with or nullptr for any match |
static QName* xmltooling::XMLHelper::getNodeQName | ( | const xercesc::DOMNode * | domNode | ) | [static] |
static bool xmltooling::XMLHelper::getNodeValueAsBool | ( | const xercesc::DOMNode * | domNode, | |
bool | def | |||
) | [static] |
Returns a boolean based on a node's value.
domNode | the DOM node with a boolean (1/0/true/false) value | |
def | value to return if the node is null/missing |
static QName* xmltooling::XMLHelper::getNodeValueAsQName | ( | const xercesc::DOMNode * | domNode | ) | [static] |
static void xmltooling::XMLHelper::getNonVisiblyUsedPrefixes | ( | const XMLObject & | tree, | |
std::map< xstring, xstring > & | prefixes | |||
) | [static] |
Returns the set of non-visibly-used namespace declarations found in a tree.
Each member of the set is a prefix/URI pair.
tree | root of tree to search | |
prefixes | container to store declarations |
static xercesc::DOMElement* xmltooling::XMLHelper::getPreviousSiblingElement | ( | const xercesc::DOMNode * | n, | |
const XMLCh * | ns, | |||
const XMLCh * | localName | |||
) | [static] |
Returns the previous matching sibling element of the node if any.
n | node to check | |
ns | namespace to compare with | |
localName | local name to compare with |
static xercesc::DOMElement* xmltooling::XMLHelper::getPreviousSiblingElement | ( | const xercesc::DOMNode * | n, | |
const XMLCh * | localName = 0 | |||
) | [static] |
Returns the previous matching sibling element of the node if any.
n | node to check | |
localName | local name to compare with or nullptr for any match |
static const XMLCh* xmltooling::XMLHelper::getTextContent | ( | const xercesc::DOMElement * | e | ) | [static] |
Returns the content of the first Text node found in the element, if any, acting on the assumption there can be no embedded comment, CDATA, or other interfering node types interrupting the text.
e | element to examine |
static XMLCh* xmltooling::XMLHelper::getWholeTextContent | ( | const xercesc::DOMElement * | e | ) | [static] |
Returns all text content inside an element, regardless of the number of child nodes involved, up to the first child element encountered if any.
Because this may require merging data, the text is returned in a separately allocated buffer the caller must free using delete[].
e | the element |
static QName* xmltooling::XMLHelper::getXSIType | ( | const xercesc::DOMElement * | e | ) | [static] |
Gets the XSI type for a given element if it has one.
The caller is responsible for freeing the result.
e | the element |
static bool xmltooling::XMLHelper::hasXSIType | ( | const xercesc::DOMElement * | e | ) | [static] |
Checks if the given element has an xsi:type defined for it.
e | the DOM element |
static unsigned int xmltooling::XMLHelper::inflate | ( | char * | in, | |
unsigned int | in_len, | |||
std::ostream & | out | |||
) | [static] |
Inflates data compressed in accordance with RFC1951 and sends the results to an output stream.
in | the data to inflate | |
in_len | length of input data | |
out | reference to output stream to receive data |
static bool xmltooling::XMLHelper::isNodeNamed | ( | const xercesc::DOMNode * | n, | |
const XMLCh * | ns, | |||
const XMLCh * | local | |||
) | [static] |
Checks the qualified name of a node.
n | node to check | |
ns | namespace to compare with | |
local | local name to compare with |
static std::ostream& xmltooling::XMLHelper::serialize | ( | const xercesc::DOMNode * | n, | |
std::ostream & | out, | |||
bool | pretty = false | |||
) | [static] |
Serializes the DOM node provided to a stream using UTF-8 encoding and the default XML serializer available.
No manipulation or formatting is applied.
n | node to serialize | |
out | stream to serialize element into | |
pretty | enable pretty printing if supported |
static void xmltooling::XMLHelper::serialize | ( | const xercesc::DOMNode * | n, | |
std::string & | buf, | |||
bool | pretty = false | |||
) | [static] |
Serializes the DOM node provided into a buffer using UTF-8 encoding and the default XML serializer available.
No manipulation or formatting is applied.
n | node to serialize | |
buf | buffer to serialize element into | |
pretty | enable pretty printing if supported |