/***** Code de MesExemples.com *******/ public void addComment(Document doc) { Element root = doc.getDocumentElement(); Element folks = (Element)root.getLastChild(); Comment comment = doc.createComment("Texte de commentaire"); root.insertBefore(comment,folks); } // Instruction public void addProcessingInstruction(Document doc) { Element root = doc.getDocumentElement(); Element folks = (Element)root.getLastChild(); ProcessingInstruction pi; pi = (ProcessingInstruction)doc.createProcessingInstruction( "validate", "phone="lookup""); root.insertBefore(pi,folks); } |
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: Exemple d’utilisation des méthodes ‘createComment’ et ‘createProcessingInstruction’ pour insérer des commentaires et des instructions de traitément est apparu en premier sur .