List of usage examples for org.w3c.dom DocumentType getEntities
public NamedNodeMap getEntities();
NamedNodeMap
containing the general entities, both external and internal, declared in the DTD. From source file:TreeDumper2.java
private void dumpDocumentType(DocumentType node, String indent) { System.out.println(indent + "DOCUMENT_TYPE: " + node.getName()); if (node.getPublicId() != null) System.out.println(indent + " Public ID: " + node.getPublicId()); if (node.getSystemId() != null) System.out.println(indent + " System ID: " + node.getSystemId()); NamedNodeMap entities = node.getEntities(); if (entities.getLength() > 0) { for (int i = 0; i < entities.getLength(); i++) { dumpLoop(entities.item(i), indent + " "); }//from w ww. ja v a 2 s . c om } NamedNodeMap notations = node.getNotations(); if (notations.getLength() > 0) { for (int i = 0; i < notations.getLength(); i++) dumpLoop(notations.item(i), indent + " "); } }
From source file:net.sourceforge.pmd.lang.xml.ast.DOMLineNumbers.java
private String unexpandEntities(Node n, String te) { String result = te;//from w ww .j a v a 2s . co m DocumentType doctype = n.getOwnerDocument().getDoctype(); // implicit entities result = result.replaceAll(Matcher.quoteReplacement("&"), "&"); result = result.replaceAll(Matcher.quoteReplacement("<"), "<"); result = result.replaceAll(Matcher.quoteReplacement(">"), ">"); result = result.replaceAll(Matcher.quoteReplacement("\""), """); result = result.replaceAll(Matcher.quoteReplacement("'"), "'"); if (doctype != null) { NamedNodeMap entities = doctype.getEntities(); String internalSubset = doctype.getInternalSubset(); if (internalSubset == null) { internalSubset = ""; } for (int i = 0; i < entities.getLength(); i++) { Node item = entities.item(i); String entityName = item.getNodeName(); Node firstChild = item.getFirstChild(); if (firstChild != null) { result = result.replaceAll(Matcher.quoteReplacement(firstChild.getNodeValue()), "&" + entityName + ";"); } else { Matcher m = Pattern .compile(Matcher.quoteReplacement("<!ENTITY " + entityName + " ") + "[']([^']*)[']>") .matcher(internalSubset); if (m.find()) { result = result.replaceAll(Matcher.quoteReplacement(m.group(1)), "&" + entityName + ";"); } } } } return result; }
From source file:tufts.vue.ds.XMLIngest.java
public static Schema ingestXML(XmlSchema schema, org.xml.sax.InputSource input, String itemKey) { final org.w3c.dom.Document doc = parseXML(input, false); //doc.normalizeDocument(); if (DEBUG.DR) { try {//from w w w . ja v a 2s .co m errout("XML parsed, document built:"); errout("org.w3c.dom.Document: " + Util.tags(doc)); final org.w3c.dom.DocumentType type = doc.getDoctype(); //errout("InputEncoding: " + doc.getInputEncoding()); // AbstractMethodError ? //errout("xmlEncoding: " + doc.getXmlEncoding()); // AbstractMethodError //errout("xmlVersion: " + doc.getXmlVersion()); // AbstractMethodError errout("docType: " + Util.tags(type)); if (type != null) { errout("docType.name: " + Util.tags(type.getName())); errout("docType.entities: " + Util.tags(type.getEntities())); errout("docType.notations: " + Util.tags(type.getNotations())); errout("docType.publicId: " + Util.tags(type.getPublicId())); errout("docType.systemId: " + Util.tags(type.getSystemId())); } errout("impl: " + Util.tags(doc.getImplementation().getClass())); errout("docElement: " + Util.tags(doc.getDocumentElement().getClass())); // toString() can dump whole document! } catch (Throwable t) { Log.error("debug failure", t); } } //out("element: " + Util.tags(doc.getDocumentElement())); //outln("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); //outln("<!-- created by RSSTest " + new Date() + " from " + src + " -->"); if (schema == null) schema = new XmlSchema(tufts.vue.Resource.instance(input), itemKey); else schema.flushData(); if (false) XPathExtract(schema, doc); else scanNode(schema, doc.getDocumentElement(), null, null); if (DEBUG.DR || DEBUG.SCHEMA) schema.dumpSchema(System.err); return schema; }