GME
13
|
00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 /* 00019 * $Id: XUtil.cpp 471747 2006-11-06 14:31:56Z amassari $ 00020 */ 00021 00022 00023 // --------------------------------------------------------------------------- 00024 // Includes 00025 // --------------------------------------------------------------------------- 00026 #include <xercesc/validators/schema/XUtil.hpp> 00027 #include <xercesc/util/XMLString.hpp> 00028 #include <xercesc/framework/XMLBuffer.hpp> 00029 #include <xercesc/util/IllegalArgumentException.hpp> 00030 #include <xercesc/dom/DOMElement.hpp> 00031 #include <xercesc/dom/DOMDocument.hpp> 00032 #include <xercesc/dom/DOMNamedNodeMap.hpp> 00033 #include <xercesc/dom/DOMNode.hpp> 00034 00035 XERCES_CPP_NAMESPACE_BEGIN 00036 00037 // Finds and returns the first child element node. 00038 DOMElement* XUtil::getFirstChildElement(const DOMNode* const parent) 00039 { 00040 // search for node 00041 DOMNode* child = parent->getFirstChild(); 00042 00043 while (child != 0) 00044 { 00045 if (child->getNodeType() == DOMNode::ELEMENT_NODE) 00046 return (DOMElement*)child; 00047 00048 child = child->getNextSibling(); 00049 } 00050 00051 // not found 00052 return 0; 00053 } 00054 00055 // Finds and returns the first child node with the given name. 00056 DOMElement* XUtil::getFirstChildElementNS(const DOMNode* const parent 00057 , const XMLCh** const elemNames 00058 , const XMLCh* const uriStr 00059 , unsigned int length) 00060 { 00061 // search for node 00062 DOMNode* child = parent->getFirstChild(); 00063 while (child != 0) 00064 { 00065 if (child->getNodeType() == DOMNode::ELEMENT_NODE) 00066 { 00067 for (unsigned int i = 0; i < length; i++) 00068 { 00069 if (XMLString::equals(child->getNamespaceURI(), uriStr) && 00070 XMLString::equals(child->getLocalName(), elemNames[i])) 00071 return (DOMElement*)child; 00072 } 00073 } 00074 child = child->getNextSibling(); 00075 } 00076 00077 // not found 00078 return 0; 00079 } 00080 00081 // Finds and returns the last child element node. 00082 DOMElement* XUtil::getNextSiblingElement(const DOMNode* const node) 00083 { 00084 // search for node 00085 DOMNode* sibling = node->getNextSibling(); 00086 00087 while (sibling != 0) 00088 { 00089 if (sibling->getNodeType() == DOMNode::ELEMENT_NODE) 00090 return (DOMElement*)sibling; 00091 00092 sibling = sibling->getNextSibling(); 00093 } 00094 00095 // not found 00096 return 0; 00097 } 00098 00099 // Finds and returns the next sibling element node with the give name. 00100 DOMElement* XUtil::getNextSiblingElementNS(const DOMNode* const node 00101 , const XMLCh** const elemNames 00102 , const XMLCh* const uriStr 00103 , unsigned int length) 00104 { 00105 // search for node 00106 DOMNode* sibling = node->getNextSibling(); 00107 while (sibling != 0) 00108 { 00109 if (sibling->getNodeType() == DOMNode::ELEMENT_NODE) 00110 { 00111 for (unsigned int i = 0; i < length; i++) 00112 { 00113 if (XMLString::equals(sibling->getNamespaceURI(), uriStr) && 00114 XMLString::equals(sibling->getLocalName(), elemNames[i])) 00115 return (DOMElement*)sibling; 00116 } 00117 } 00118 sibling = sibling->getNextSibling(); 00119 } 00120 00121 // not found 00122 return 0; 00123 } 00124 00125 XERCES_CPP_NAMESPACE_END