The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > org.w3c.dom  [30 examples] > Getting Nodes  [5 examples]

e528. Getting the Notations in a DOM Document

The notations declared in the DTD of an XML document are available in the DocumentType object of a DOM document.
    // Obtain a document; the following method is implemented in
    // e510 The Quintessential Program to Create a DOM Document from an XML File
    Document doc = parseXmlFile("infilename.xml", false);
    
    // Get list of notations
    NamedNodeMap notations = doc.getDoctype().getNotations();
    for (int i=0; i<notations.getLength(); i++) {
        // Get notation node
        Notation notation = (Notation)notations.item(i);
    
        // Get details in notation node
        String notationName = notation.getNodeName();
        String notationPublicId = notation.getPublicId();
        String notationSystemId = notation.getSystemId();
    }
This is the sample input for the example:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE root [
        <!NOTATION not1 PUBLIC "publicId" "systemId1">
        <!NOTATION not2 SYSTEM "systemId2">
        <!NOTATION not3 SYSTEM "http://hostname.com/systemid">
        <!NOTATION not4 SYSTEM "">
    ]>
    <root>
    </root>
This is the data in the Notation nodes from the above input file. Note that the system ids are converted to absolute URIs.
    Name, PublicId, SystemId
    
    not1, publicId, file:D:/almanac/1.4/egs/org.w3c.dom/systemId1
    not2, null,     file:D:/almanac/1.4/egs/org.w3c.dom/systemId2
    not3, null,     http://hostname.com/systemid
    not4, null,     file:D:/almanac/1.4/egs/org.w3c.dom/.

 Related Examples
e1073. Getting the Root Element in a DOM Document
e527. Getting a Node Relative to Another Node in a DOM Document
e529. Getting the Declared Entities in a DOM Document
e530. Getting the Value of an Entity Reference in a DOM Document

See also: Adding and Removing Nodes    Element Attributes    Elements    Text Nodes    XPath   


© 2002 Addison-Wesley.