/***** Code de MesExemples.com *******/ /** * @(#)XMLNExtElement.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/7/5 */ import javax.xml.namespace.QName; import org.w3c.dom.Element; import org.w3c.dom.Node; public class XMLNExtElement { public static Element getNextElement(Element el) { Node noeud = el.getNextSibling(); while (noeud != null) { if (noeud.getNodeType() == Node.ELEMENT_NODE) { return (Element)noeud; } noeud = noeud.getNextSibling(); } return null; } } |
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> |
A Voir sur le même Sujet
-
Java: Java XML: Obtenir l’élément suivant de même parent
{filelink=8452} /***** Code de MesExemples.com *******/ /** * @(#)XMLNExtSiblingElement.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/7/5 */ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public …
-
Java: Obtenir les attributs d’un Noeud
{filelink=8355} /***** Code de MesExemples.com *******/ /** * @(#)ExempleAttributNoeud.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/7/4 */ import org.w3c.dom.Attr; import org.w3c.dom.Element; public class ExempleAttributNoeud …
-
Java: Clôner un noeud fils
{filelink=8393} /***** Code de MesExemples.com *******/ public void duplicatePerson(Document doc) { Element root = doc.getDocumentElement(); Element origPerson = (Element)root.getFirstChild(); Element newPerson = (Element)origPerson.cloneNode(true); root.appendChild(newPerson); } Code testé avec le fichier XML Suivant Sakoba Adams Rappel Ne m’oubliez pas ce week-end!
-
Java: Clôner un noeud fils
{filelink=8393} /***** Code de MesExemples.com *******/ public void duplicatePerson(Document doc) { Element root = doc.getDocumentElement(); Element origPerson = (Element)root.getFirstChild(); Element newPerson = (Element)origPerson.cloneNode(true); root.appendChild(newPerson); } Code testé avec le fichier XML Suivant Sakoba Adams Rappel Ne m’oubliez pas ce week-end!
-
Java XML: Ajouter un nouvel élément sous un noeud parent
{filelink=8419} /***** Code de MesExemples.com *******/ import org.w3c.dom.Document;import org.w3c.dom.Element;public class ExempleXMLNewElem { public static Element createElement(Element parent, String name) { Document document; Element element; document = parent.getOwnerDocument(); element = document.createElement(name); parent.appendChild(element); return element; }} Code testé avec le fichier XML Suivant Sakoba Adams Rappel Ne m’oubliez pas ce week-end!
-
Java: Modifier un attribut
{filelink=8358} /***** Code de MesExemples.com *******/ /** * @(#)SetAttributes.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/7/4 */ import javax.xml.namespace.QName; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import …
-
Java XML: Modifier un attribut
{filelink=8358} /***** Code de MesExemples.com *******/ /** * @(#)SetAttributes.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/7/4 */ import javax.xml.namespace.QName; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import …
-
Java: Insérer un commentaire au début de l’élément noeud
{filelink=8345} /***** Code de MesExemples.com *******/ /** * @(#)InsertComment.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/7/4 */ import java.io.File; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Comment; import …
-
Java XML: Recherche des Noeud frères pour d’un nœud défini
{filelink=8559} /***** 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 …
-
Java XML: Effacer le texte d’un Noeud
{filelink=8422} /***** Code de MesExemples.com *******/ /** * @(#)XMLCleanNodeText.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/7/4 */ import java.util.Vector; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import …
-
Java XML: Retourner le texte concaténé de l’enfant d’un noeud spécifique
{filelink=8553} /***** Code de MesExemples.com *******/ import org.w3c.dom.Element;import org.w3c.dom.Node;/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the “License”); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an “AS IS” BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */public class Main { /** * Returns the concatenated child text of the specified node. * This method only looks at the immediate children of type * Node.TEXT_NODE or the children of any child * node that is of type Node.CDATA_SECTION_NODE * for the concatenation. * * @param node The node to look at. */ public static String getChildText(Node node) { // is there anything to do? if (node == null) { return null; } // concatenate children text StringBuffer str = new StringBuffer(); Node child = node.getFirstChild(); while (child != null) { short type = child.getNodeType(); if (type == Node.TEXT_NODE) { str.append(child.getNodeValue()); } else if (type == Node.CDATA_SECTION_NODE) { str.append(getChildText(child)); } child = child.getNextSibling(); } // return text value return str.toString(); } // getChildText(Node):String} Code testé avec le fichier XML Suivant Sakoba Adams Rappel Ne m’oubliez pas ce week-end!
-
Java XML: Accéder aux Enfants d’un noeud défini
{filelink=8446} /***** Code de MesExemples.com *******/ /** * @(#)XMLChildFromNodeName.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/7/5 */ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public …
-
Java: Obtenir le CData d’un document XML*
{filelink=8340} /***** Code de MesExemples.com *******/ /** * @(#)ListeNoeud.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/7/4 */ import java.io.File; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import …
-
Java: Localiser un nœud et Modifier son contenu
{filelink=8388} /***** Code de MesExemples.com *******/ /** * @(#)XMLUpdateNode.java * * * @author *sakoba(java.mesexemples.com) @version 1.00 2013/7/4 */ import org.w3c.dom.Comment; import org.w3c.dom.Document; import org.w3c.dom.Element; import …
-
Javascript: Obtenir le nombre de point d’ancrage d’une page
{filelink=3343} Ancrage document.anchors function suivantAnchor(where) { window.location.hash = where } Haut section 1 section 2 section 3 document.write(“Nombre d’ancrage: ” + document.anchors.length)
Cet article Java XML: Accéder à l’élément suivant d’un noeud est apparu en premier sur .