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 // 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/.

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.