List of usage examples for org.w3c.dom Attr setPrefix
public void setPrefix(String prefix) throws DOMException;
null
if it is unspecified. From source file:org.apache.hadoop.gateway.filter.rewrite.impl.xml.XmlFilterReader.java
private void streamAttribute(Element element, Attribute attribute) throws XPathExpressionException { Attr node; QName name = attribute.getName(); String prefix = name.getPrefix(); String uri = name.getNamespaceURI(); if (uri == null || uri.isEmpty()) { node = document.createAttribute(name.getLocalPart()); element.setAttributeNode(node);/*from w ww. ja v a2 s . co m*/ } else { node = document.createAttributeNS(uri, name.getLocalPart()); if (prefix != null && !prefix.isEmpty()) { node.setPrefix(prefix); } element.setAttributeNodeNS(node); } String value = attribute.getValue(); Level level = stack.peek(); if ((level.scopeConfig) == null || (level.scopeConfig.getSelectors().isEmpty())) { value = filterAttribute(null, attribute.getName(), value, null); node.setValue(value); } else { UrlRewriteFilterPathDescriptor path = pickFirstMatchingPath(level); if (path instanceof UrlRewriteFilterApplyDescriptor) { String rule = ((UrlRewriteFilterApplyDescriptor) path).rule(); value = filterAttribute(null, attribute.getName(), value, rule); node.setValue(value); } } //dump( document ); if (prefix == null || prefix.isEmpty()) { writer.write(" "); writer.write(name.getLocalPart()); } else { writer.write(" "); writer.write(prefix); writer.write(":"); writer.write(name.getLocalPart()); } writer.write("=\""); writer.write(value); writer.write("\""); element.removeAttributeNode(node); }
From source file:org.ojbc.util.xml.XmlUtils.java
/** * Add an attribute to the specified element * @param parent the element to which we add the attribute * @param ns the namespace of the attribute * @param attributeName the name of the attribute * @param value the value of the attribute * @return the attribute/*from ww w. j ava 2s .c om*/ */ public static final Attr addAttribute(Element parent, String ns, String attributeName, String value) { Document doc = parent.getOwnerDocument(); Attr ret = doc.createAttributeNS(ns, attributeName); ret.setTextContent(value); ret.setPrefix(OJBC_NAMESPACE_CONTEXT.getPrefix(ns)); parent.setAttributeNode(ret); return ret; }