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


Java Element.getAttributeNode方法代码示例

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


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

示例1: getFilter

import org.w3c.dom.Element; //导入方法依赖的package包/类
private String getFilter(Element element) {
	String filter = "";
	if (element != null) {
		// Looks for attributes
		if (element.hasAttributes()) {
			List<String> list = Arrays.asList(new String[] {"id", "name"});
			Iterator<String> it = list.iterator();
			while (it.hasNext()) {
				Attr attr = element.getAttributeNode(it.next());
				if (filter.equals("") && (attr != null)) {
					filter += "[@" + attr.getNodeName().trim() + "=\""+ attr.getNodeValue().trim() + "\"";
					break;
				}
			}
		}
		
		// Looks for Text child node
		if (filter.equals("")) {
			
		}
	}
	
	return filter;
}
 
开发者ID:convertigo,项目名称:convertigo-eclipse,代码行数:25,代码来源:XpathEvaluatorComposite.java

示例2: addOrMergeJDBCProperties

import org.w3c.dom.Element; //导入方法依赖的package包/类
public static List<JDBCProperties> addOrMergeJDBCProperties(InputStream in, String name, boolean userDefined) {
    LogService.getRoot().log(Level.CONFIG, "com.rapidminer.tools.jdbc.DatabaseService.loading_jdbc_driver_information", name);
    Document document = null;
    LinkedList propsList = new LinkedList();

    try {
        document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in);
    } catch (Exception var10) {
        LogService.getRoot().log(Level.WARNING, I18N.getMessage(LogService.getRoot().getResourceBundle(), "com.rapidminer.tools.jdbc.DatabaseService.reading_jdbc_driver_description_file_error", new Object[]{name, var10.getMessage()}), var10);
    }

    if(document != null) {
        if(!document.getDocumentElement().getTagName().toLowerCase().equals("drivers")) {
            LogService.getRoot().log(Level.WARNING, "com.rapidminer.tools.jdbc.DatabaseService.reading_jdbc_driver_description_file_outermost_tag_error", name);
            return Collections.emptyList();
        }

        NodeList driverTags = document.getDocumentElement().getElementsByTagName("driver");

        for(int i = 0; i < driverTags.getLength(); ++i) {
            Element currentElement = (Element)driverTags.item(i);

            try {
                propsList.add(addDriverInformation(currentElement, userDefined));
            } catch (Exception var11) {
                Attr currentNameAttr = currentElement.getAttributeNode("name");
                if(currentNameAttr != null) {
                    LogService.getRoot().log(Level.WARNING, I18N.getMessage(LogService.getRoot().getResourceBundle(), "com.rapidminer.tools.jdbc.DatabaseService.registering_jdbc_driver_description_error", new Object[]{currentNameAttr.getValue(), var11}), var11);
                } else {
                    LogService.getRoot().log(Level.WARNING, I18N.getMessage(LogService.getRoot().getResourceBundle(), "com.rapidminer.tools.jdbc.DatabaseService.registering_jdbc_driver_description_error", new Object[]{currentElement, var11}), var11);
                }
            }
        }
    }

    return propsList;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:38,代码来源:DatabaseService.java

示例3: requireAttr

import org.w3c.dom.Element; //导入方法依赖的package包/类
public static Attr requireAttr(Element parent, String name) throws ParseException {
    final Attr attr = parent.getAttributeNode(name);
    if(attr == null) {
        throw new MissingException("attribute", name);
    }
    return attr;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:8,代码来源:XML.java

示例4: 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);
        }
    }
}
 
开发者ID:xipki,项目名称:xitk,代码行数:30,代码来源:SimpleXpath.java

示例5: testIMPLIEDAttribute

import org.w3c.dom.Element; //导入方法依赖的package包/类
@Test
public void testIMPLIEDAttribute() throws Exception {
    Document document = createDOM("Attr3.xml");
    Element elemNode = (Element) document.getElementsByTagName("Name").item(0);
    Attr attr = elemNode.getAttributeNode("type");
    assertNull(attr);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:AttrTest.java

示例6: locateAttrParent

import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
 * Support for getParentOfNode; walks a DOM tree until it finds
 * the Element which owns the Attr. This is hugely expensive, and
 * if at all possible you should use the DOM Level 2 Attr.ownerElement()
 * method instead.
 *  <p>
 * The DOM Level 1 developers expected that folks would keep track
 * of the last Element they'd seen and could recover the info from
 * that source. Obviously that doesn't work very well if the only
 * information you've been presented with is the Attr. The DOM Level 2
 * getOwnerElement() method fixes that, but only for Level 2 and
 * later DOMs.
 *
 * @param elem Element whose subtree is to be searched for this Attr
 * @param attr Attr whose owner is to be located.
 *
 * @return the first Element whose attribute list includes the provided
 * attr. In modern DOMs, this will also be the only such Element. (Early
 * DOMs had some hope that Attrs might be sharable, but this idea has
 * been abandoned.)
 */
private static Node locateAttrParent(Element elem, Node attr)
{

  Node parent = null;

      // This should only be called for Level 1 DOMs, so we don't have to
      // worry about namespace issues. In later levels, it's possible
      // for a DOM to have two Attrs with the same NodeName but
      // different namespaces, and we'd need to get getAttributeNodeNS...
      // but later levels also have Attr.getOwnerElement.
      Attr check=elem.getAttributeNode(attr.getNodeName());
      if(check==attr)
              parent = elem;

  if (null == parent)
  {
    for (Node node = elem.getFirstChild(); null != node;
            node = node.getNextSibling())
    {
      if (Node.ELEMENT_NODE == node.getNodeType())
      {
        parent = locateAttrParent((Element) node, attr);

        if (null != parent)
          break;
      }
    }
  }

  return parent;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:53,代码来源:DOMHelper.java

示例7: getAttribute

import org.w3c.dom.Element; //导入方法依赖的package包/类
/**
 * Returns the value of an attribute of an element. Returns null
 * if the attribute is not found (whereas Element.getAttribute
 * returns "" if an attrib is not found).
 *
 * @param el       Element whose attrib is looked for
 * @param attrName name of attribute to look for
 * @return the attribute value
 */
static public String getAttribute (Element el, String attrName) {
    String sRet = null;
    Attr   attr = el.getAttributeNode(attrName);
    
    if (attr != null) {
        sRet = attr.getValue();
    }
    return sRet;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:19,代码来源:DOMUtils.java

示例8: getXmlAttrString

import org.w3c.dom.Element; //导入方法依赖的package包/类
public static String getXmlAttrString(Element element, String name) {
  Attr at = element.getAttributeNode(name);
  if (at != null) {
    return at.getValue();
  }
  return null;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:8,代码来源:WebServicesTestUtils.java

示例9: getAttributeValueFrom

import org.w3c.dom.Element; //导入方法依赖的package包/类
private static String getAttributeValueFrom(
    Element element,
    String uri,
    String localName,
    String prefix,
    String qualifiedName) {

    String nonzeroLengthUri =
        (uri == null || uri.length() == 0) ? null : uri;

    boolean mustUseGetAttributeNodeNS =  (nonzeroLengthUri != null);

    if (mustUseGetAttributeNodeNS) {

        if (!element.hasAttributeNS(uri, localName)) {
            return null;
        }

        String attrValue =
            element.getAttributeNS(nonzeroLengthUri, localName);

        return attrValue;
    }

    Attr attribute = null;
    attribute = element.getAttributeNode(qualifiedName);

    return attribute == null ? null : attribute.getValue();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:ElementImpl.java

示例10: testRemoveAttributeNode

import org.w3c.dom.Element; //导入方法依赖的package包/类
@Test
public void testRemoveAttributeNode() throws Exception {
    Document document = createDOMWithNS("ElementSample01.xml");
    Element elemNode = (Element) document.getElementsByTagName("book").item(1);
    Attr attr = elemNode.getAttributeNode("category1");
    assertEquals(attr.getValue(), "research");

    assertEquals(elemNode.getTagName(), "book");
    elemNode.removeAttributeNode(attr);
    assertEquals(elemNode.getAttribute("category1"), "");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:ElementTest.java

示例11: testGetSpecified2

import org.w3c.dom.Element; //导入方法依赖的package包/类
@Test
public void testGetSpecified2() throws Exception {

    Document document = createDOM("Attr2.xml");
    Element elemNode = (Element) document.getElementsByTagName("Name").item(0);
    Attr attr = elemNode.getAttributeNode("type");

    assertFalse(attr.getSpecified());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:AttrTest.java

示例12: JDBCProperties

import org.w3c.dom.Element; //导入方法依赖的package包/类
public JDBCProperties(Element driverElement, boolean userDefined) throws Exception {
    this.userDefined = userDefined;
    Attr nameAttr = driverElement.getAttributeNode("name");
    Attr driversAttr = driverElement.getAttributeNode("drivers");
    Attr portAttr = driverElement.getAttributeNode("defaultport");
    Attr urlAttr = driverElement.getAttributeNode("urlprefix");
    Attr dbNameAttr = driverElement.getAttributeNode("dbnameseparator");
    if(dbNameAttr == null) {
        dbNameAttr = driverElement.getAttributeNode("dbnameseperator");
    }

    Attr driverJarAttr = driverElement.getAttributeNode("driver_jar");
    if(nameAttr == null) {
        throw new Exception("Missing name for <driver> tag");
    } else {
        this.setName(nameAttr.getValue());
        if(portAttr == null) {
            throw new Exception("Missing defaultport for <driver> tag for driver \'" + this.getName() + "\'");
        } else if(urlAttr == null) {
            throw new Exception("Missing urlprefix for <driver> tag for driver \'" + this.getName() + "\'");
        } else {
            if(driversAttr == null) {
                LogService.getRoot().log(Level.WARNING, "com.rapidminer.tools.jdbc.JDBCProperties.missing_database_driver_class", this.getName());
            }

            this.setDefaultPort(portAttr.getValue());
            this.setUrlPrefix(urlAttr.getValue());
            this.dbNameSeperator = dbNameAttr != null?dbNameAttr.getValue():"/";
            if(driversAttr != null) {
                String value = driversAttr.getValue();
                this.setDriverClasses(value);
            } else {
                this.drivers = new String[0];
            }

            if(driverJarAttr != null) {
                this.setDriverJarFile(driverJarAttr.getValue());
            } else {
                this.setDriverJarFile((String)null);
            }

        }
    }
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:45,代码来源:JDBCProperties.java

示例13: parseInputDocument

import org.w3c.dom.Element; //导入方法依赖的package包/类
@Override
public void parseInputDocument(Context context) throws EngineException {
	super.parseInputDocument(context);

	if (context.inputDocument != null && Engine.logContext.isInfoEnabled()) {
		Document printDoc = (Document) Visibility.Logs.replaceVariables(getVariablesList(), context.inputDocument);
		XMLUtils.logXml(printDoc, Engine.logContext, "Input document");
	}
	
	NodeList variableNodes = context.inputDocument.getElementsByTagName("variable");
	int len = variableNodes.getLength();
	
	variables.clear();
	
	for (int i = 0 ; i < len ; i++) {
		Element variableNode = (Element) variableNodes.item(i);
		String variableName = variableNode.getAttribute("name");
		String variableValue = (variableNode.hasAttribute("value") ? variableNode.getAttribute("value") : null);
		Attr valueAttrNode = variableNode.getAttributeNode("value");
		
		// Test case for sequence
		if (variableName.indexOf(Parameter.Testcase.getName()) == 0) {
			TestCase testcase = getTestCaseByName(variableValue);
			if (testcase != null) {
				String testCaseVariableName;
				Object testCaseVariableValue;
				// Add test case variables default value(s)
				for (TestCaseVariable testCaseVariable: testcase.getVariables()) {
					testCaseVariableName = testCaseVariable.getName();
					testCaseVariableValue = testcase.getVariableValue(testCaseVariableName);
					if (testCaseVariableValue != null) {
						variables.put(testCaseVariableName, testCaseVariableValue);
					}
				}
			}
			else {
				if (Engine.logBeans.isInfoEnabled())
					Engine.logBeans.warn("Sequence: there's no testcase named '" + variableValue + "' for '" +  getName() + "' sequence");
			}
			continue;
		}
		
		// Standard variable case
		RequestableVariable variable = (RequestableVariable) getVariable(variableName);
		
		// Structured value?
		Object scopeValue = (variableValue != null) ? variableValue : variableNode.getChildNodes();
		
		// Multivalued variable ?
		if ((variable != null) && (variable.isMultiValued())) {
			List<Object> current = GenericUtils.cast(variables.get(variableName));
			if (current == null) {
				current = new LinkedList<Object>();
				variables.put(variableName, current);
			}
			if (variableValue == null || valueAttrNode != null) {
				current.add(scopeValue);
			}
		} else {
			variables.put(variableName, scopeValue);
		}
	}
	
	// Enumeration of all sequence variables
	if (Engine.logBeans.isDebugEnabled())
		Engine.logBeans.debug("Sequence variables: " + (variables == null ? "none" : Visibility.Logs.replaceVariables(getVariablesList(), variables)));
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:68,代码来源:Sequence.java

示例14: getAttributeOrNull

import org.w3c.dom.Element; //导入方法依赖的package包/类
public static String getAttributeOrNull(Element e, String name) {
    Attr a = e.getAttributeNode(name);
    if (a == null)
        return null;
    return a.getValue();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:7,代码来源:XmlUtil.java

示例15: getAttribute

import org.w3c.dom.Element; //导入方法依赖的package包/类
final static String getAttribute(Element e,String attName) {
    if(e.getAttributeNode(attName)==null)   return null;
    return e.getAttribute(attName);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:5,代码来源:DOMUtil.java


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