Coverage Report

Created: 2025-06-13 07:02

/src/xerces-c/src/xercesc/validators/schema/XUtil.cpp
Line
Count
Source (jump to first uncovered 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 <xercesc/util/XMLString.hpp>
28
#include <xercesc/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
35
XERCES_CPP_NAMESPACE_BEGIN
36
37
// Finds and returns the first child element node.
38
DOMElement* XUtil::getFirstChildElement(const DOMNode* const parent)
39
0
{
40
    // search for node
41
0
    DOMNode* child = parent->getFirstChild();
42
43
0
    while (child != 0)
44
0
  {
45
0
        if (child->getNodeType() == DOMNode::ELEMENT_NODE)
46
0
            return (DOMElement*)child;
47
48
0
        child = child->getNextSibling();
49
0
    }
50
51
    // not found
52
0
    return 0;
53
0
}
54
55
// Finds and returns the first child node with the given name.
56
DOMElement* XUtil::getFirstChildElementNS(const DOMNode* const parent
57
                                          , const XMLCh** const elemNames
58
                                          , const XMLCh* const uriStr
59
                                          , unsigned int        length)
60
0
{
61
    // search for node
62
0
    DOMNode* child = parent->getFirstChild();
63
0
    while (child != 0)
64
0
  {
65
0
        if (child->getNodeType() == DOMNode::ELEMENT_NODE)
66
0
    {
67
0
            for (unsigned int i = 0; i < length; i++)
68
0
      {
69
0
                if (XMLString::equals(child->getNamespaceURI(), uriStr) &&
70
0
                    XMLString::equals(child->getLocalName(), elemNames[i]))
71
0
                    return (DOMElement*)child;
72
0
      }
73
0
    }
74
0
        child = child->getNextSibling();
75
0
    }
76
77
    // not found
78
0
    return 0;
79
0
}
80
81
// Finds and returns the last child element node.
82
DOMElement* XUtil::getNextSiblingElement(const DOMNode* const node)
83
0
{
84
    // search for node
85
0
    DOMNode* sibling = node->getNextSibling();
86
87
0
    while (sibling != 0)
88
0
  {
89
0
        if (sibling->getNodeType() == DOMNode::ELEMENT_NODE)
90
0
            return (DOMElement*)sibling;
91
92
0
        sibling = sibling->getNextSibling();
93
0
    }
94
95
    // not found
96
0
    return 0;
97
0
}
98
99
// Finds and returns the next sibling element node with the give name.
100
DOMElement* XUtil::getNextSiblingElementNS(const DOMNode* const node
101
                                           , const XMLCh** const elemNames
102
                                           , const XMLCh* const uriStr
103
                         , unsigned int        length)
104
0
{
105
    // search for node
106
0
    DOMNode* sibling = node->getNextSibling();
107
0
    while (sibling != 0)
108
0
  {
109
0
        if (sibling->getNodeType() == DOMNode::ELEMENT_NODE)
110
0
    {
111
0
            for (unsigned int i = 0; i < length; i++)
112
0
      {
113
0
                if (XMLString::equals(sibling->getNamespaceURI(), uriStr) &&
114
0
                    XMLString::equals(sibling->getLocalName(), elemNames[i]))
115
0
                    return (DOMElement*)sibling;
116
0
      }
117
0
    }
118
0
        sibling = sibling->getNextSibling();
119
0
    }
120
121
    // not found
122
0
    return 0;
123
0
}
124
125
XERCES_CPP_NAMESPACE_END