Java XML: Modifier un attribut

Author:

Java: Modifier un attribut
Download

/***** 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 org.w3c.dom.Node;
 
 
public class SetAttributes
  {
  public static void setAttribute(Node noeud, String nom_attribut, String val) 
    {
    NamedNodeMap attributes = noeud.getAttributes();
    Node attNode = noeud.getOwnerDocument().createAttribute(nom_attribut);
    attNode.setNodeValue(val);
    attributes.setNamedItem(attNode);
   }
}

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: Modifier un attribut est apparu en premier sur .