Java XML: Recherche des Noeud frères pour d’un nœud défini

Author:

Java XML: Recherche des Noeud frères pour d'un nœud défini
Download

/***** Code de MesExemples.com *******/
/**
 * @(#)XMLFindSiblingNode.java
 *
 *
 * @author 
 *sakoba(java.mesexemples.com) @version 1.00 2013/7/5
 */
 
import org.w3c.dom.Node;
 
public class XMLFindSiblingNode {
 
  public static Node getPreviousSiblingByName(Node currentNode, String 
    tagName) 
  {
    Node node = currentNode.getPreviousSibling();
 
    while ((node != null) && (!node.getNodeName().equals(tagName))) {
      node = node.getPreviousSibling();
    }
    return node;
  }
 
}

Code testé avec le fichier XML Suivant

<?xml version="1.0" encoding="windows-1252"?>
<!-- Edited by MesEXemple.com -->
<note>
	<to>Sakoba</to>
	<from>Adams</from>
	<heading>Rappel</heading>
	<body>Ne m'oubliez pas ce week-end!</body>
</note>

Cet article Java XML: Recherche des Noeud frères pour d’un nœud défini est apparu en premier sur .