当前位置: 首页>>代码示例>>Java>>正文


Java Attr.getNodeName方法代码示例

本文整理汇总了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);
}
 
开发者ID:spetitjean,项目名称:TuLiPA-frames,代码行数:27,代码来源:DOMderivationBuilder.java

示例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);
            }
        }
    };
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:28,代码来源:MergerXmlUtils.java

示例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
        );
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:C14nHelper.java

示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:DOMStreamReader.java

示例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 + ")");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:SetAttributeNode.java

示例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;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:19,代码来源:OpendaylightNamespaceHandler.java

示例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);
}
 
开发者ID:spetitjean,项目名称:TuLiPA-frames,代码行数:38,代码来源:DOMderivationBuilder.java

示例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
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:35,代码来源:DOMStreamReader.java

示例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;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:67,代码来源:SdkRepoSource.java


注:本文中的org.w3c.dom.Attr.getNodeName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。