public Element (Token token) { this.startToken = token; this.beginName = token.getText ().substring (1); this.name = this.beginName.trim (); setNamespace (null); }
public Element (Parent parent, String name, Namespace ns) { if (name == null) throw new NullPointerException ("name is null"); if (name.trim ().length () == 0) throw new IllegalArgumentException ("name is blank"); this.parent = parent; this.name = name; compactEmpty = true; setNamespace (ns); if (parent != null) parent.addNode (this); }
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; }
throw new XMLParseException ("The namespace prefix "+prefix+" is not defined: '"+parent.getName ()+"'", parent.getStartToken ()); parent.setNamespace (ns);