本文整理匯總了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;
}
示例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;
}
示例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());
}
}
示例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;
}
示例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
}
}
}
示例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();
}
}
示例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);
}
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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());
}