source: icXML/icXML-devel/src/xercesc/validators/schema/XUtil.cpp @ 2734

Last change on this file since 2734 was 2722, checked in by cameron, 7 years ago

Original Xerces files with import mods for icxercesc

File size: 3.9 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: XUtil.cpp 471747 2006-11-06 14:31:56Z amassari $
20 */
21
22
23// ---------------------------------------------------------------------------
24//  Includes
25// ---------------------------------------------------------------------------
26#include <xercesc/validators/schema/XUtil.hpp>
27#include <icxercesc/util/XMLString.hpp>
28#include <icxercesc/framework/XMLBuffer.hpp>
29#include <xercesc/util/IllegalArgumentException.hpp>
30#include <xercesc/dom/DOMElement.hpp>
31#include <xercesc/dom/DOMDocument.hpp>
32#include <xercesc/dom/DOMNamedNodeMap.hpp>
33#include <xercesc/dom/DOMNode.hpp>
34
35XERCES_CPP_NAMESPACE_BEGIN
36
37// Finds and returns the first child element node.
38DOMElement* XUtil::getFirstChildElement(const DOMNode* const parent)
39{
40    // search for node
41    DOMNode* child = parent->getFirstChild();
42
43    while (child != 0)
44        {
45        if (child->getNodeType() == DOMNode::ELEMENT_NODE)
46            return (DOMElement*)child;
47
48        child = child->getNextSibling();
49    }
50
51    // not found
52    return 0;
53}
54
55// Finds and returns the first child node with the given name.
56DOMElement* XUtil::getFirstChildElementNS(const DOMNode* const parent
57                                          , const XMLCh** const elemNames
58                                          , const XMLCh* const uriStr
59                                          , unsigned int        length)
60{
61    // search for node
62    DOMNode* child = parent->getFirstChild();
63    while (child != 0)
64        {
65        if (child->getNodeType() == DOMNode::ELEMENT_NODE)
66                {
67            for (unsigned int i = 0; i < length; i++)
68                        {
69                if (XMLString::equals(child->getNamespaceURI(), uriStr) &&
70                    XMLString::equals(child->getLocalName(), elemNames[i]))
71                    return (DOMElement*)child;
72                        }
73                }
74        child = child->getNextSibling();
75    }
76
77    // not found
78    return 0;
79}
80
81// Finds and returns the last child element node.
82DOMElement* XUtil::getNextSiblingElement(const DOMNode* const node)
83{
84    // search for node
85    DOMNode* sibling = node->getNextSibling();
86
87    while (sibling != 0)
88        {
89        if (sibling->getNodeType() == DOMNode::ELEMENT_NODE)
90            return (DOMElement*)sibling;
91
92        sibling = sibling->getNextSibling();
93    }
94
95    // not found
96    return 0;
97}
98
99// Finds and returns the next sibling element node with the give name.
100DOMElement* XUtil::getNextSiblingElementNS(const DOMNode* const node
101                                           , const XMLCh** const elemNames
102                                           , const XMLCh* const uriStr
103                                                                               , unsigned int        length)
104{
105    // search for node
106    DOMNode* sibling = node->getNextSibling();
107    while (sibling != 0)
108        {
109        if (sibling->getNodeType() == DOMNode::ELEMENT_NODE)
110                {
111            for (unsigned int i = 0; i < length; i++)
112                        {
113                if (XMLString::equals(sibling->getNamespaceURI(), uriStr) &&
114                    XMLString::equals(sibling->getLocalName(), elemNames[i]))
115                    return (DOMElement*)sibling;
116                        }
117                }
118        sibling = sibling->getNextSibling();
119    }
120
121    // not found
122    return 0;
123}
124
125XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.