本文整理匯總了Java中org.w3c.dom.Attr.getNodeName方法的典型用法代碼示例。如果您正苦於以下問題:Java Attr.getNodeName方法的具體用法?Java Attr.getNodeName怎麽用?Java Attr.getNodeName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.Attr
的用法示例。
在下文中一共展示了Attr.getNodeName方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildDerivationTree
import org.w3c.dom.Attr; //導入方法依賴的package包/類
public static void buildDerivationTree(Element mother, Node derivation){
Element t = derivDoc.createElement("tree");
NamedNodeMap atts = derivation.getAttributes();
for (int i = 0 ; i < atts.getLength() ; i++){
Attr a = (Attr) atts.item(i);
String name = a.getNodeName();
String val = a.getNodeValue();
if (name.equals("id")) {
t.setAttribute("id", val);
} else if (name.equals("op")) {
t.setAttribute("op", val);
} else if (name.equals("op-node")) {
t.setAttribute("node", val);
} // skip the other attributes
}
NodeList childList = derivation.getChildNodes();
for (int i = 0; i < childList.getLength(); i++)
{
Node child = childList.item(i);
if (child instanceof Element)
{
buildDerivationTree(t, child);
}
}
mother.appendChild(t);
}
示例2: getAttrComparator
import org.w3c.dom.Attr; //導入方法依賴的package包/類
/**
* Returns a comparator for {@link Attr}, alphabetically sorted by name.
* The "name" attribute is special and always sorted to the front.
*/
@NonNull
static Comparator<? super Attr> getAttrComparator() {
return new Comparator<Attr>() {
@Override
public int compare(Attr a1, Attr a2) {
String s1 = a1 == null ? "" : a1.getNodeName(); //$NON-NLS-1$
String s2 = a2 == null ? "" : a2.getNodeName(); //$NON-NLS-1$
boolean name1 = s1.equals("name"); //$NON-NLS-1$
boolean name2 = s2.equals("name"); //$NON-NLS-1$
if (name1 && name2) {
return 0;
} else if (name1) {
return -1; // name is always first
} else if (name2) {
return 1; // name is always first
} else {
return s1.compareTo(s2);
}
}
};
}
示例3: assertNotRelativeNS
import org.w3c.dom.Attr; //導入方法依賴的package包/類
/**
* This method throws an exception if the Attribute value contains
* a relative URI.
*
* @param attr
* @throws CanonicalizationException
*/
public static void assertNotRelativeNS(Attr attr) throws CanonicalizationException {
if (attr == null) {
return;
}
String nodeAttrName = attr.getNodeName();
boolean definesDefaultNS = nodeAttrName.equals("xmlns");
boolean definesNonDefaultNS = nodeAttrName.startsWith("xmlns:");
if ((definesDefaultNS || definesNonDefaultNS) && namespaceIsRelative(attr)) {
String parentName = attr.getOwnerElement().getTagName();
String attrValue = attr.getValue();
Object exArgs[] = { parentName, nodeAttrName, attrValue };
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs
);
}
}
示例4: getPrefixForAttr
import org.w3c.dom.Attr; //導入方法依賴的package包/類
/**
* If the given attribute is a namespace declaration for the given namespace URI,
* return its prefix. Otherwise null.
*/
private static String getPrefixForAttr(Attr attr, String nsUri) {
String attrName = attr.getNodeName();
if (!attrName.startsWith("xmlns:") && !attrName.equals("xmlns"))
return null; // not nsdecl
if(attr.getValue().equals(nsUri)) {
if(attrName.equals("xmlns"))
return "";
String localName = attr.getLocalName();
return (localName != null) ? localName :
QName.valueOf(attrName).getLocalPart();
}
return null;
}
示例5: test2
import org.w3c.dom.Attr; //導入方法依賴的package包/類
public static void test2() {
String name = "attr";
String oldValue = "old value";
String newValue = "new value";
Attr retAttr;
IIOMetadataNode parent = new IIOMetadataNode("parent");
MyAttrNode attrNode1 = new MyAttrNode(name, oldValue);
MyAttrNode attrNode2 = new MyAttrNode(name, newValue);
retAttr = parent.setAttributeNode(attrNode1);
retAttr = parent.setAttributeNode(attrNode2);
String actName = retAttr.getNodeName();
String actValue = retAttr.getValue();
if (!actName.equals(name) || !actValue.equals(oldValue)) {
throw new RuntimeException("Test 2 failed: Invalid attribute " +
"returned: " +
"(name: " + actName +
", value: " + actValue + ")");
}
}
示例6: enableComponentProcessorProperty
import org.w3c.dom.Attr; //導入方法依賴的package包/類
private static ComponentMetadata enableComponentProcessorProperty(final Attr attr,
final ComponentMetadata component, final ParserContext context, final String propertyName) {
if (component != null) {
throw new ComponentDefinitionException("Attribute " + attr.getNodeName()
+ " can only be used on the root <blueprint> element");
}
LOG.debug("{}: {}", propertyName, attr.getValue());
if (!Boolean.parseBoolean(attr.getValue())) {
return component;
}
MutableBeanMetadata metadata = registerComponentProcessor(context);
metadata.addProperty(propertyName, createValue(context, "true"));
return component;
}
示例7: buildDerivedTree
import org.w3c.dom.Attr; //導入方法依賴的package包/類
public static void buildDerivedTree(Element mother, Node derived){
Element t = derivDoc.createElement("node");
Element narg = derivDoc.createElement("narg");
t.appendChild(narg);
Element fs= derivDoc.createElement("fs");
narg.appendChild(fs);
NamedNodeMap atts = derived.getAttributes();
for (int i = 0 ; i < atts.getLength() ; i++){
Attr a = (Attr) atts.item(i);
Element f = derivDoc.createElement("f");
String name = a.getNodeName();
f.setAttribute("name", name);
String val = a.getNodeValue();
buildVal(f, val);
fs.appendChild(f);
}
NodeList childList = derived.getChildNodes();
for (int i = 0; i < childList.getLength(); i++)
{
Node child = childList.item(i);
if (child instanceof Element)
{
buildDerivedTree(t, child);
}
}
if (childList.getLength() == 0) {
//lex node
t.setAttribute("type", "lex");
t.setAttribute("value", derived.getNodeName());
} else {
t.setAttribute("type", "std");
}
mother.appendChild(t);
}
示例8: splitAttributes
import org.w3c.dom.Attr; //導入方法依賴的package包/類
/**
* Called when the current node is {@link Element} to look at attribute list
* (which contains both ns decl and attributes in DOM) and split them
* to attributes-proper and namespace decls.
*/
protected void splitAttributes() {
// Clear attribute and namespace lists
_currentAttributes.clear();
Scope scope = allocateScope();
_namedNodeMap = _current.getAttributes();
if (_namedNodeMap != null) {
final int n = _namedNodeMap.getLength();
for (int i = 0; i < n; i++) {
final Attr attr = (Attr) _namedNodeMap.item(i);
final String attrName = attr.getNodeName();
if (attrName.startsWith("xmlns:") || attrName.equals("xmlns")) { // NS decl?
scope.currentNamespaces.add(attr);
}
else {
_currentAttributes.add(attr);
}
}
}
// verify that all the namespaces used in element and attributes are indeed available
ensureNs(_current);
for( int i=_currentAttributes.size()-1; i>=0; i-- ) {
Attr a = _currentAttributes.get(i);
if(fixNull(a.getNamespaceURI()).length()>0)
ensureNs(a); // no need to declare "" for attributes in the default namespace
}
}
示例9: duplicateNode
import org.w3c.dom.Attr; //導入方法依賴的package包/類
/**
* Helper method used by {@link #findAlternateToolsXml(InputStream)} to duplicate a node
* and attach it to the given root in the new document.
*/
private Element duplicateNode(Element newRootNode, Element oldNode,
String namespaceUri, String prefix) {
// The implementation here is more or less equivalent to
//
// newRoot.appendChild(newDoc.importNode(oldNode, deep=true))
//
// except we can't just use importNode() since we need to deal with the fact
// that the old document is not namespace-aware yet the new one is.
Document newDoc = newRootNode.getOwnerDocument();
Element newNode = null;
String nodeName = oldNode.getNodeName();
int pos = nodeName.indexOf(':');
if (pos > 0 && pos < nodeName.length() - 1) {
nodeName = nodeName.substring(pos + 1);
newNode = newDoc.createElementNS(namespaceUri, nodeName);
newNode.setPrefix(prefix);
} else {
newNode = newDoc.createElement(nodeName);
}
newRootNode.appendChild(newNode);
// Merge in all the attributes
NamedNodeMap attrs = oldNode.getAttributes();
for (int i = 0; i < attrs.getLength(); i++) {
Attr attr = (Attr) attrs.item(i);
Attr newAttr = null;
String attrName = attr.getNodeName();
pos = attrName.indexOf(':');
if (pos > 0 && pos < attrName.length() - 1) {
attrName = attrName.substring(pos + 1);
newAttr = newDoc.createAttributeNS(namespaceUri, attrName);
newAttr.setPrefix(prefix);
} else {
newAttr = newDoc.createAttribute(attrName);
}
newAttr.setNodeValue(attr.getNodeValue());
if (pos > 0) {
newNode.getAttributes().setNamedItemNS(newAttr);
} else {
newNode.getAttributes().setNamedItem(newAttr);
}
}
// Merge all child elements and texts
for (Node child = oldNode.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
duplicateNode(newNode, (Element) child, namespaceUri, prefix);
} else if (child.getNodeType() == Node.TEXT_NODE) {
Text newText = newDoc.createTextNode(child.getNodeValue());
newNode.appendChild(newText);
}
}
return newNode;
}