1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xerces" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, International
  53. * Business Machines, Inc., http://www.apache.org. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package com.sun.org.apache.xerces.internal.util;
  58. import com.sun.org.apache.xerces.internal.dom.AttrImpl;
  59. import com.sun.org.apache.xerces.internal.dom.DocumentImpl;
  60. import org.w3c.dom.Attr;
  61. import org.w3c.dom.Document;
  62. import org.w3c.dom.DOMException;
  63. import org.w3c.dom.Element;
  64. import org.w3c.dom.NamedNodeMap;
  65. import org.w3c.dom.Node;
  66. /**
  67. * Some useful utility methods.
  68. * This class was modified in Xerces2 with a view to abstracting as
  69. * much as possible away from the representation of the underlying
  70. * parsed structure (i.e., the DOM). This was done so that, if Xerces
  71. * ever adopts an in-memory representation more efficient than the DOM
  72. * (such as a DTM), we should easily be able to convert our schema
  73. * parsing to utilize it.
  74. *
  75. * @version $ID DOMUtil
  76. */
  77. public class DOMUtil {
  78. //
  79. // Constructors
  80. //
  81. /** This class cannot be instantiated. */
  82. protected DOMUtil() {}
  83. //
  84. // Public static methods
  85. //
  86. /**
  87. * Copies the source tree into the specified place in a destination
  88. * tree. The source node and its children are appended as children
  89. * of the destination node.
  90. * <p>
  91. * <em>Note:</em> This is an iterative implementation.
  92. */
  93. public static void copyInto(Node src, Node dest) throws DOMException {
  94. // get node factory
  95. Document factory = dest.getOwnerDocument();
  96. boolean domimpl = factory instanceof DocumentImpl;
  97. // placement variables
  98. Node start = src;
  99. Node parent = src;
  100. Node place = src;
  101. // traverse source tree
  102. while (place != null) {
  103. // copy this node
  104. Node node = null;
  105. int type = place.getNodeType();
  106. switch (type) {
  107. case Node.CDATA_SECTION_NODE: {
  108. node = factory.createCDATASection(place.getNodeValue());
  109. break;
  110. }
  111. case Node.COMMENT_NODE: {
  112. node = factory.createComment(place.getNodeValue());
  113. break;
  114. }
  115. case Node.ELEMENT_NODE: {
  116. Element element = factory.createElement(place.getNodeName());
  117. node = element;
  118. NamedNodeMap attrs = place.getAttributes();
  119. int attrCount = attrs.getLength();
  120. for (int i = 0; i < attrCount; i++) {
  121. Attr attr = (Attr)attrs.item(i);
  122. String attrName = attr.getNodeName();
  123. String attrValue = attr.getNodeValue();
  124. element.setAttribute(attrName, attrValue);
  125. if (domimpl && !attr.getSpecified()) {
  126. ((AttrImpl)element.getAttributeNode(attrName)).setSpecified(false);
  127. }
  128. }
  129. break;
  130. }
  131. case Node.ENTITY_REFERENCE_NODE: {
  132. node = factory.createEntityReference(place.getNodeName());
  133. break;
  134. }
  135. case Node.PROCESSING_INSTRUCTION_NODE: {
  136. node = factory.createProcessingInstruction(place.getNodeName(),
  137. place.getNodeValue());
  138. break;
  139. }
  140. case Node.TEXT_NODE: {
  141. node = factory.createTextNode(place.getNodeValue());
  142. break;
  143. }
  144. default: {
  145. throw new IllegalArgumentException("can't copy node type, "+
  146. type+" ("+
  147. node.getNodeName()+')');
  148. }
  149. }
  150. dest.appendChild(node);
  151. // iterate over children
  152. if (place.hasChildNodes()) {
  153. parent = place;
  154. place = place.getFirstChild();
  155. dest = node;
  156. }
  157. // advance
  158. else {
  159. place = place.getNextSibling();
  160. while (place == null && parent != start) {
  161. place = parent.getNextSibling();
  162. parent = parent.getParentNode();
  163. dest = dest.getParentNode();
  164. }
  165. }
  166. }
  167. } // copyInto(Node,Node)
  168. /** Finds and returns the first child element node. */
  169. public static Element getFirstChildElement(Node parent) {
  170. // search for node
  171. Node child = parent.getFirstChild();
  172. while (child != null) {
  173. if (child.getNodeType() == Node.ELEMENT_NODE) {
  174. return (Element)child;
  175. }
  176. child = child.getNextSibling();
  177. }
  178. // not found
  179. return null;
  180. } // getFirstChildElement(Node):Element
  181. /** Finds and returns the first visible child element node. */
  182. public static Element getFirstVisibleChildElement(Node parent) {
  183. // search for node
  184. Node child = parent.getFirstChild();
  185. while (child != null) {
  186. if (child.getNodeType() == Node.ELEMENT_NODE &&
  187. !isHidden(child)) {
  188. return (Element)child;
  189. }
  190. child = child.getNextSibling();
  191. }
  192. // not found
  193. return null;
  194. } // getFirstChildElement(Node):Element
  195. /** Finds and returns the last child element node. */
  196. public static Element getLastChildElement(Node parent) {
  197. // search for node
  198. Node child = parent.getLastChild();
  199. while (child != null) {
  200. if (child.getNodeType() == Node.ELEMENT_NODE) {
  201. return (Element)child;
  202. }
  203. child = child.getPreviousSibling();
  204. }
  205. // not found
  206. return null;
  207. } // getLastChildElement(Node):Element
  208. /** Finds and returns the last visible child element node. */
  209. public static Element getLastVisibleChildElement(Node parent) {
  210. // search for node
  211. Node child = parent.getLastChild();
  212. while (child != null) {
  213. if (child.getNodeType() == Node.ELEMENT_NODE &&
  214. !isHidden(child)) {
  215. return (Element)child;
  216. }
  217. child = child.getPreviousSibling();
  218. }
  219. // not found
  220. return null;
  221. } // getLastChildElement(Node):Element
  222. /** Finds and returns the next sibling element node. */
  223. public static Element getNextSiblingElement(Node node) {
  224. // search for node
  225. Node sibling = node.getNextSibling();
  226. while (sibling != null) {
  227. if (sibling.getNodeType() == Node.ELEMENT_NODE) {
  228. return (Element)sibling;
  229. }
  230. sibling = sibling.getNextSibling();
  231. }
  232. // not found
  233. return null;
  234. } // getNextSiblingElement(Node):Element
  235. // get next visible (un-hidden) node.
  236. public static Element getNextVisibleSiblingElement(Node node) {
  237. // search for node
  238. Node sibling = node.getNextSibling();
  239. while (sibling != null) {
  240. if (sibling.getNodeType() == Node.ELEMENT_NODE &&
  241. !isHidden(sibling)) {
  242. return (Element)sibling;
  243. }
  244. sibling = sibling.getNextSibling();
  245. }
  246. // not found
  247. return null;
  248. } // getNextSiblingdElement(Node):Element
  249. // set this Node as being hidden
  250. public static void setHidden(Node node) {
  251. if (node instanceof com.sun.org.apache.xerces.internal.impl.xs.opti.NodeImpl)
  252. ((com.sun.org.apache.xerces.internal.impl.xs.opti.NodeImpl)node).setReadOnly(true, false);
  253. else if (node instanceof com.sun.org.apache.xerces.internal.dom.NodeImpl)
  254. ((com.sun.org.apache.xerces.internal.dom.NodeImpl)node).setReadOnly(true, false);
  255. } // setHidden(node):void
  256. // set this Node as being visible
  257. public static void setVisible(Node node) {
  258. if (node instanceof com.sun.org.apache.xerces.internal.impl.xs.opti.NodeImpl)
  259. ((com.sun.org.apache.xerces.internal.impl.xs.opti.NodeImpl)node).setReadOnly(false, false);
  260. else if (node instanceof com.sun.org.apache.xerces.internal.dom.NodeImpl)
  261. ((com.sun.org.apache.xerces.internal.dom.NodeImpl)node).setReadOnly(false, false);
  262. } // setVisible(node):void
  263. // is this node hidden?
  264. public static boolean isHidden(Node node) {
  265. if (node instanceof com.sun.org.apache.xerces.internal.impl.xs.opti.NodeImpl)
  266. return ((com.sun.org.apache.xerces.internal.impl.xs.opti.NodeImpl)node).getReadOnly();
  267. else if (node instanceof com.sun.org.apache.xerces.internal.dom.NodeImpl)
  268. return ((com.sun.org.apache.xerces.internal.dom.NodeImpl)node).getReadOnly();
  269. return false;
  270. } // isHidden(Node):boolean
  271. /** Finds and returns the first child node with the given name. */
  272. public static Element getFirstChildElement(Node parent, String elemName) {
  273. // search for node
  274. Node child = parent.getFirstChild();
  275. while (child != null) {
  276. if (child.getNodeType() == Node.ELEMENT_NODE) {
  277. if (child.getNodeName().equals(elemName)) {
  278. return (Element)child;
  279. }
  280. }
  281. child = child.getNextSibling();
  282. }
  283. // not found
  284. return null;
  285. } // getFirstChildElement(Node,String):Element
  286. /** Finds and returns the last child node with the given name. */
  287. public static Element getLastChildElement(Node parent, String elemName) {
  288. // search for node
  289. Node child = parent.getLastChild();
  290. while (child != null) {
  291. if (child.getNodeType() == Node.ELEMENT_NODE) {
  292. if (child.getNodeName().equals(elemName)) {
  293. return (Element)child;
  294. }
  295. }
  296. child = child.getPreviousSibling();
  297. }
  298. // not found
  299. return null;
  300. } // getLastChildElement(Node,String):Element
  301. /** Finds and returns the next sibling node with the given name. */
  302. public static Element getNextSiblingElement(Node node, String elemName) {
  303. // search for node
  304. Node sibling = node.getNextSibling();
  305. while (sibling != null) {
  306. if (sibling.getNodeType() == Node.ELEMENT_NODE) {
  307. if (sibling.getNodeName().equals(elemName)) {
  308. return (Element)sibling;
  309. }
  310. }
  311. sibling = sibling.getNextSibling();
  312. }
  313. // not found
  314. return null;
  315. } // getNextSiblingdElement(Node,String):Element
  316. /** Finds and returns the first child node with the given qualified name. */
  317. public static Element getFirstChildElementNS(Node parent,
  318. String uri, String localpart) {
  319. // search for node
  320. Node child = parent.getFirstChild();
  321. while (child != null) {
  322. if (child.getNodeType() == Node.ELEMENT_NODE) {
  323. String childURI = child.getNamespaceURI();
  324. if (childURI != null && childURI.equals(uri) &&
  325. child.getLocalName().equals(localpart)) {
  326. return (Element)child;
  327. }
  328. }
  329. child = child.getNextSibling();
  330. }
  331. // not found
  332. return null;
  333. } // getFirstChildElementNS(Node,String,String):Element
  334. /** Finds and returns the last child node with the given qualified name. */
  335. public static Element getLastChildElementNS(Node parent,
  336. String uri, String localpart) {
  337. // search for node
  338. Node child = parent.getLastChild();
  339. while (child != null) {
  340. if (child.getNodeType() == Node.ELEMENT_NODE) {
  341. String childURI = child.getNamespaceURI();
  342. if (childURI != null && childURI.equals(uri) &&
  343. child.getLocalName().equals(localpart)) {
  344. return (Element)child;
  345. }
  346. }
  347. child = child.getPreviousSibling();
  348. }
  349. // not found
  350. return null;
  351. } // getLastChildElementNS(Node,String,String):Element
  352. /** Finds and returns the next sibling node with the given qualified name. */
  353. public static Element getNextSiblingElementNS(Node node,
  354. String uri, String localpart) {
  355. // search for node
  356. Node sibling = node.getNextSibling();
  357. while (sibling != null) {
  358. if (sibling.getNodeType() == Node.ELEMENT_NODE) {
  359. String siblingURI = sibling.getNamespaceURI();
  360. if (siblingURI != null && siblingURI.equals(uri) &&
  361. sibling.getLocalName().equals(localpart)) {
  362. return (Element)sibling;
  363. }
  364. }
  365. sibling = sibling.getNextSibling();
  366. }
  367. // not found
  368. return null;
  369. } // getNextSiblingdElementNS(Node,String,String):Element
  370. /** Finds and returns the first child node with the given name. */
  371. public static Element getFirstChildElement(Node parent, String elemNames[]) {
  372. // search for node
  373. Node child = parent.getFirstChild();
  374. while (child != null) {
  375. if (child.getNodeType() == Node.ELEMENT_NODE) {
  376. for (int i = 0; i < elemNames.length; i++) {
  377. if (child.getNodeName().equals(elemNames[i])) {
  378. return (Element)child;
  379. }
  380. }
  381. }
  382. child = child.getNextSibling();
  383. }
  384. // not found
  385. return null;
  386. } // getFirstChildElement(Node,String[]):Element
  387. /** Finds and returns the last child node with the given name. */
  388. public static Element getLastChildElement(Node parent, String elemNames[]) {
  389. // search for node
  390. Node child = parent.getLastChild();
  391. while (child != null) {
  392. if (child.getNodeType() == Node.ELEMENT_NODE) {
  393. for (int i = 0; i < elemNames.length; i++) {
  394. if (child.getNodeName().equals(elemNames[i])) {
  395. return (Element)child;
  396. }
  397. }
  398. }
  399. child = child.getPreviousSibling();
  400. }
  401. // not found
  402. return null;
  403. } // getLastChildElement(Node,String[]):Element
  404. /** Finds and returns the next sibling node with the given name. */
  405. public static Element getNextSiblingElement(Node node, String elemNames[]) {
  406. // search for node
  407. Node sibling = node.getNextSibling();
  408. while (sibling != null) {
  409. if (sibling.getNodeType() == Node.ELEMENT_NODE) {
  410. for (int i = 0; i < elemNames.length; i++) {
  411. if (sibling.getNodeName().equals(elemNames[i])) {
  412. return (Element)sibling;
  413. }
  414. }
  415. }
  416. sibling = sibling.getNextSibling();
  417. }
  418. // not found
  419. return null;
  420. } // getNextSiblingdElement(Node,String[]):Element
  421. /** Finds and returns the first child node with the given qualified name. */
  422. public static Element getFirstChildElementNS(Node parent,
  423. String[][] elemNames) {
  424. // search for node
  425. Node child = parent.getFirstChild();
  426. while (child != null) {
  427. if (child.getNodeType() == Node.ELEMENT_NODE) {
  428. for (int i = 0; i < elemNames.length; i++) {
  429. String uri = child.getNamespaceURI();
  430. if (uri != null && uri.equals(elemNames[i][0]) &&
  431. child.getLocalName().equals(elemNames[i][1])) {
  432. return (Element)child;
  433. }
  434. }
  435. }
  436. child = child.getNextSibling();
  437. }
  438. // not found
  439. return null;
  440. } // getFirstChildElementNS(Node,String[][]):Element
  441. /** Finds and returns the last child node with the given qualified name. */
  442. public static Element getLastChildElementNS(Node parent,
  443. String[][] elemNames) {
  444. // search for node
  445. Node child = parent.getLastChild();
  446. while (child != null) {
  447. if (child.getNodeType() == Node.ELEMENT_NODE) {
  448. for (int i = 0; i < elemNames.length; i++) {
  449. String uri = child.getNamespaceURI();
  450. if (uri != null && uri.equals(elemNames[i][0]) &&
  451. child.getLocalName().equals(elemNames[i][1])) {
  452. return (Element)child;
  453. }
  454. }
  455. }
  456. child = child.getPreviousSibling();
  457. }
  458. // not found
  459. return null;
  460. } // getLastChildElementNS(Node,String[][]):Element
  461. /** Finds and returns the next sibling node with the given qualified name. */
  462. public static Element getNextSiblingElementNS(Node node,
  463. String[][] elemNames) {
  464. // search for node
  465. Node sibling = node.getNextSibling();
  466. while (sibling != null) {
  467. if (sibling.getNodeType() == Node.ELEMENT_NODE) {
  468. for (int i = 0; i < elemNames.length; i++) {
  469. String uri = sibling.getNamespaceURI();
  470. if (uri != null && uri.equals(elemNames[i][0]) &&
  471. sibling.getLocalName().equals(elemNames[i][1])) {
  472. return (Element)sibling;
  473. }
  474. }
  475. }
  476. sibling = sibling.getNextSibling();
  477. }
  478. // not found
  479. return null;
  480. } // getNextSiblingdElementNS(Node,String[][]):Element
  481. /**
  482. * Finds and returns the first child node with the given name and
  483. * attribute name, value pair.
  484. */
  485. public static Element getFirstChildElement(Node parent,
  486. String elemName,
  487. String attrName,
  488. String attrValue) {
  489. // search for node
  490. Node child = parent.getFirstChild();
  491. while (child != null) {
  492. if (child.getNodeType() == Node.ELEMENT_NODE) {
  493. Element element = (Element)child;
  494. if (element.getNodeName().equals(elemName) &&
  495. element.getAttribute(attrName).equals(attrValue)) {
  496. return element;
  497. }
  498. }
  499. child = child.getNextSibling();
  500. }
  501. // not found
  502. return null;
  503. } // getFirstChildElement(Node,String,String,String):Element
  504. /**
  505. * Finds and returns the last child node with the given name and
  506. * attribute name, value pair.
  507. */
  508. public static Element getLastChildElement(Node parent,
  509. String elemName,
  510. String attrName,
  511. String attrValue) {
  512. // search for node
  513. Node child = parent.getLastChild();
  514. while (child != null) {
  515. if (child.getNodeType() == Node.ELEMENT_NODE) {
  516. Element element = (Element)child;
  517. if (element.getNodeName().equals(elemName) &&
  518. element.getAttribute(attrName).equals(attrValue)) {
  519. return element;
  520. }
  521. }
  522. child = child.getPreviousSibling();
  523. }
  524. // not found
  525. return null;
  526. } // getLastChildElement(Node,String,String,String):Element
  527. /**
  528. * Finds and returns the next sibling node with the given name and
  529. * attribute name, value pair. Since only elements have attributes,
  530. * the node returned will be of type Node.ELEMENT_NODE.
  531. */
  532. public static Element getNextSiblingElement(Node node,
  533. String elemName,
  534. String attrName,
  535. String attrValue) {
  536. // search for node
  537. Node sibling = node.getNextSibling();
  538. while (sibling != null) {
  539. if (sibling.getNodeType() == Node.ELEMENT_NODE) {
  540. Element element = (Element)sibling;
  541. if (element.getNodeName().equals(elemName) &&
  542. element.getAttribute(attrName).equals(attrValue)) {
  543. return element;
  544. }
  545. }
  546. sibling = sibling.getNextSibling();
  547. }
  548. // not found
  549. return null;
  550. } // getNextSiblingElement(Node,String,String,String):Element
  551. /**
  552. * Returns the concatenated child text of the specified node.
  553. * This method only looks at the immediate children of type
  554. * <code>Node.TEXT_NODE</code> or the children of any child
  555. * node that is of type <code>Node.CDATA_SECTION_NODE</code>
  556. * for the concatenation.
  557. *
  558. * @param node The node to look at.
  559. */
  560. public static String getChildText(Node node) {
  561. // is there anything to do?
  562. if (node == null) {
  563. return null;
  564. }
  565. // concatenate children text
  566. StringBuffer str = new StringBuffer();
  567. Node child = node.getFirstChild();
  568. while (child != null) {
  569. short type = child.getNodeType();
  570. if (type == Node.TEXT_NODE) {
  571. str.append(child.getNodeValue());
  572. }
  573. else if (type == Node.CDATA_SECTION_NODE) {
  574. str.append(getChildText(child));
  575. }
  576. child = child.getNextSibling();
  577. }
  578. // return text value
  579. return str.toString();
  580. } // getChildText(Node):String
  581. // return the name of this element
  582. public static String getName(Node node) {
  583. return node.getNodeName();
  584. } // getLocalName(Element): String
  585. /** returns local name of this element if not null, otherwise
  586. returns the name of the node
  587. */
  588. public static String getLocalName(Node node) {
  589. String name = node.getLocalName();
  590. return (name!=null)? name:node.getNodeName();
  591. } // getLocalName(Element): String
  592. public static Element getParent(Element elem) {
  593. Node parent = elem.getParentNode();
  594. if (parent instanceof Element)
  595. return (Element)parent;
  596. return null;
  597. } // getParent(Element):Element
  598. // get the Document of which this Node is a part
  599. public static Document getDocument(Node node) {
  600. return node.getOwnerDocument();
  601. } // getDocument(Node):Document
  602. // return this Document's root node
  603. public static Element getRoot(Document doc) {
  604. return doc.getDocumentElement();
  605. } // getRoot(Document(: Element
  606. // some methods for handling attributes:
  607. // return the right attribute node
  608. public static Attr getAttr(Element elem, String name) {
  609. return elem.getAttributeNode(name);
  610. } // getAttr(Element, String):Attr
  611. // return the right attribute node
  612. public static Attr getAttrNS(Element elem, String nsUri,
  613. String localName) {
  614. return elem.getAttributeNodeNS(nsUri, localName);
  615. } // getAttrNS(Element, String):Attr
  616. // get all the attributes for an Element
  617. public static Attr[] getAttrs(Element elem) {
  618. NamedNodeMap attrMap = elem.getAttributes();
  619. Attr [] attrArray = new Attr[attrMap.getLength()];
  620. for (int i=0; i<attrMap.getLength(); i++)
  621. attrArray[i] = (Attr)attrMap.item(i);
  622. return attrArray;
  623. } // getAttrs(Element): Attr[]
  624. // get attribute's value
  625. public static String getValue(Attr attribute) {
  626. return attribute.getValue();
  627. } // getValue(Attr):String
  628. // It is noteworthy that, because of the way the DOM specs
  629. // work, the next two methods return the empty string (not
  630. // null!) when the attribute with the specified name does not
  631. // exist on an element. Beware!
  632. // return the value of the attribute of the given element
  633. // with the given name
  634. public static String getAttrValue(Element elem, String name) {
  635. return elem.getAttribute(name);
  636. } // getAttr(Element, String):Attr
  637. // return the value of the attribute of the given element
  638. // with the given name
  639. public static String getAttrValueNS(Element elem, String nsUri,
  640. String localName) {
  641. return elem.getAttributeNS(nsUri, localName);
  642. } // getAttrValueNS(Element, String):Attr
  643. // return the namespace URI
  644. public static String getNamespaceURI(Node node) {
  645. return node.getNamespaceURI();
  646. }
  647. } // class XUtil