View Javadoc

1   /*
2    * Copyright 2004,2007 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.ws.commons.schema.utils;
18  
19  import org.w3c.dom.Element;
20  import org.w3c.dom.Node;
21  
22  public class XDOMUtil extends DOMUtil {
23  
24      /**
25       * Creates a new instance of XDOMUtil
26       */
27      private XDOMUtil() {
28      }
29  
30      public static Element getFirstChildElementNS(Node parent, String uri) {
31  
32          // search for node
33          Node child = parent.getFirstChild();
34          while (child != null) {
35              if (child.getNodeType() == Node.ELEMENT_NODE) {
36                  String childURI = child.getNamespaceURI();
37                  if (childURI != null && childURI.equals(uri)) {
38                      return (Element) child;
39                  }
40              }
41              child = child.getNextSibling();
42          }
43  
44          // not found
45          return null;
46  
47      }
48  
49      public static Element getNextSiblingElementNS(Node node, String uri) {
50          // search for node
51          Node sibling = node.getNextSibling();
52          while (sibling != null) {
53              if (sibling.getNodeType() == Node.ELEMENT_NODE) {
54                  String siblingURI = sibling.getNamespaceURI();
55                  if (siblingURI != null && siblingURI.equals(uri)) {
56                      return (Element) sibling;
57                  }
58              }
59              sibling = sibling.getNextSibling();
60          }
61  
62          // not found
63          return null;
64  
65      }
66  
67  }