本文整理汇总了Java中org.w3c.dom.Element.getAttributeNodeNS方法的典型用法代码示例。如果您正苦于以下问题:Java Element.getAttributeNodeNS方法的具体用法?Java Element.getAttributeNodeNS怎么用?Java Element.getAttributeNodeNS使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.Element
的用法示例。
在下文中一共展示了Element.getAttributeNodeNS方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: allocatePrefix
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Declares a new prefix on the given element and associates it
* with the specified namespace URI.
* <p>
* Note that this method doesn't use the default namespace
* even if it can.
*/
private String allocatePrefix( Element e, String nsUri ) {
// look for existing namespaces.
NamedNodeMap atts = e.getAttributes();
for( int i=0; i<atts.getLength(); i++ ) {
Attr a = (Attr)atts.item(i);
if( Const.XMLNS_URI.equals(a.getNamespaceURI()) ) {
if( a.getName().indexOf(':')==-1 ) continue;
if( a.getValue().equals(nsUri) )
return a.getLocalName(); // found one
}
}
// none found. allocate new.
while(true) {
String prefix = "p"+(int)(Math.random()*1000000)+'_';
if(e.getAttributeNodeNS(Const.XMLNS_URI,prefix)!=null)
continue; // this prefix is already allocated.
e.setAttributeNS(Const.XMLNS_URI,"xmlns:"+prefix,nsUri);
return prefix;
}
}
示例2: SignatureAlgorithm
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Constructor SignatureAlgorithm
*
* @param element
* @param baseURI
* @param secureValidation
* @throws XMLSecurityException
*/
public SignatureAlgorithm(
Element element, String baseURI, boolean secureValidation
) throws XMLSecurityException {
super(element, baseURI);
algorithmURI = this.getURI();
Attr attr = element.getAttributeNodeNS(null, "Id");
if (attr != null) {
element.setIdAttributeNode(attr, true);
}
if (secureValidation && (XMLSignature.ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5.equals(algorithmURI)
|| XMLSignature.ALGO_ID_SIGNATURE_NOT_RECOMMENDED_RSA_MD5.equals(algorithmURI))) {
Object exArgs[] = { algorithmURI };
throw new XMLSecurityException("signature.signatureAlgorithm", exArgs);
}
signatureAlgorithm = getSignatureAlgorithmSpi(algorithmURI);
signatureAlgorithm.engineGetContextFromElement(this.constructionElement);
}
示例3: declareExtensionNamespace
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Adds the specified namespace URI to the jaxb:extensionBindingPrefixes
* attribute of the target document.
*/
private void declareExtensionNamespace( Element target, String nsUri ) {
// look for the attribute
Element root = target.getOwnerDocument().getDocumentElement();
Attr att = root.getAttributeNodeNS(Const.JAXB_NSURI,EXTENSION_PREFIXES);
if( att==null ) {
String jaxbPrefix = allocatePrefix(root,Const.JAXB_NSURI);
// no such attribute. Create one.
att = target.getOwnerDocument().createAttributeNS(
Const.JAXB_NSURI,jaxbPrefix+':'+EXTENSION_PREFIXES);
root.setAttributeNodeNS(att);
}
String prefix = allocatePrefix(root,nsUri);
if( att.getValue().indexOf(prefix)==-1 )
// avoid redeclaring the same namespace twice.
att.setValue( att.getValue()+' '+prefix);
}
示例4: DOMSignatureValue
import org.w3c.dom.Element; //导入方法依赖的package包/类
DOMSignatureValue(Element sigValueElem, XMLCryptoContext context)
throws MarshalException
{
try {
// base64 decode signatureValue
value = Base64.decode(sigValueElem);
} catch (Base64DecodingException bde) {
throw new MarshalException(bde);
}
Attr attr = sigValueElem.getAttributeNodeNS(null, "Id");
if (attr != null) {
id = attr.getValue();
sigValueElem.setIdAttributeNode(attr, true);
} else {
id = null;
}
this.sigValueElem = sigValueElem;
}
示例5: select
import org.w3c.dom.Element; //导入方法依赖的package包/类
private static void select(List<Node> results, Element context,
List<SimpleXpathStep> steps, int stepIndex, boolean onlyFirst) {
if (onlyFirst && CollectionUtil.isNonEmpty(results)) {
return;
}
ParamUtil.requireNonNull("context", context);
ParamUtil.requireNonNull("steps", steps);
SimpleXpathStep step = steps.get(stepIndex);
if (step.isElement) {
List<Element> children = XmlUtil.getElementChilden(
context, step.namespaceUri, step.localPart);
if (steps.size() == stepIndex + 1) {
results.addAll(children);
} else {
for (Element child : children) {
select(results, child, steps, stepIndex + 1, onlyFirst);
}
}
} else {
Attr attr = context.getAttributeNodeNS(step.namespaceUri, step.localPart);
if (attr == null && step.namespaceUri == null) {
attr = context.getAttributeNode(step.localPart);
}
if (attr != null) {
results.add(attr);
}
}
}
示例6: KeyInfo
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Constructor KeyInfo
*
* @param element
* @param baseURI
* @throws XMLSecurityException
*/
public KeyInfo(Element element, String baseURI) throws XMLSecurityException {
super(element, baseURI);
Attr attr = element.getAttributeNodeNS(null, "Id");
if (attr != null) {
element.setIdAttributeNode(attr, true);
}
}
示例7: marshal
import org.w3c.dom.Element; //导入方法依赖的package包/类
public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
throws MarshalException
{
Document ownerDoc = DOMUtils.getOwnerDocument(parent);
Element rmElem = DOMUtils.createElement(ownerDoc, "RetrievalMethod",
XMLSignature.XMLNS, dsPrefix);
// add URI and Type attributes
DOMUtils.setAttribute(rmElem, "URI", uri);
DOMUtils.setAttribute(rmElem, "Type", type);
// add Transforms elements
if (!transforms.isEmpty()) {
Element transformsElem = DOMUtils.createElement(ownerDoc,
"Transforms",
XMLSignature.XMLNS,
dsPrefix);
rmElem.appendChild(transformsElem);
for (Transform transform : transforms) {
((DOMTransform)transform).marshal(transformsElem,
dsPrefix, context);
}
}
parent.appendChild(rmElem);
// save here node
here = rmElem.getAttributeNodeNS(null, "URI");
}
示例8: circumventBug2650
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* This method spreads all namespace attributes in a DOM document to their
* children. This is needed because the XML Signature XPath transform
* must evaluate the XPath against all nodes in the input, even against
* XPath namespace nodes. Through a bug in XalanJ2, the namespace nodes are
* not fully visible in the Xalan XPath model, so we have to do this by
* hand in DOM spaces so that the nodes become visible in XPath space.
*
* @param doc
* @see <A HREF="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2650">
* Namespace axis resolution is not XPath compliant </A>
*/
public static void circumventBug2650(Document doc) {
Element documentElement = doc.getDocumentElement();
// if the document element has no xmlns definition, we add xmlns=""
Attr xmlnsAttr =
documentElement.getAttributeNodeNS(Constants.NamespaceSpecNS, "xmlns");
if (xmlnsAttr == null) {
documentElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns", "");
}
XMLUtils.circumventBug2650internal(doc);
}
示例9: getAttributeNSOrNull
import org.w3c.dom.Element; //导入方法依赖的package包/类
public static String getAttributeNSOrNull(
Element e,
String name,
String nsURI) {
Attr a = e.getAttributeNodeNS(nsURI, name);
if (a == null)
return null;
return a.getValue();
}
示例10: findAttributes
import org.w3c.dom.Element; //导入方法依赖的package包/类
@Override
public List<Attr> findAttributes(Element element) {
Attr found = element.getAttributeNodeNS(this.namespace, getLocalName());
if (found == null) {
return Collections.emptyList();
}
return Arrays.asList(found);
}
示例11: DOMXMLObject
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Creates an <code>XMLObject</code> from an element.
*
* @param objElem an Object element
* @throws MarshalException if there is an error when unmarshalling
*/
public DOMXMLObject(Element objElem, XMLCryptoContext context,
Provider provider)
throws MarshalException
{
// unmarshal attributes
this.encoding = DOMUtils.getAttributeValue(objElem, "Encoding");
Attr attr = objElem.getAttributeNodeNS(null, "Id");
if (attr != null) {
this.id = attr.getValue();
objElem.setIdAttributeNode(attr, true);
} else {
this.id = null;
}
this.mimeType = DOMUtils.getAttributeValue(objElem, "MimeType");
NodeList nodes = objElem.getChildNodes();
int length = nodes.getLength();
List<XMLStructure> content = new ArrayList<XMLStructure>(length);
for (int i = 0; i < length; i++) {
Node child = nodes.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE) {
Element childElem = (Element)child;
String tag = childElem.getLocalName();
if (tag.equals("Manifest")) {
content.add(new DOMManifest(childElem, context, provider));
continue;
} else if (tag.equals("SignatureProperties")) {
content.add(new DOMSignatureProperties(childElem, context));
continue;
} else if (tag.equals("X509Data")) {
content.add(new DOMX509Data(childElem));
continue;
}
//@@@FIXME: check for other dsig structures
}
content.add(new javax.xml.crypto.dom.DOMStructure(child));
}
if (content.isEmpty()) {
this.content = Collections.emptyList();
} else {
this.content = Collections.unmodifiableList(content);
}
this.objectElem = objElem;
}
示例12: getAttribute
import org.w3c.dom.Element; //导入方法依赖的package包/类
public static String getAttribute(Element e, String nsUri, String local) {
if(e.getAttributeNodeNS(nsUri,local)==null) return null;
return e.getAttributeNS(nsUri,local);
}
示例13: getAttributeValue
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Returns the value of the given "android:attribute" in the given element.
*
* @param element The non-null element where to extract the attribute.
* @param attrName The local name of the attribute.
* It must use the {@link #NS_URI} but no prefix should be specified here.
* @return The value of the attribute or a non-null empty string if not found.
*/
private String getAttributeValue(Element element, String attrName) {
Attr attr = element.getAttributeNodeNS(NS_URI, attrName);
String value = attr == null ? "" : attr.getNodeValue(); //$NON-NLS-1$
return value;
}
示例14: getAttributeValue
import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
* Returns the attribute value for the attribute with the specified name.
* Returns null if there is no such attribute, or
* the empty string if the attribute value is empty.
*
* <p>This works around a limitation of the DOM
* <code>Element.getAttributeNode</code> method, which does not distinguish
* between an unspecified attribute and an attribute with a value of
* "" (it returns "" for both cases).
*
* @param elem the element containing the attribute
* @param name the name of the attribute
* @return the attribute value (may be null if unspecified)
*/
public static String getAttributeValue(Element elem, String name) {
Attr attr = elem.getAttributeNodeNS(null, name);
return (attr == null) ? null : attr.getValue();
}