Java HTML / XML How to - Get Notations in a DOM Document


We would like to know how to get Notations in a DOM Document.


   /*w w  w.  j av  a  2 s .  c o m*/

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Notation;
import org.xml.sax.InputSource;

public class Main {
  public static String getXMLData(){
    return "your data";
  public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    Document doc = factory.newDocumentBuilder().parse(new InputSource(new StringReader(getXMLData())));

    NamedNodeMap notations = doc.getDoctype().getNotations();
    for (int i = 0; i < notations.getLength(); i++) {
      Notation notation = (Notation) notations.item(i);

      String notationName = notation.getNodeName();
      String notationPublicId = notation.getPublicId();
      String notationSystemId = notation.getSystemId();