String getNamespaceURIOnPath(String nsPrefix) { if (nsDeclarations != null) { for (Map.Entry<String, String> nsEntry : nsDeclarations.entrySet()) { String currName = nsEntry.getKey(); if (currName.equals(nsPrefix) || ("".equals(currName) && nsPrefix == null)) { return nsEntry.getValue(); } } } if (parent != null) { return parent.getNamespaceURIOnPath(nsPrefix); } return null; }
String getNamespaceURIOnPath(String nsPrefix) { if (nsDeclarations != null) { for (Map.Entry<String, String> nsEntry : nsDeclarations.entrySet()) { String currName = nsEntry.getKey(); if (currName.equals(nsPrefix) || ("".equals(currName) && nsPrefix == null)) { return nsEntry.getValue(); } } } if (parent != null) { return parent.getNamespaceURIOnPath(nsPrefix); } return null; }
public Document createDOM(TagNode rootNode) throws ParserConfigurationException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); DOMImplementation impl = builder.getDOMImplementation(); Document document; // // Where a DOCTYPE is supplied in the input, ensure that this is in the output DOM. See issue #27 // if (rootNode.getDocType() != null){ String qualifiedName = rootNode.getDocType().getPart1(); String publicId = rootNode.getDocType().getPublicId(); String systemId = rootNode.getDocType().getSystemId(); DocumentType documentType = impl.createDocumentType(qualifiedName, publicId, systemId); document = impl.createDocument(rootNode.getNamespaceURIOnPath(""), qualifiedName, documentType); } else { document = builder.newDocument(); Element rootElement = document.createElement(rootNode.getName()); document.appendChild(rootElement); } createSubnodes(document, (Element)document.getDocumentElement(), rootNode.getAllChildren()); return document; }
document = impl.createDocument(rootNode.getNamespaceURIOnPath(""), qualifiedName, documentType); } else { document = builder.newDocument();
private void setAttributes(TagNode node, Element element) { for (Map.Entry<String, String> entry : node.getAttributes().entrySet()) { String attrName = entry.getKey(); String attrValue = entry.getValue(); if (escapeXml) { attrValue = Utils.escapeXml(attrValue, props, true); } String attPrefix = Utils.getXmlNSPrefix(attrName); Namespace ns = null; if (attPrefix != null) { attrName = Utils.getXmlName(attrName); if (props.isNamespacesAware()) { String nsURI = node.getNamespaceURIOnPath(attPrefix); if (nsURI == null) { nsURI = attPrefix; } if (!attPrefix.startsWith("xml")) { ns = Namespace.getNamespace(attPrefix, nsURI); } } } if (ns == null) { element.setAttribute(attrName, attrValue); } else { element.setAttribute(attrName, attrValue, ns); } } }
attrName = Utils.getXmlName(attrName); if (props.isNamespacesAware()) { String nsURI = node.getNamespaceURIOnPath(attPrefix); if (nsURI == null) { nsURI = attPrefix;
nsURI = node.getNamespaceURIOnPath(prefix); nsURI = node.getNamespaceURIOnPath(prefix);
nsURI = node.getNamespaceURIOnPath(prefix); nsURI = node.getNamespaceURIOnPath(prefix);
qualifiedName = HTML_QUALIFIED_NAME; document = impl.createDocument(rootNode.getNamespaceURIOnPath(""), qualifiedName, documentType); } else { document = builder.newDocument();