public Attribute getAttribute(String namespaceUri, String name) { for (Attribute attribute : attributes) { // name must match and must be in empty namespace if (attribute.getName().equals(name) && attribute.getNamespaceUri().equals(namespaceUri)) return attribute; } return null; }
private boolean hasXmlnsReservedName(Attribute attribute) { String name = attribute.getName(); return name.equals("xmlns") || name.startsWith("xmlns:"); }
public B addAttribute(Attribute attribute) { checkReset(); // check if attribute already exists for(Attribute existing : currentElement.attributes) { if(existing.getName().equals(attribute.getName()) && existing.getNamespaceUri().equals(attribute.getNamespaceUri())) { currentElement.attributes.remove(existing); break; } } currentElement.attributes.add(attribute); return (B) this; }
private void renderAttribute(StringBuilder buffer, Attribute attribute, ResolverNamespaceResolver nsResolver) { String qname; if (!attribute.getNamespaceUri().equals("")) { // attribute is in a namespace, resolve prefix qname = nsResolver.resolvePrefix(attribute.getNamespaceUri()) + ":" + attribute.getName(); } else { qname = attribute.getName(); } renderAttribute(buffer, qname, attribute.getValue()); }
/** * example for "http://myNS.org/anything", this method returns "myNS" for * element <test xmlns:myNS="http://myNS.org/anything" /> * * @return the identifier for the given namespace definition */ public String getNamespaceIdentifier(String namespace) { for (Attribute attribute : element.getAttributes()) { if (attribute.getValue().equals(namespace) && attribute.getName().startsWith(Namespaces.XMLNS_AND_COLON)) { return attribute.getName().substring(Namespaces.XMLNS_AND_COLON.length()); } } return null; }
public boolean namespacePresent(String namespaceURI) { Collection<String> nsUris = element.getDeclaredNamespaces().values(); if (nsUris.contains(namespaceURI)) { return true; } for (Attribute attribute : element.getAttributes()) { if (attribute.getName().startsWith("xmlns") && attribute.getValue().equals(namespaceURI)) { return true; } } if (namespaceURI.equals(element.getNamespaceURI())) return true; return false; // not present }
if (!attribute.getName().startsWith("xmlns")) { openElementBuffer.append(" "); renderAttribute(openElementBuffer, attribute, nsResolver);
StanzaBuilder stanzaBuilder = new StanzaBuilder(stanza.getName(), stanza.getNamespaceURI()); for (Attribute attribute : stanza.getAttributes()) { if ("from".equals(attribute.getName())) continue; stanzaBuilder.addAttribute(attribute);