Java: Comment ignorer les commentaires pendant la lecture d’un fichier XML

Author:

Java: Comment ignorer les commentaires pendant la lecture d'un fichier XML
Download

/***** Code de MesExemples.com *******/
/**
 * @(#)IgnorerCommentaire.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.Document;
 
public class IgnorerCommentaire {
  public static void main(String[] argv) throws Exception{
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// Ignrer les commentaires
    factory.setIgnoringComments(true);
    Document doc = factory.newDocumentBuilder().parse(new 
    File("filename.xml"));
 
  }
}

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: Comment ignorer les commentaires pendant la lecture d’un fichier XML est apparu en premier sur .