本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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"), "");
}
示例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());
}
示例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);
}
}
}
}
示例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)));
}
示例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();
}
示例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);
}