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


Java Attr.getName方法代码示例

本文整理汇总了Java中org.w3c.dom.Attr.getName方法的典型用法代码示例。如果您正苦于以下问题:Java Attr.getName方法的具体用法?Java Attr.getName怎么用?Java Attr.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.w3c.dom.Attr的用法示例。


在下文中一共展示了Attr.getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractAttribute

import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
 * Search for a specific attribute in an element and return it's value
 *
 * @param attribName the name of the attribute
 * @param element the {@link Element} to search in
 * @return the value of the attribute
 */
private String extractAttribute(
                                 Element element,
                                 String attribName ) {

    NamedNodeMap attributes = element.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Attr attribute = (Attr) attributes.item(i);

        String propertyName = attribute.getName();
        if (attribName.equals(propertyName)) {
            return attribute.getValue();
        }
    }
    return null;
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:23,代码来源:ReadingsRepository.java

示例2: createAttributeStep

import org.w3c.dom.Attr; //导入方法依赖的package包/类
private static Step createAttributeStep(Sequence mainSequence, Object parent, Attr attr) throws EngineException {
	XMLAttributeStep step = null;
	if (attr != null) {
		String attrName = attr.getName();
		String localName = attr.getLocalName();
		String attributeNodeName = (localName == null) ? attrName:localName;
		if (!attributeNodeName.equals("done"/*xsd.getXmlGenerationDescription().getDoneAttribute()*/) &&
			!attributeNodeName.equals("occurs"/*xsd.getXmlGenerationDescription().getOccursAttribute()*/)) {
			step = new XMLAttributeStep();
			step.setNodeName(attributeNodeName);
			step.bNew = true;
			addStepToParent(mainSequence, parent, step);
		}
	}
	return step;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:17,代码来源:StepUtils.java

示例3: serializeAttributes

import org.w3c.dom.Attr; //导入方法依赖的package包/类
public void serializeAttributes(Object element, XMLSerializer target) throws SAXException {
    NamedNodeMap al = ((Element)element).getAttributes();
    int len = al.getLength();
    for( int i=0; i<len; i++ ) {
        Attr a = (Attr)al.item(i);
        // work defensively
        String uri = a.getNamespaceURI();
        if(uri==null)   uri="";
        String local = a.getLocalName();
        String name = a.getName();
        if(local==null) local = name;
        if (uri.equals(WellKnownNamespace.XML_SCHEMA_INSTANCE) && ("nil".equals(local))) {
            isNilIncluded = true;
        }
        if(name.startsWith("xmlns")) continue;// DOM reports ns decls as attributes

        target.attribute(uri,local,a.getValue());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:AnyTypeBeanInfo.java

示例4: checkXMLAttrs

import org.w3c.dom.Attr; //导入方法依赖的package包/类
public boolean checkXMLAttrs(Attr template, Attr source) {
    if (source == null || template == null) {
        return template == source;
    }
    String tname = template.getName();
    String tvalue = template.getValue();
    String sname = source.getName();
    String svalue = source.getValue();
    System.out.println("Attr:" + tname + "?" + sname);
    if (tname != null && !tname.equals(sname)) {
        // ref.println("Attr Name:" + tname + "!=" + sname);
        return false;
    }
    if (tvalue != null && !tvalue.equals(svalue)) {
        // ref.println("Attr value:" + tvalue + "!=" + svalue);
        return false;
    }
    // ref.println("Attr:" + tname + ":" + tvalue + "=" + sname + ":" +
    // svalue);
    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:LSParserTCKTest.java

示例5: addNamespacesFrom

import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
 * Adds namespaces from the tag to this context, possibly overriding namespaces
 * from previously added tags. Tags should be added starting from the root down
 * to the context position.
 */
private void addNamespacesFrom(SyntaxElement s) {
    Node e = s.getNode();
    NamedNodeMap attrs = e.getAttributes();
    String nodePrefix = getPrefix(e.getNodeName(), false);
    String version = null;
    String xsltAttrName = null;
    
    for (int i = attrs.getLength() - 1; i >= 0; i--) {
        Node n = attrs.item(i);
        if (n.getNodeType() == Node.ATTRIBUTE_NODE) {
            Attr a = (Attr)n;
            String attrName = a.getName();
            String value = a.getValue();
            addNamespace(attrName, value, nodePrefix);

        
            if(value.trim().equals("http://www.w3.org/1999/XSL/Transform")) { //NOI18N
                xsltAttrName = attrName;
            }
            if(CompletionUtil.getLocalNameFromTag(attrName).
                    equals("version")) { //NOI18N
                version = value.trim();
            }
        } 
    }
    
    if (xsltAttrName != null && "2.0".equals(version)) {
        String prefix = getPrefix(xsltAttrName, false);
        if (prefix == null) {
            // override nonNS location because nonNS schema is XSLT 2.0
            noNamespaceSchemaLocation = "http://www.w3.org/2007/schema-for-xslt20.xsd";
        } else {
            addSchemaLocation(prefix + " http://www.w3.org/2007/schema-for-xslt20.xsd"); //NOI18N
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:42,代码来源:CompletionContextImpl.java

示例6: populateNamespaces

import org.w3c.dom.Attr; //导入方法依赖的package包/类
private void populateNamespaces() {
    // Find the a start or empty tag just before the current syntax element.
    SyntaxElement element = this.element;
    while (element != null && !(syntaxSupport.isStartTag(element)) && !(syntaxSupport.isEmptyTag(element))) {
        element = element.getPrevious();
    }
    if (element == null) {
        return;
    }

    // To find all namespace declarations active at the caret offset, we
    // need to look at xmlns attributes of the current element and its ancestors.
    while (element != null) {
        Node node = element.getNode();
        if (syntaxSupport.isStartTag(element) || syntaxSupport.isEmptyTag(element)) {
            NamedNodeMap attributes = node.getAttributes();
            for (int index = 0; index < attributes.getLength(); index++) {
                Attr attr = (Attr) attributes.item(index);
                String attrName = attr.getName();
                String attrValue = attr.getValue();
                if (attrName == null || attrValue == null) {
                    continue;
                }
                String prefix = ContextUtilities.getPrefixFromNamespaceDeclaration(attrName);
                if (prefix == null) {
                    continue;
                }
                // Avoid overwriting a namespace declaration "closer" to the caret offset.
                if (!declaredNamespaces.containsKey(prefix)) {
                    declaredNamespaces.put(prefix, attrValue);
                }
            }
        }
        element = element.getParentElement();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:DocumentContext.java

示例7: populateNamespaces

import org.w3c.dom.Attr; //导入方法依赖的package包/类
private void populateNamespaces() {
    // Find the a start or empty tag just before the current syntax element.
    SyntaxElement element = this.element;
    while (element != null && !syntaxSupport.isStartTag(element) && !syntaxSupport.isEmptyTag(element)) {
        element = element.getPrevious();
    }
    if (element == null) {
        return;
    }

    // To find all namespace declarations active at the caret offset, we
    // need to look at xmlns attributes of the current element and its ancestors.
    Node node = (Node)element;
    while (node != null && element != null) {
        if (syntaxSupport.isStartTag(element) || syntaxSupport.isEmptyTag(element)) {
            NamedNodeMap attributes = node.getAttributes();
            for (int index = 0; index < attributes.getLength(); index++) {
                Attr attr = (Attr) attributes.item(index);
                String attrName = attr.getName();
                String attrValue = attr.getValue();
                if (attrName == null || attrValue == null) {
                    continue;
                }
                String prefix = ContextUtilities.getPrefixFromNamespaceDeclaration(attrName);
                if (prefix == null) {
                    continue;
                }
                // Avoid overwriting a namespace declaration "closer" to the caret offset.
                if (!declaredNamespaces.containsKey(prefix)) {
                    declaredNamespaces.put(prefix, attrValue);
                }
            }
        }
        node = node.getParentNode();
        element = syntaxSupport.getSyntaxElement(node);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:DocumentContext.java

示例8: readXmlElement

import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
 * This method will read a tree of elements and their attributes
 * 
 * @param element the root element of the tree
 */
private void readXmlElement(
                             LinkedList<String> currentElementPath,
                             Element element ) {

    //append this node element to the current path
    currentElementPath.add(element.getNodeName());

    NodeList childNodes = element.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node childNode = childNodes.item(i);
        if (childNode.getNodeType() == Node.ELEMENT_NODE) {
            readXmlElement(currentElementPath, (Element) childNode);
        }
    }

    //read all attributes
    NamedNodeMap attributes = element.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Attr attribute = (Attr) attributes.item(i);

        String propertyName = getCurrentXmlElementPath(currentElementPath) + attribute.getName();
        String propertyValue = attribute.getValue();

        //put in the properties table
        properties.put(propertyName, propertyValue);

        log.debug("Added property with name '" + propertyName + "' and value '" + propertyValue + "'");
    }

    //after we are done with the node, remove it from the path
    currentElementPath.removeLast();
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:38,代码来源:ConfigurationResource.java

示例9: isEligibleAttribute

import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
 * Determine whether the given attribute is eligible for being
 * turned into a corresponding bean property value.
 * <p>The default implementation considers any attribute as eligible,
 * except for the "id" attribute and namespace declaration attributes.
 * @param attribute the XML attribute to check
 * @param parserContext the {@code ParserContext}
 * @see #isEligibleAttribute(String)
 */
protected boolean isEligibleAttribute(Attr attribute, ParserContext parserContext) {
	boolean eligible = isEligibleAttribute(attribute);
	if(!eligible) {
		String fullName = attribute.getName();
		eligible = (!fullName.equals("xmlns") && !fullName.startsWith("xmlns:") &&
				isEligibleAttribute(parserContext.getDelegate().getLocalName(attribute)));
	}
	return eligible;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:AbstractSimpleBeanDefinitionParser.java

示例10: getPrefixForNs

import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
 * Looks for an existing prefix for a a given namespace.
 * The prefix must start with "xmlns:". The whole prefix is returned.
 * @param attributes the list of attributes to look through
 * @param ns the namespace to find.
 * @return the found prefix or null if none is found.
 */
private static String getPrefixForNs(NamedNodeMap attributes, String ns) {
    if (attributes != null) {
        for (int i = 0, n = attributes.getLength(); i < n; i++) {
            Attr attribute = (Attr) attributes.item(i);
            if (ns.equals(attribute.getValue()) && ns.startsWith(SdkConstants.XMLNS_PREFIX)) {
                return attribute.getName();
            }
        }
    }

    return null;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:20,代码来源:NodeUtils.java

示例11: setAttributeNode

import org.w3c.dom.Attr; //导入方法依赖的package包/类
public Attr setAttributeNode(Attr newAttr) throws DOMException {
    Element owner = newAttr.getOwnerElement();
    if (owner != null) {
        if (owner == this) {
            return null;
        } else {
            throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR,
                                   "Attribute is already in use");
        }
    }

    IIOAttr attr;
    if (newAttr instanceof IIOAttr) {
        attr = (IIOAttr)newAttr;
        attr.setOwnerElement(this);
    } else {
        attr = new IIOAttr(this,
                           newAttr.getName(),
                           newAttr.getValue());
    }

    Attr oldAttr = getAttributeNode(attr.getName());
    if (oldAttr != null) {
        removeAttributeNode(oldAttr);
    }

    attributes.add(attr);

    return oldAttr;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:IIOMetadataNode.java

示例12: populateNamespaces

import org.w3c.dom.Attr; //导入方法依赖的package包/类
private void populateNamespaces() {
    // Find the a start or empty tag just before the current syntax element.
    SyntaxElement element = this.element;
    while (element != null && !syntaxSupport.isStartTag(element) && !syntaxSupport.isEmptyTag(element)) {
        element = element.getPrevious();
    }
    if (element == null) {
        return;
    }

    // To find all namespace declarations active at the caret offset, we
    // need to look at xmlns attributes of the current element and its ancestors.
    Node node = (Node)element;
    while (node != null && element != null) {
        if (syntaxSupport.isStartTag(element) || syntaxSupport.isEmptyTag(element)) {
            NamedNodeMap attributes = node.getAttributes();
            for (int index = 0; index < attributes.getLength(); index++) {
                Attr attr = (Attr) attributes.item(index);
                String attrName = attr.getName();
                String attrValue = attr.getValue();
                if (attrName == null || attrValue == null) {
                    continue;
                }
                String prefix = ContextUtilities.getPrefixFromNamespaceDeclaration(attrName);
                if (prefix == null) {
                    continue;
                }
                // Avoid overwriting a namespace declaration "closer" to the caret offset.
                if (!declaredNamespaces.containsKey(prefix)) {
                    declaredNamespaces.put(prefix, attrValue);
                }
                Node tmp = attributes.getNamedItem(VERSION);
                if(tmp!=null) {
                    persistenceVersion = tmp.getNodeValue();
                }
            }
        }
        node = node.getParentNode();
        element = syntaxSupport.getSyntaxElement(node);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:42,代码来源:DocumentContext.java

示例13: calcXpath

import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
 * Compute the xpath of a node relative to an anchor.
 * 
 * @param node
 *            node to find the xpath from.
 * @param anchor
 *            the relative point to fid from.
 * @return the computed xpath.
 */
public static String calcXpath(Node node, Node anchor) {
	String xpath = "";
	Node current = null;

	if (node == null || node.equals(anchor))
		return "";

	// add attribute to xpath
	if (node instanceof Attr) {
		Attr attr = (Attr) node;
		node = attr.getOwnerElement();
		xpath = '@' + attr.getName() + '/';
	}

	while ((current = node.getParentNode()) != anchor) {
		Engine.logEngine.trace("Calc Xpath : current node : " + current.getNodeName());
		NodeList childs = current.getChildNodes();
		int index = 0;
		for (int i = 0; i < childs.getLength(); i++) {
			if (childs.item(i).getNodeType() != Node.ELEMENT_NODE
					&& !childs.item(i).getNodeName().equalsIgnoreCase("#text"))
				continue;

			Engine.logEngine.trace("Calc Xpath : ==== > Child node : " + childs.item(i).getNodeName());

			// Bump the index if we have the same tag names..
			if (childs.item(i).getNodeName().equalsIgnoreCase(node.getNodeName())) {
				// tag names are equal ==> bump the index.
				index++;
				// is our node the one that is listed ?
				if (childs.item(i).equals(node))
					// We found our node in the parent node list
					break;
			}
		}
		// count the number of elements having the same tag
		int nbElements = 0;
		for (int i = 0; i < childs.getLength(); i++) {
			if (childs.item(i).getNodeName().equalsIgnoreCase(node.getNodeName())) {
				nbElements++;
			}
		}

		String name = node.getNodeName();
		if (name.equalsIgnoreCase("#text"))
			name = "text()";
		name = xpathEscapeColon(name);

		if (nbElements > 1) {
			xpath = name + "[" + index + "]/" + xpath;
		} else {
			// only one element had the same tag ==> do not compute the [xx]
			// syntax..
			xpath = name + "/" + xpath;
		}
		node = current;
	}
	if (xpath.length() > 0)
		// remove the trailing '/'
		xpath = xpath.substring(0, xpath.length() - 1);

	return xpath;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:73,代码来源:XMLUtils.java

示例14: XSDAttribute

import org.w3c.dom.Attr; //导入方法依赖的package包/类
private XSDAttribute(Attr attr) {
//			this.source = attr;
			this.name = attr.getName();
			this.value = attr.getValue();
			this.type = ATTRIBUTE_SIMPLE_TYPE;
		}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:7,代码来源:XSDExtractor.java

示例15: compare

import org.w3c.dom.Attr; //导入方法依赖的package包/类
/**
 * Compares two attributes based on the C14n specification.
 *
 * <UL>
 * <LI>Namespace nodes have a lesser document order position than
 *   attribute nodes.
 * <LI> An element's namespace nodes are sorted lexicographically by
 *   local name (the default namespace node, if one exists, has no
 *   local name and is therefore lexicographically least).
 * <LI> An element's attribute nodes are sorted lexicographically with
 *   namespace URI as the primary key and local name as the secondary
 *   key (an empty namespace URI is lexicographically least).
 * </UL>
 *
 * @param attr0
 * @param attr1
 * @return returns a negative integer, zero, or a positive integer as
 *   obj0 is less than, equal to, or greater than obj1
 *
 */
public int compare(Attr attr0, Attr attr1) {
    String namespaceURI0 = attr0.getNamespaceURI();
    String namespaceURI1 = attr1.getNamespaceURI();

    boolean isNamespaceAttr0 = XMLNS.equals(namespaceURI0);
    boolean isNamespaceAttr1 = XMLNS.equals(namespaceURI1);

    if (isNamespaceAttr0) {
        if (isNamespaceAttr1) {
            // both are namespaces
            String localname0 = attr0.getLocalName();
            String localname1 = attr1.getLocalName();

            if ("xmlns".equals(localname0)) {
                localname0 = "";
            }

            if ("xmlns".equals(localname1)) {
                localname1 = "";
            }

            return localname0.compareTo(localname1);
        }
        // attr0 is a namespace, attr1 is not
        return ATTR0_BEFORE_ATTR1;
    } else if (isNamespaceAttr1) {
        // attr1 is a namespace, attr0 is not
        return ATTR1_BEFORE_ATTR0;
    }

    // none is a namespace
    if (namespaceURI0 == null) {
        if (namespaceURI1 == null) {
            String name0 = attr0.getName();
            String name1 = attr1.getName();
            return name0.compareTo(name1);
        }
        return ATTR0_BEFORE_ATTR1;
    } else if (namespaceURI1 == null) {
        return ATTR1_BEFORE_ATTR0;
    }

    int a = namespaceURI0.compareTo(namespaceURI1);
    if (a != 0) {
        return a;
    }

    return (attr0.getLocalName()).compareTo(attr1.getLocalName());
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:70,代码来源:AttrCompare.java


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