Here you can find the source of getNode(Node iNode, String iNodeName)
Parameter | Description |
---|---|
iNode | The provided node structure to be traversed. |
iNodeName | The name of the node being searched for. |
public static Node getNode(Node iNode, String iNodeName)
//package com.java2s; /******************************************************************************* ADL SCORM 2004 4th Edition Sample Run-Time Environment The ADL SCORM 2004 4th Ed. Sample Run-Time Environment is licensed under Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States. The Advanced Distributed Learning Initiative allows you to: * Share - to copy, distribute and transmit the work. * Remix - to adapt the work. //ww w . j ava 2 s .c om Under the following conditions: * Attribution. You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work). * Noncommercial. You may not use this work for commercial purposes. * Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one. For any reuse or distribution, you must make clear to others the license terms of this work. Any of the above conditions can be waived if you get permission from the ADL Initiative. Nothing in this license impairs or restricts the author's moral rights. *******************************************************************************/ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import java.util.logging.Logger; public class Main { /** * This method returns the desired node which is determined by the * provided node name and namespace. * * @param iNode The provided node structure to be traversed. * @param iNodeName The name of the node being searched for. * * @return Returns the desired node. */ public static Node getNode(Node iNode, String iNodeName) { Logger.getLogger("org.adl.util.debug.samplerte").entering( "DOMTreeUtility", "getNode()"); Logger.getLogger("org.adl.util.debug.samplerte").info( "Parent Node: " + iNode.getLocalName()); Logger.getLogger("org.adl.util.debug.samplerte").info( "Node being searched for: " + iNodeName); Node result = null; if (iNode != null) { // Get the children of the current node NodeList children = iNode.getChildNodes(); // If there are children, loop through the children nodes looking // for the appropriate node if (children != null) { for (int i = 0; i < children.getLength(); i++) { // Get the child node Node currentChild = children.item(i); // Get the current child node's local name String currentChildName = currentChild.getLocalName(); Logger.getLogger("org.adl.util.debug.samplerte").info( "Child #" + i + ": " + currentChildName); if (currentChildName != null) { // Determine if the current child node is the one that // is being looked for if (currentChildName.equalsIgnoreCase(iNodeName)) { result = currentChild; break; } } } // end looping of children } } // return the resulting vector of nodes return result; } }