org.w3c.dom.Element.hasAttribute()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(264)

本文整理了Java中org.w3c.dom.Element.hasAttribute()方法的一些代码示例,展示了Element.hasAttribute()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.hasAttribute()方法的具体详情如下:
包路径:org.w3c.dom.Element
类名称:Element
方法名:hasAttribute

Element.hasAttribute介绍

[英]Returns true when an attribute with a given name is specified on this element or has a default value, false otherwise.
[中]当在此元素上指定了具有给定名称的属性或具有默认值时,返回true,否则返回false

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
protected String getBeanClassName(Element element) {
  if (element.hasAttribute(WEAVER_CLASS_ATTRIBUTE)) {
    return element.getAttribute(WEAVER_CLASS_ATTRIBUTE);
  }
  return DEFAULT_LOAD_TIME_WEAVER_CLASS_NAME;
}

代码示例来源:origin: marytts/marytts

public short acceptNode(Node n) {
    if (!(n instanceof Element))
      return NodeFilter.FILTER_SKIP;
    Element e = (Element) n;
    if (e.getTagName().equals(MaryXML.TOKEN) && e.hasAttribute("ending"))
      return NodeFilter.FILTER_ACCEPT;
    return NodeFilter.FILTER_SKIP;
  }
}, true);

代码示例来源:origin: marytts/marytts

protected void setPh(Element t, String ph) {
  if (!t.getTagName().equals(MaryXML.TOKEN))
    throw new DOMException(DOMException.INVALID_ACCESS_ERR, "Only t elements allowed, received " + t.getTagName() + ".");
  if (t.hasAttribute("ph")) {
    String prevPh = t.getAttribute("ph");
    // In previous sampa, replace star with sampa:
    String newPh = prevPh.replaceFirst("\\*", ph);
    t.setAttribute("ph", newPh);
  } else {
    t.setAttribute("ph", ph);
  }
}

代码示例来源:origin: ehcache/ehcache3

@Override
public ServiceCreationConfiguration<Jsr107Service> parseServiceCreationConfiguration(final Element fragment, ClassLoader classLoader) {
 boolean jsr107CompliantAtomics = true;
 ConfigurationElementState enableManagementAll = ConfigurationElementState.UNSPECIFIED;
 ConfigurationElementState enableStatisticsAll = ConfigurationElementState.UNSPECIFIED;
 if (fragment.hasAttribute(JSR_107_COMPLIANT_ATOMICS_ATTRIBUTE)) {
  jsr107CompliantAtomics = parseBoolean(fragment.getAttribute(JSR_107_COMPLIANT_ATOMICS_ATTRIBUTE));
 }
 if (fragment.hasAttribute(ENABLE_MANAGEMENT_ALL_ATTRIBUTE)) {
  enableManagementAll = parseBoolean(fragment.getAttribute(ENABLE_MANAGEMENT_ALL_ATTRIBUTE)) ? ConfigurationElementState.ENABLED : ConfigurationElementState.DISABLED;
 }
 if (fragment.hasAttribute(ENABLE_STATISTICS_ALL_ATTRIBUTE)) {
  enableStatisticsAll = parseBoolean(fragment.getAttribute(ENABLE_STATISTICS_ALL_ATTRIBUTE)) ? ConfigurationElementState.ENABLED : ConfigurationElementState.DISABLED;
 }
 final String defaultTemplate = fragment.getAttribute(DEFAULT_TEMPLATE_ATTRIBUTE);
 final HashMap<String, String> templates = new HashMap<>();
 final NodeList childNodes = fragment.getChildNodes();
 for (int i = 0; i < childNodes.getLength(); i++) {
  final Node node = childNodes.item(i);
  if (node.getNodeType() == Node.ELEMENT_NODE) {
   final Element item = (Element)node;
   templates.put(item.getAttribute(CACHE_NAME_ATTRIBUTE), item.getAttribute(TEMPLATE_NAME_ATTRIBUTE));
  }
 }
 return new Jsr107Configuration(defaultTemplate, templates, jsr107CompliantAtomics, enableManagementAll, enableStatisticsAll);
}

代码示例来源:origin: marytts/marytts

private void createSubStructure(Element token, AllophoneSet allophoneSet) {
  String phone = token.getAttribute("ph");
  if (phone.equals(""))
    return; // nothing to do
  if (token.getElementsByTagName(MaryXML.SYLLABLE).getLength() > 0) {
    return; // there is already a substructure under this token; nothing to do
    String volumeString = prosody.getAttribute("volume");
    int volume = -1;
    try {
      if (token.hasAttribute("accent")) {
        syllable.setAttribute("accent", token.getAttribute("accent"));

代码示例来源:origin: alibaba/cobar

private void loadSchemas(Element root) {
  NodeList list = root.getElementsByTagName("schema");
  for (int i = 0, n = list.getLength(); i < n; i++) {
    Element schemaElement = (Element) list.item(i);
    String name = schemaElement.getAttribute("name");
    String dataNode = schemaElement.getAttribute("dataNode");
    // 在非空的情况下检查dataNode是否存在
    if (dataNode != null && dataNode.length() != 0) {
      checkDataNodeExists(dataNode);
    } else {
      dataNode = "";// 确保非空
    }
    String group = "default";
    if (schemaElement.hasAttribute("group")) {
      group = schemaElement.getAttribute("group").trim();
    }
    Map<String, TableConfig> tables = loadTables(schemaElement);
    if (schemas.containsKey(name)) {
      throw new ConfigException("schema " + name + " duplicated!");
    }
    boolean keepSqlSchema = false;
    if (schemaElement.hasAttribute("keepSqlSchema")) {
      keepSqlSchema = Boolean.parseBoolean(schemaElement.getAttribute("keepSqlSchema").trim());
    }
    schemas.put(name, new SchemaConfig(name, dataNode, group, keepSqlSchema, tables));
  }
}

代码示例来源:origin: marytts/marytts

protected void setPh(Element t, String ph) {
  if (!t.getTagName().equals(MaryXML.TOKEN))
    throw new DOMException(DOMException.INVALID_ACCESS_ERR, "Only t elements allowed, received " + t.getTagName() + ".");
  if (t.hasAttribute("ph")) {
    String prevPh = t.getAttribute("ph");
    // In previous sampa, replace star with sampa:
    String newPh = prevPh.replaceFirst("\\*", ph);
    t.setAttribute("ph", newPh);
  } else {
    t.setAttribute("ph", ph);
  }
}

代码示例来源:origin: spring-projects/spring-framework

static String extractCacheManager(Element element) {
  return (element.hasAttribute(CacheNamespaceHandler.CACHE_MANAGER_ATTRIBUTE) ?
      element.getAttribute(CacheNamespaceHandler.CACHE_MANAGER_ATTRIBUTE) :
      CacheNamespaceHandler.DEFAULT_CACHE_MANAGER_BEAN_NAME);
}

代码示例来源:origin: marytts/marytts

boolean hasRateAttribute = e.hasAttribute("rate");
boolean hasContourAttribute = e.hasAttribute("contour");
boolean hasPitchAttribute = e.hasAttribute("pitch");
if (nl.getLength() == 0) {
  continue;
  applySpeechRateSpecifications(nl, e.getAttribute("rate"));
    baseF0Contour = applyPitchSpecifications(nl, baseF0Contour, e.getAttribute("pitch"));
    baseF0Contour = applyContourSpecifications(nl, baseF0Contour, e.getAttribute("contour"));

代码示例来源:origin: marytts/marytts

public short acceptNode(Node n) {
    if (!(n instanceof Element))
      return NodeFilter.FILTER_SKIP;
    Element e = (Element) n;
    if (e.getTagName().equals(MaryXML.TOKEN) && e.hasAttribute("ending"))
      return NodeFilter.FILTER_ACCEPT;
    return NodeFilter.FILTER_SKIP;
  }
}, true);

代码示例来源:origin: pmd/pmd

/**
 * Check whether the given ruleName is contained in the given ruleset.
 *
 * @param ruleSetReferenceId the ruleset to check
 * @param ruleName           the rule name to search for
 *
 * @return {@code true} if the ruleName exists
 */
private boolean containsRule(RuleSetReferenceId ruleSetReferenceId, String ruleName) {
  boolean found = false;
  try (InputStream ruleSet = ruleSetReferenceId.getInputStream(resourceLoader)) {
    DocumentBuilder builder = createDocumentBuilder();
    Document document = builder.parse(ruleSet);
    Element ruleSetElement = document.getDocumentElement();
    NodeList rules = ruleSetElement.getElementsByTagName("rule");
    for (int i = 0; i < rules.getLength(); i++) {
      Element rule = (Element) rules.item(i);
      if (rule.hasAttribute("name") && rule.getAttribute("name").equals(ruleName)) {
        found = true;
        break;
      }
    }
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
  return found;
}

代码示例来源:origin: marytts/marytts

protected void setPh(Element t, String ph) {
  if (!t.getTagName().equals(MaryXML.TOKEN))
    throw new DOMException(DOMException.INVALID_ACCESS_ERR, "Only t elements allowed, received " + t.getTagName() + ".");
  if (t.hasAttribute("ph")) {
    String prevPh = t.getAttribute("ph");
    // In previous sampa, replace star with sampa:
    String newPh = prevPh.replaceFirst("\\*", ph);
    t.setAttribute("ph", newPh);
  } else {
    t.setAttribute("ph", ph);
  }
}

代码示例来源:origin: spring-projects/spring-framework

static String getTransactionManagerName(Element element) {
  return (element.hasAttribute(TRANSACTION_MANAGER_ATTRIBUTE) ?
      element.getAttribute(TRANSACTION_MANAGER_ATTRIBUTE) : DEFAULT_TRANSACTION_MANAGER_BEAN_NAME);
}

代码示例来源:origin: marytts/marytts

boolean hasRateAttribute = e.hasAttribute("rate");
boolean hasContourAttribute = e.hasAttribute("contour");
boolean hasPitchAttribute = e.hasAttribute("pitch");
if (nl.getLength() == 0) {
  continue;
  applySpeechRateSpecifications(nl, e.getAttribute("rate"));
    baseF0Contour = applyPitchSpecifications(nl, baseF0Contour, e.getAttribute("pitch"));
    baseF0Contour = applyContourSpecifications(nl, baseF0Contour, e.getAttribute("contour"));

代码示例来源:origin: marytts/marytts

public Element getElement(Target target) {
    Element segment = target.getMaryxmlElement();
    if (segment == null)
      return null;
    Element sentence = (Element) MaryDomUtils.getAncestor(segment, MaryXML.SENTENCE);
    if (sentence == null)
      return null;
    TreeWalker tw = MaryDomUtils.createTreeWalker(sentence, MaryXML.TOKEN);
    Element lastWord = null;
    Element lastToken = (Element) tw.lastChild();
    // The last word is the lastToken which has a "ph" attribute:
    while (lastToken != null) {
      if (lastToken.hasAttribute("ph")) {
        lastWord = lastToken;
        break;
      }
      lastToken = (Element) tw.previousNode();
    }
    if (lastWord != null) {
      assert lastWord.getTagName().equals(MaryXML.TOKEN) : "Unexpected tag name: expected " + MaryXML.TOKEN + ", got "
          + lastWord.getTagName();
    }
    return lastWord;
  }
}

代码示例来源:origin: marytts/marytts

for (int i = 0; i < nl.getLength(); i++) {
  Element e = (Element) nl.item(i);
  if (!e.hasAttribute("d")) {
    continue;
  double durAttribute = new Double(e.getAttribute("d")).doubleValue();
  double newDurAttribute = durAttribute + (incriment * percentage * durAttribute / 100);
  e.setAttribute("d", newDurAttribute + "");
Element e = (Element) nl.item(0);
for (int i = 0; (nd = (Element) nit.nextNode()) != null; i++) {
  if ("boundary".equals(nd.getNodeName())) {
    if (nd.hasAttribute("duration")) {
      duration += new Double(nd.getAttribute("duration")).doubleValue();
    if (nd.hasAttribute("d")) {
      duration += new Double(nd.getAttribute("d")).doubleValue();

代码示例来源:origin: marytts/marytts

protected void setPh(Element t, String ph) {
  if (!t.getTagName().equals(MaryXML.TOKEN))
    throw new DOMException(DOMException.INVALID_ACCESS_ERR, "Only t elements allowed, received " + t.getTagName() + ".");
  if (t.hasAttribute("ph")) {
    String prevPh = t.getAttribute("ph");
    // In previous sampa, replace star with sampa:
    String newPh = prevPh.replaceFirst("\\*", ph);
    t.setAttribute("ph", newPh);
  } else {
    t.setAttribute("ph", ph);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Nullable
private RuntimeBeanReference getMessageCodesResolver(Element element) {
  if (element.hasAttribute("message-codes-resolver")) {
    return new RuntimeBeanReference(element.getAttribute("message-codes-resolver"));
  }
  else {
    return null;
  }
}

代码示例来源:origin: stanfordnlp/CoreNLP

eRoot.getElementsByTagName(NODE_WORD).getLength() == 0) {
 String posStr = getPOS(eRoot);
 posStr = treeNormalizer.normalizeNonterminal(posStr);
boolean isMWE = rootLabel.equals("w") && eRoot.hasAttribute(ATTR_POS);
if(isMWE)
 rootLabel = eRoot.getAttribute(ATTR_POS).trim();

代码示例来源:origin: marytts/marytts

public Element getElement(Target target) {
    Element segment = target.getMaryxmlElement();
    if (segment == null)
      return null;
    Element sentence = (Element) MaryDomUtils.getAncestor(segment, MaryXML.SENTENCE);
    if (sentence == null)
      return null;
    TreeWalker tw = MaryDomUtils.createTreeWalker(sentence, MaryXML.TOKEN);
    Element lastWord = null;
    Element lastToken = (Element) tw.lastChild();
    // The last word is the lastToken which has a "ph" attribute:
    while (lastToken != null) {
      if (lastToken.hasAttribute("ph")) {
        lastWord = lastToken;
        break;
      }
      lastToken = (Element) tw.previousNode();
    }
    if (lastWord != null) {
      assert lastWord.getTagName().equals(MaryXML.TOKEN) : "Unexpected tag name: expected " + MaryXML.TOKEN + ", got "
          + lastWord.getTagName();
    }
    return lastWord;
  }
}

相关文章

微信公众号

最新文章

更多