protected Node replaceNamespace(Node node, String oldNS, String newNS) { if (node instanceof Element) { String ns = getNamespaceURI(node); if (ns != null && ns.equals(oldNS)) { Namespace namespace = ((Element) node).getNamespace(); if (namespace != null) { if (namespace.getURI() != null && namespace.getURI().equals(oldNS)) { ((Element) node).setNamespace(new Namespace(namespace.getPrefix(), newNS)); } } for (Attribute attr : ((Element) node).getAttributes()) { if (attr.getName().startsWith("xmlns")) { String value = attr.getValue(); if (value != null && value.equals(oldNS)) { attr.setValue(newNS); } } } } } if (node instanceof NodeWithChildren) { for (Node n : ((NodeWithChildren) node).getNodes()) { replaceNamespace(n, oldNS, newNS); } } return node; }
public void addNamespace (Namespace ns) { map.put (ns.getPrefix (), ns); }
List<Node> sessions = nodesByNamespace(doc, droolsNamespace.getURI(), "ksession"); if (sessions != null) { for (Node session : sessions) {
namespaces.addNamespace (new Namespace (name.substring (Namespace.NS_PREFIX.length ()), a.getValue ()));
@Override public boolean matches (Node n) { if (!isElement (n)) return false; Element e = (Element)n; boolean match = true; if (match && name != null && !e.getName ().equals (name)) match = false; if (match && ns != null && !ns.equals (getNamespace ())) match = false; return match; } };
protected Node replaceNamespace(Node node, String oldNS, String newNS) { if (node instanceof Element) { String ns = getNamespaceURI(node); if (ns != null && ns.equals(oldNS)) { Namespace namespace = ((Element) node).getNamespace(); if (namespace != null) { if (namespace.getURI() != null && namespace.getURI().equals(oldNS)) { ((Element) node).setNamespace(new Namespace(namespace.getPrefix(), newNS)); } } for (Attribute attr : ((Element) node).getAttributes()) { if (attr.getName().startsWith("xmlns")) { String value = attr.getValue(); if (value != null && value.equals(oldNS)) { attr.setValue(newNS); } } } } } if (node instanceof NodeWithChildren) { for (Node n : ((NodeWithChildren) node).getNodes()) { replaceNamespace(n, oldNS, newNS); } } return node; }
List<Node> sessions = nodesByNamespace(doc, droolsNamespace.getURI(), "ksession"); if (sessions != null) { for (Node session: sessions) {
public static String getNamespaceURI(Node node) { if (node instanceof Element) { Namespace ns = ((Element) node).getNamespace(); if (ns != null) { String uri = ns.getURI(); if (uri == null || uri.length() == 0) { String uriAttr = ns.getPrefix().equals("") ? ((Element) node).getAttributeValue("xmlns") : null; if (uriAttr != null) { return uriAttr; } else { return getNamespaceURI(((Element) node).getParent()); } } else { return uri; } } } return null; }
public static String getNamespaceURI(Node node) { if (node instanceof Element) { Namespace ns = ((Element) node).getNamespace(); if (ns != null) { String uri = ns.getURI(); if (uri == null || uri.length() == 0) { String uriAttr = ns.getPrefix().equals("") ? ((Element) node).getAttributeValue("xmlns") : null; if (uriAttr != null) { return uriAttr; } else { return getNamespaceURI(((Element) node).getParent()); } } else { return uri; } } } return null; }
@Override public BasicNode toXML (XMLWriter writer) throws IOException { writer.write (this, getPreSpace ()); String prefix = getNamespace ().getPrefix (); if (prefix.length () != 0) { writer.write (this, prefix); writer.write (this, ":"); } writer.write (this, getName ()); writer.write (this, getEqualsSpace ()); char[] buffer = new char[1]; buffer[0] = (char)quoteChar; String s = new String (buffer); writer.write (this, s); if (rawValue != null) writer.write (this, rawValue); else writer.writeAttributeValue (this, getValue (), quoteChar); writer.write (this, s); return this; }