public W3CDOMStreamWriter(Element e) { this.document = e.getOwnerDocument(); currentNode = e; W3CNamespaceContext newContext = new W3CNamespaceContext(); newContext.setElement(currentNode); this.context = newContext; }
public String getNamespaceURI(String prefix) { String name = prefix; if (name.length() == 0) { name = "xmlns"; } else { name = "xmlns:" + prefix; } return getNamespaceURI(currentNode, name); }
public String getPrefix(String uri) { return getPrefix(currentNode, uri); }
public void writeEndElement() throws XMLStreamException { if (stack.size() > 0) { currentNode = (Element)stack.pop(); } else { currentNode = null; } ((W3CNamespaceContext)context).setElement(currentNode); }
private void newChild(Element element) { if (currentNode != null) { stack.push(currentNode); currentNode.appendChild(element); } else { document.appendChild(element); } W3CNamespaceContext newContext = new W3CNamespaceContext(); newContext.setElement(element); this.context = newContext; currentNode = element; }
public Iterator getPrefixes(String uri) { List<String> prefixes = new ArrayList<String>(); String prefix = getPrefix(uri); if (prefix != null) { prefixes.add(prefix); } return prefixes.iterator(); }
private String getNamespaceURI(Element e, String name) { Attr attr = e.getAttributeNode(name); if (attr == null) { Node n = e.getParentNode(); if (n instanceof Element && n != e) { return getNamespaceURI((Element)n, name); } } else { return attr.getValue(); } return null; }
private String getPrefix(Element e, String uri) { NamedNodeMap attributes = e.getAttributes(); if (attributes != null) { for (int i = 0; i < attributes.getLength(); i++) { Attr a = (Attr)attributes.item(i); String val = a.getValue(); if (val != null && val.equals(uri)) { String name = a.getNodeName(); if ("xmlns".equals(name)) { return ""; } else { return name.substring(6); } } } } Node n = e.getParentNode(); if (n instanceof Element && n != e) { return getPrefix((Element)n, uri); } return null; }