List of usage examples for org.w3c.dom Attr getValue
public String getValue();
From source file:xsul.dsig.globus.security.authentication.wssec.WSSecurityUtil.java
/** * Returns the first WS-Security header element for a given actor * Only one WS-Security header is allowed for an actor. *///ww w . ja v a2s. c o m public static Element getSecurityHeader(Document doc, String actor) { Element soapHeaderElement = (Element) getDirectChild(doc.getFirstChild(), XmlConstants.S_HEADER, WSConstants.SOAP_NS); // TODO: this can also be slightly optimized NodeList list = soapHeaderElement.getElementsByTagNameNS(WSConstants.WSSE_NS, WSConstants.WS_SEC_LN); int len = list.getLength(); Element elem; Attr attr; String hActor; for (int i = 0; i < len; i++) { elem = (Element) list.item(i); attr = elem.getAttributeNodeNS(WSConstants.SOAP_NS, "actor"); hActor = (attr != null) ? attr.getValue() : null; if ((((hActor == null) || (hActor.length() == 0)) && ((actor == null) || (actor.length() == 0))) || ((hActor != null) && (actor != null) && hActor.equalsIgnoreCase(actor))) { return elem; } } return null; }
From source file:yax.test.XmlTest.java
static void dumpnode(Node node, int depth, StringBuilder buf) throws Exception { switch (node.getNodeType()) { case DOCUMENT_NODE: Node root = ((Document) node).getDocumentElement(); buf.append("<?xml version=\"1.0\"?>\n"); buf.append("<!DOCTYPE>\n"); dumpnode(root, 0, buf);// w ww . j av a 2 s . c o m break; case ELEMENT_NODE: Element enode = (Element) node; buf.append(String.format("%s<%s", indent(depth), enode.getTagName())); NamedNodeMap attrs = enode.getAttributes(); if (attrs != null) { for (int i = 0; i < attrs.getLength(); i++) { Attr attr = (Attr) attrs.item(i); buf.append(String.format(" %s=\"%s\"", attr.getName(), attr.getValue())); } } buf.append(">\n"); NodeList children = enode.getChildNodes(); if (children != null) { for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); dumpnode(child, depth + 1, buf); } } buf.append(String.format("%s</%s>", indent(depth), enode.getTagName())); break; case TEXT_NODE: buf.append(String.format("%s|%s|", indent(depth), ((Text) node).getData())); break; default: String typename = node.getNodeName(); throw new Exception("dumpnode: unexpected node type: " + typename); } }