2 * Copyright 2001-2006 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
20 * A helper class for working with W3C DOM objects.
\r
23 #if !defined(__xmltooling_xmlhelper_h__)
\r
24 #define __xmltooling_xmlhelper_h__
\r
26 #include <xmltooling/QName.h>
\r
27 #include <xercesc/dom/DOM.hpp>
\r
29 using namespace xercesc;
\r
31 namespace xmltooling {
\r
34 * A helper class for working with W3C DOM objects.
\r
36 class XMLTOOL_API XMLHelper
\r
40 * Checks if the given element has an xsi:type defined for it
\r
42 * @param e the DOM element
\r
43 * @return true if there is a type, false if not
\r
45 static bool hasXSIType(const DOMElement* e);
\r
48 * Gets the XSI type for a given element if it has one.
\r
50 * @param e the element
\r
51 * @return the type or null
\r
53 static QName* getXSIType(const DOMElement* e);
\r
56 * Gets the ID attribute of a DOM element.
\r
58 * @param domElement the DOM element
\r
59 * @return the ID attribute or null if there isn't one
\r
61 static DOMAttr* getIdAttribute(const DOMElement* domElement);
\r
64 * Gets the QName for the given DOM node.
\r
66 * @param domNode the DOM node
\r
67 * @return the QName for the element or null if the element was null
\r
69 static QName* getNodeQName(const DOMNode* domNode);
\r
72 * Constructs a QName from an attributes value.
\r
74 * @param attribute the attribute with a QName value
\r
75 * @return a QName from an attributes value, or null if the given attribute is null
\r
77 static QName* getAttributeValueAsQName(const DOMAttr* attribute);
\r
80 * Appends the child Element to the parent Element,
\r
81 * importing the child Element into the parent's Document if needed.
\r
83 * @param parentElement the parent Element
\r
84 * @param childElement the child Element
\r
85 * @return the child Element that was added (may be an imported copy)
\r
87 static DOMElement* appendChildElement(DOMElement* parentElement, DOMElement* childElement);
\r
90 * Checks the qualified name of an element.
\r
92 * @param e element to check
\r
93 * @param ns namespace to compare with
\r
94 * @param local local name to compare with
\r
95 * @return true iff the element's qualified name matches the other parameters
\r
97 static bool isElementNamed(const DOMElement* e, const XMLCh* ns, const XMLCh* local) {
\r
98 return (e && !XMLString::compareString(ns,e->getNamespaceURI()) && !XMLString::compareString(local,e->getLocalName()));
\r
104 #endif /* __xmltooling_xmlhelper_h__ */
\r