@Override public boolean equals (Object obj) { if (obj == null) return false; if (!(obj instanceof Namespace) ) return false; Namespace ns = (Namespace)obj; return prefix.equals (ns.getPrefix ()) && uri.equals (ns.getURI ()) ; }
List<Node> sessions = nodesByNamespace(doc, droolsNamespace.getURI(), "ksession"); if (sessions != null) { for (Node session : sessions) {
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; }
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; }
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; }