/***** Code de MesExemples.com *******/ public void edit3(Document doc) { int count; int offset; Element root = doc.getDocumentElement(); Element place = (Element)root.getFirstChild(); Text name = (Text)place.getFirstChild().getFirstChild(); Text directions = (Text)place.getLastChild().getFirstChild(); offset = 7; name.insertData(offset," black"); offset = 5; count = 4; directions.replaceData(offset,count,"right"); } |
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: Editer un texte par insertion et le remplacement* est apparu en premier sur .