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

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

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

Element.getTagName介绍

[英]The name of the element. If Node.localName is different from null, this attribute is a qualified name. For example, in:

<elementExample id="demo"> ... 
</elementExample> ,

tagName has the value "elementExample". Note that this is case-preserving in XML, as are all of the operations of the DOM. The HTML DOM returns the tagName of an HTML element in the canonical uppercase form, regardless of the case in the source HTML document.
[中]元素的名称。如果Node.localNamenull不同,则此属性是限定名。例如,in:

<elementExample id="demo"> ... 
</elementExample> ,

tagName具有值"elementExample"。注意,这在XML中是保留大小写的,DOM的所有操作也是如此。HTML DOM以规范大写形式返回HTML元素的tagName,而不管源HTML文档中的大小写。

代码示例

代码示例来源:origin: org.apache.ant/ant

@Override
  public String toString() {
    return element.getTagName() + ":" + element.getAttribute("name");
  }
}

代码示例来源:origin: Tencent/tinker

private void readPackageConfigFromXml(Node node) throws IOException {
  NodeList childNodes = node.getChildNodes();
  if (childNodes.getLength() > 0) {
    for (int j = 0, n = childNodes.getLength(); j < n; j++) {
      Node child = childNodes.item(j);
      if (child.getNodeType() == Node.ELEMENT_NODE) {
        Element check = (Element) child;
        String tagName = check.getTagName();
        String value = check.getAttribute(ATTR_VALUE);
        String name = check.getAttribute(ATTR_NAME);
        if (tagName.equals(ATTR_CONFIG_FIELD)) {
          mPackageFields.put(name, value);
        } else {
          System.err.println("unknown package config tag " + tagName);
        }
      }
    }
  }
}

代码示例来源: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: apache/geode

private StatisticsType[] extractStatistics(Element root, StatisticsTypeFactory statFactory) {
 Assert.assertTrue(root.getTagName().equals("statistics"));
 ArrayList types = new ArrayList();
 NodeList typeNodes = root.getElementsByTagName("type");
 for (int i = 0; i < typeNodes.getLength(); i++) {
  Element typeNode = (Element) typeNodes.item(i);
  types.add(extractType(typeNode, statFactory));
 }
 return (StatisticsType[]) types.toArray(new StatisticsType[types.size()]);
}

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

private static XmlDom convert(Node node, String tag, String attr, String value){
  
  if(node.getNodeType() != Node.ELEMENT_NODE){
    return null;
  }
  
  Element e = (Element) node;
  
  XmlDom result = null;
  
  if(tag == null || tag.equals(e.getTagName())){		
    if(attr == null || e.hasAttribute(attr)){			
      if(value == null || value.equals(e.getAttribute(attr))){
        result = new XmlDom(e);
      }
    }
  }
  
  return result;
}

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

/**
 * Check if the List of Elements contains any TOKENS that have PHONE descendants
 * 
 * @param tokensAndBoundaries
 *            the List of Elements to check for PHONE elements
 * @return true once a PHONE has been found within a TOKEN, false if this never happens
 */
private boolean containsPhoneDescendants(List<Element> tokensAndBoundaries) {
  for (Element element : tokensAndBoundaries) {
    if (element.getTagName().equals(MaryXML.TOKEN) && element.getElementsByTagName(MaryXML.PHONE).getLength() > 0) {
      return true;
    }
  }
  return false;
}

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

/**
 * Get the next sibling of <code>e</code> which is an element and has tag name <code>name</code>, or <code>null</code> if
 * there is no such element.
 * 
 * @param e
 *            e
 * @param name
 *            name
 * @return null if n is null, true otherwise
 */
public static Element getNextSiblingElementByTagName(Element e, String name) {
  Node n = e;
  if (n == null)
    return null;
  while ((n = n.getNextSibling()) != null) {
    if (n.getNodeType() == Node.ELEMENT_NODE && ((Element) n).getTagName().equals(name))
      return (Element) n;
  }
  return null;
}

代码示例来源:origin: Tencent/tinker

private void readLibPatternsFromXml(Node node) throws IOException {
  NodeList childNodes = node.getChildNodes();
  if (childNodes.getLength() > 0) {
    for (int j = 0, n = childNodes.getLength(); j < n; j++) {
      Node child = childNodes.item(j);
      if (child.getNodeType() == Node.ELEMENT_NODE) {
        Element check = (Element) child;
        String tagName = check.getTagName();
        String value = check.getAttribute(ATTR_VALUE);
        if (tagName.equals(ATTR_PATTERN)) {
          addToPatterns(value, mSoFilePattern);
        } else {
          System.err.println("unknown dex tag " + tagName);
        }
      }
    }
  }
}

代码示例来源: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: marytts/marytts

public InstallFileParser(URL installFile) throws IOException, SAXException {
  Document doc;
  try {
    InputStream in = installFile.openStream();
    doc = builder.parse(in);
    in.close();
  } catch (Exception e) {
    throw new IOException("Problem parsing install file " + installFile, e);
  }
  Element docElt = doc.getDocumentElement();
  if (!docElt.getTagName().equals("marytts-install")) {
    throw new IllegalArgumentException("Expected <marytts-install> document, but found root node <" + docElt.getTagName()
        + ">!");
  }
  NodeList languageElements = docElt.getElementsByTagName("language");
  for (int i = 0, max = languageElements.getLength(); i < max; i++) {
    Element languageElement = (Element) languageElements.item(i);
    languages.add(new LanguageComponentDescription(languageElement));
  }
  NodeList voiceElements = docElt.getElementsByTagName("voice");
  for (int i = 0, max = voiceElements.getLength(); i < max; i++) {
    Element voiceElement = (Element) voiceElements.item(i);
    voices.add(new VoiceComponentDescription(voiceElement));
  }
}

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

public static String getPhoneSymbol(Element segmentOrBoundary) {
  String phone;
  if (segmentOrBoundary.getTagName().equals(MaryXML.PHONE)) {
    phone = segmentOrBoundary.getAttribute("p");
  } else {
    assert segmentOrBoundary.getTagName().equals(MaryXML.BOUNDARY) : "Expected boundary element, but got "
        + segmentOrBoundary.getTagName();
    // TODO: how can we know the silence symbol here?
    phone = "_";
  }
  return phone;
}

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

/**
 * Check if the List of Elements contains any TOKENS that have PHONE descendants
 * 
 * @param tokensAndBoundaries
 *            the List of Elements to check for PHONE elements
 * @return true once a PHONE has been found within a TOKEN, false if this never happens
 */
private boolean containsPhoneDescendants(List<Element> tokensAndBoundaries) {
  for (Element element : tokensAndBoundaries) {
    if (element.getTagName().equals(MaryXML.TOKEN) && element.getElementsByTagName(MaryXML.PHONE).getLength() > 0) {
      return true;
    }
  }
  return false;
}

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

/**
 * Get the previous sibling of <code>e</code> which is an element and has tag name <code>name</code>, or <code>null</code> if
 * there is no such element.
 * 
 * @param e
 *            e
 * @param name
 *            name
 * @return null if n is null
 */
public static Element getPreviousSiblingElementByTagName(Element e, String name) {
  Node n = e;
  if (n == null)
    return null;
  while ((n = n.getPreviousSibling()) != null) {
    if (n.getNodeType() == Node.ELEMENT_NODE && ((Element) n).getTagName().equals(name))
      return (Element) n;
  }
  return null;
}

代码示例来源:origin: Tencent/tinker

private void readDexPatternsFromXml(Node node) throws IOException {
  NodeList childNodes = node.getChildNodes();
  if (childNodes.getLength() > 0) {
    for (int j = 0, n = childNodes.getLength(); j < n; j++) {
      Node child = childNodes.item(j);
      if (child.getNodeType() == Node.ELEMENT_NODE) {
        Element check = (Element) child;
        String tagName = check.getTagName();
        String value = check.getAttribute(ATTR_VALUE);
        if (tagName.equals(ATTR_DEX_MODE)) {
          if (value.equals("raw")) {
            mDexRaw = true;
          }
        } else if (tagName.equals(ATTR_PATTERN)) {
          addToPatterns(value, mDexFilePattern);
        } else if (tagName.equals(ATTR_LOADER)) {
          mDexLoaderPattern.add(value);
        } else if (tagName.equals(ATTR_IGNORE_CHANGE)) {
          mDexIgnoreWarningLoaderPattern.add(value);
        } else {
          System.err.println("unknown dex tag " + tagName);
        }
      }
    }
  }
}

代码示例来源: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: marytts/marytts

public InstallFileParser(URL installFile) throws IOException, SAXException {
  Document doc;
  try {
    InputStream in = installFile.openStream();
    doc = builder.parse(in);
    in.close();
  } catch (Exception e) {
    throw new IOException("Problem parsing install file " + installFile, e);
  }
  Element docElt = doc.getDocumentElement();
  if (!docElt.getTagName().equals("marytts-install")) {
    throw new IllegalArgumentException("Expected <marytts-install> document, but found root node <" + docElt.getTagName()
        + ">!");
  }
  NodeList languageElements = docElt.getElementsByTagName("language");
  for (int i = 0, max = languageElements.getLength(); i < max; i++) {
    Element languageElement = (Element) languageElements.item(i);
    languages.add(new LanguageComponentDescription(languageElement));
  }
  NodeList voiceElements = docElt.getElementsByTagName("voice");
  for (int i = 0, max = voiceElements.getLength(); i < max; i++) {
    Element voiceElement = (Element) voiceElements.item(i);
    voices.add(new VoiceComponentDescription(voiceElement));
  }
}

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

@Override
public ServiceConfiguration<XAStore.Provider> parseServiceConfiguration(Element fragment, ClassLoader classLoader) {
 String localName = fragment.getLocalName();
 if ("xa-store".equals(localName)) {
  String uniqueXAResourceId = fragment.getAttribute("unique-XAResource-id");
  return new XAStoreConfiguration(uniqueXAResourceId);
 } else {
  throw new XmlConfigurationException(String.format("XML configuration element <%s> in <%s> is not supported",
    fragment.getTagName(), (fragment.getParentNode() == null ? "null" : fragment.getParentNode().getLocalName())));
 }
}

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

/**
 * Get the next sibling of <code>e</code> which is an element and has tag name <code>name</code>, or <code>null</code> if
 * there is no such element.
 * 
 * @param e
 *            e
 * @param name
 *            name
 * @return null if n is null, true otherwise
 */
public static Element getNextSiblingElementByTagName(Element e, String name) {
  Node n = e;
  if (n == null)
    return null;
  while ((n = n.getNextSibling()) != null) {
    if (n.getNodeType() == Node.ELEMENT_NODE && ((Element) n).getTagName().equals(name))
      return (Element) n;
  }
  return null;
}

代码示例来源:origin: Tencent/tinker

private void readPropertyFromXml(Node node) throws IOException {
  NodeList childNodes = node.getChildNodes();
  if (childNodes.getLength() > 0) {
    for (int j = 0, n = childNodes.getLength(); j < n; j++) {
      Node child = childNodes.item(j);
      if (child.getNodeType() == Node.ELEMENT_NODE) {
        Element check = (Element) child;
        String tagName = check.getTagName();
        String value = check.getAttribute(ATTR_VALUE);
        if (value.length() == 0) {
          throw new IOException(

代码示例来源: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);
  }
}

相关文章

微信公众号

最新文章

更多