List of usage examples for org.w3c.dom Document getDoctype
public DocumentType getDoctype();
DocumentType
) associated with this document. From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);/*w w w. ja va 2 s.c om*/ factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); 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(); } }
From source file:Main.java
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(); System.out.println(notationName); String notationPublicId = notation.getPublicId(); String notationSystemId = notation.getSystemId(); }/*from w ww . ja v a 2 s.co m*/ }
From source file:TryDOM.java
public static void main(String args[]) throws Exception { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setNamespaceAware(true); builderFactory.setValidating(true); builderFactory.setIgnoringElementContentWhitespace(true); DocumentBuilder builder = null; builder = builderFactory.newDocumentBuilder(); builder.setErrorHandler(new TryDOM()); Document xmlDoc = builder.parse(new File("y.xml")); DocumentType doctype = xmlDoc.getDoctype(); System.out.println("DOCTYPE node:\n" + getDoctypeString(doctype)); listNodes(xmlDoc.getDocumentElement(), ""); }/*from w w w. ja v a2 s . co m*/
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true);/*ww w .ja va2 s . co m*/ factory.setExpandEntityReferences(false); Document doc = factory.newDocumentBuilder().parse(new File("filename")); Map entityValues = new HashMap(); getEntityValues(doc, entityValues); NamedNodeMap entities = doc.getDoctype().getEntities(); for (int i = 0; i < entities.getLength(); i++) { Entity entity = (Entity) entities.item(i); System.out.println(entity); String entityName = entity.getNodeName(); System.out.println(entityName); String entityPublicId = entity.getPublicId(); System.out.println(entityPublicId); String entitySystemId = entity.getSystemId(); System.out.println(entitySystemId); Node entityValue = (Node) entityValues.get(entityName); System.out.println(entityValue); } }
From source file:Main.java
public static void main(String[] argv) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document doc = factory.newDocumentBuilder().parse(new InputSource(new StringReader(getXMLData()))); Map entityValues = new HashMap(); getEntityValues(doc, entityValues);/*from w w w. j ava 2 s . c o m*/ NamedNodeMap entities = doc.getDoctype().getEntities(); for (int i = 0; i < entities.getLength(); i++) { Entity entity = (Entity) entities.item(i); System.out.println(entity); String entityName = entity.getNodeName(); System.out.println(entityName); String entityPublicId = entity.getPublicId(); System.out.println(entityPublicId); String entitySystemId = entity.getSystemId(); System.out.println(entitySystemId); Node entityValue = (Node) entityValues.get(entityName); System.out.println(entityValue); } }
From source file:Main.java
public static void main(String args[]) { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setNamespaceAware(true); // Set namespace aware builderFactory.setValidating(true); // and validating parser feaures builderFactory.setIgnoringElementContentWhitespace(true); DocumentBuilder builder = null; try {/*from w w w.j av a 2s. com*/ builder = builderFactory.newDocumentBuilder(); // Create the parser } catch (ParserConfigurationException e) { e.printStackTrace(); } Document xmlDoc = null; try { xmlDoc = builder.parse(new InputSource(new StringReader(xmlString))); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } DocumentType doctype = xmlDoc.getDoctype(); if (doctype == null) { System.out.println("DOCTYPE is null"); } else { System.out.println("DOCTYPE node:\n" + doctype.getInternalSubset()); } System.out.println("\nDocument body contents are:"); listNodes(xmlDoc.getDocumentElement(), ""); // Root element & children }
From source file:MainClass.java
public static void main(String args[]) { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setValidating(true); // and validating parser feaures builderFactory.setIgnoringElementContentWhitespace(true); DocumentBuilder builder = null; try {/*from ww w . ja va2 s .co m*/ builder = builderFactory.newDocumentBuilder(); // Create the parser } catch (ParserConfigurationException e) { e.printStackTrace(); } Document xmlDoc = null; try { xmlDoc = builder.parse(new InputSource(new StringReader(xmlString))); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } DocumentType doctype = xmlDoc.getDoctype(); if (doctype == null) { System.out.println("DOCTYPE is null"); } else { System.out.println("DOCTYPE node:\n" + doctype.getInternalSubset()); } System.out.println("\nDocument body contents are:"); listNodes(xmlDoc.getDocumentElement(), ""); // Root element & children }
From source file:Main.java
public static boolean checkDocumentType(Document document, String dtdPublicId) { DocumentType documentType = document.getDoctype(); if (documentType != null) { String publicId = documentType.getPublicId(); return publicId != null && publicId.equals(dtdPublicId); }//from w ww .j a va 2s .c o m return true; // Workaround until DTDs are published // return false; }
From source file:Main.java
public static boolean checkDocumentType(Document document, String dtdPublicId) { DocumentType documentType = document.getDoctype(); if (documentType != null) { String publicId = documentType.getPublicId(); return publicId != null && publicId.equals(dtdPublicId); }/*from w w w. j av a 2 s . c o m*/ // System.err.println("Can't check document type: " + dtdPublicId); return true; // false; Due to problem of IdentityTransformer not creating the DocType nodes }
From source file:Main.java
/**returns the type of document represented * @param d document to get the type of/*from w w w . j a v a 2 s .c om*/ * @return string representing type of document*/ static public String getDocumentType(Document d) throws Exception { if (d == null) throw new Exception(); else return (d.getDoctype().getName()); }