org.jdom2.Element.getName()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(127)

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

Element.getName介绍

[英]Returns the (local) name of the element (without any namespace prefix).
[中]返回元素的(本地)名称(不带任何命名空间前缀)。

代码示例

代码示例来源:origin: com.thoughtworks.xstream/xstream

public String peekNextChild() {
    List list = currentElement.getChildren();
    if (null == list || list.isEmpty()) {
      return null;
    }
    return decodeNode(((Element) list.get(0)).getName());
  }
}

代码示例来源:origin: org.jdom/jdom

final String ename = ((Element) content).getName();
final List<?> sibs = pnt == null ? null : pnt
    .getChildren(ename);
return getPositionPath(content, sibs, ename, buffer);
  pnt.getChildren(emt.getName(), emt.getNamespace());
String xps = "*[local-name() = '" + emt.getName() + 
    "' and namespace-uri() = '" + 
    emt.getNamespaceURI() + "']";

代码示例来源:origin: miltonio/milton2

public static Set<QName> getProps(Document doc, Namespace propNs) {
    Element elProp = doc.getRootElement().getChild("prop", propNs);
    if (elProp == null) {
      throw new RuntimeException("No prop element");
    }

    Set<QName> set = new HashSet<QName>();
    for (Object o : elProp.getChildren()) {
      if (o instanceof Element) {
        Element el = (Element) o;
        String local = el.getName();
        String ns = el.getNamespaceURI();
        set.add(new QName(ns, local, el.getNamespacePrefix()));
      }
    }
    return set;
  }
}

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

private Class<?> findTypeOfField() {
  Class<?> type = field.getType();
  if (isInterface(type)) {
    for (Element subElement : (List<Element>) e.getChildren()) {
      Class<?> concreteType = findConcreteTypeFrom(subElement, type);
      if (concreteType != null) {
        return concreteType;
      }
    }
    boolean optional = annotationFor(field, ConfigSubtag.class).optional();
    if (optional) { return null; }
    throw bomb("Unable to find a tag of type '" + type.getSimpleName() + "' under element '" + e.getName()
        + "'");
  }
  return field.getType();
}

代码示例来源:origin: miltonio/milton2

private Set<QName> getProps(Document doc) {
    Element elProp = doc.getRootElement().getChild("prop", NS_DAV);
    if (elProp == null) {
      throw new RuntimeException("No prop element");
    }

    Set<QName> set = new HashSet<QName>();
    for (Object o : elProp.getChildren()) {
      if (o instanceof Element) {
        Element el = (Element) o;
        String local = el.getName();
        String ns = el.getNamespaceURI();
        set.add(new QName(ns, local, el.getNamespacePrefix()));
      }
    }
    return set;
  }
}

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

@SuppressWarnings("unchecked")
private Collection parseCollection(Element e, Class<?> collectionType) {
  ConfigCollection collection = collectionType.getAnnotation(ConfigCollection.class);
  Class<?> type = collection.value();
  Object o = newInstance(collectionType);
  bombUnless(o instanceof Collection,
      "Must be some sort of list. Was: " + collectionType.getName());
  Collection baseCollection = (Collection) o;
  for (Element childElement : (List<Element>) e.getChildren()) {
    if (isInCollection(childElement, type)) {
      baseCollection.add(parseType(childElement, type));
    }
  }
  bombIf(baseCollection.size() < collection.minimum(),
      "Required at least " + collection.minimum() + " subelements to '" + e.getName() + "'. "
          + "Found " + baseCollection.size() + ".");
  return baseCollection;
}

代码示例来源:origin: miltonio/milton2

private Set<QName> getProps(Document doc) {
    Element elProp = doc.getRootElement().getChild("prop", NS_DAV);
    if (elProp == null) {
      throw new RuntimeException("No prop element");
    }

    Set<QName> set = new HashSet<QName>();
    for (Object o : elProp.getChildren()) {
      if (o instanceof Element) {
        Element el = (Element) o;
        String local = el.getName();
        String ns = el.getNamespaceURI();
        set.add(new QName(ns, local, el.getNamespacePrefix()));
      }
    }
    return set;
  }
}

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

@SuppressWarnings("unchecked")
private void parseCollection(Collection collection) {
  ConfigCollection collectionAnnotation = annotationFor(aClass, ConfigCollection.class);
  Class<?> elementType = collectionAnnotation.value();
  for (Element childElement : (List<Element>) e.getChildren()) {
    if (isInCollection(childElement, elementType)) {
      Class<?> collectionType = findConcreteType(childElement, elementType);
      collection.add(classParser(childElement, collectionType, configCache, new GoCipher(), registry, configReferenceElements).parse());
    }
  }
  int minimumSize = collectionAnnotation.minimum();
  bombIf(collection.size() < minimumSize,
      "Required at least " + minimumSize + " subelements to '" + e.getName() + "'. "
          + "Found " + collection.size() + ".");
}

代码示例来源:origin: miltonio/milton2

private Set<QName> getProps(Document doc) {
    Element elProp = doc.getRootElement().getChild("prop", NS_DAV);
    if (elProp == null) {
      throw new RuntimeException("No prop element");
    }

    Set<QName> set = new HashSet<QName>();
    for (Object o : elProp.getChildren()) {
      if (o instanceof Element) {
        Element el = (Element) o;
        String local = el.getName();
        String ns = el.getNamespaceURI();
        set.add(new QName(ns, local, el.getNamespacePrefix()));
      }
    }
    return set;
  }
}

代码示例来源:origin: jwpttcg66/NettyGameServer

public static void loadFormat(String folderPath, List<MessageObject> list) throws JDOMException, IOException{

    File file =  FileUtil.getFile(folderPath);
    if(!file.exists() || file.isFile()){
      return ;
    }
    folderPath = file.getPath();
    String[] xmlFileNames = file.list();
    for(String xmlFileName : xmlFileNames){
      Document doc = new SAXBuilder().build(new File(folderPath, xmlFileName));
      Element root = doc.getRootElement();
      if(!"messages".equals(root.getName())){
        continue;
      }
      for(Element message : root.getChildren()){
        list.add(new MessageObject(message));
      }
    }
  }
}

代码示例来源:origin: jwpttcg66/NettyGameServer

public static void loadMacro(String folderPath) throws JDOMException, IOException{

    File file =  FileUtil.getFile(folderPath);
//        File file = new File(url.getFile());
    if(!file.exists() || file.isFile()){
      return;
    }
    folderPath = file.getPath();
    String[] xmlFileNames = file.list();
    for(String xmlFileName : xmlFileNames){
      Document doc = new SAXBuilder().build(new File(folderPath,xmlFileName));
      Element root = doc.getRootElement();
      if(!"macros".equals(root.getName())){
        continue;
      }
      for(Element macro : root.getChildren()){
        new MacroObject(macro);
      }
    }

  }

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

public void assignTo(Element element) {
  if (!element.getName().equals(GeoTiffConstants.GEOTIFF_IIO_ROOT_ELEMENT_NAME)) {
    throw new IllegalArgumentException(
        "root not found: " + GeoTiffConstants.GEOTIFF_IIO_ROOT_ELEMENT_NAME);
  }
  final Element ifd1 = element.getChild(GeoTiffConstants.GEOTIFF_IFD_TAG);
  if (ifd1 == null) {
    throw new IllegalArgumentException(
        "Unable to find child " + GeoTiffConstants.GEOTIFF_IFD_TAG);
  }
  final Element ifd2 = createIFD();
  ifd1.setAttribute(
      GeoTiffConstants.GEOTIFF_TAGSETS_ATT_NAME,
      ifd2.getAttributeValue(GeoTiffConstants.GEOTIFF_TAGSETS_ATT_NAME));
  final Element[] childElems = (Element[]) ifd2.getChildren().toArray(new Element[0]);
  for (int i = 0; i < childElems.length; i++) {
    final Element child = childElems[i];
    ifd2.removeContent(child);
    ifd1.addContent(child);
  }
}

代码示例来源:origin: x-stream/xstream

@Override
  public String peekNextChild() {
    final List<Element> list = currentElement.getChildren();
    if (null == list || list.isEmpty()) {
      return null;
    }
    return decodeNode(list.get(0).getName());
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.xstream-java8

public String peekNextChild() {
    List list = currentElement.getChildren();
    if (null == list || list.isEmpty()) {
      return null;
    }
    return decodeNode(((Element) list.get(0)).getName());
  }
}

代码示例来源:origin: org.sonatype.nexus.xstream/xstream

public String peekNextChild() {
    List list = currentElement.getChildren();
    if (null == list || list.isEmpty()) {
      return null;
    }
    return decodeNode(((Element) list.get(0)).getName());
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.xstream

public String peekNextChild() {
    List list = currentElement.getChildren();
    if (null == list || list.isEmpty()) {
      return null;
    }
    return decodeNode(((Element) list.get(0)).getName());
  }
}

代码示例来源:origin: pl.edu.icm.synat/synat-importer-yadda

private List<Element> getElements(Document inputDocument) {
  List<Element> elements = new ArrayList<>();
  Element root = inputDocument.getRootElement();
  if (BwmetaStrings.E_BWMETA.equals(root.getName())) {
    elements.addAll(root.getChildren());
  } else {
    elements.add(root);
  }
  return elements;
}

代码示例来源:origin: org.opencadc/caom2

protected List getChildrenElements(String name, Element element, Namespace ns, boolean required)
  throws ObservationParsingException
{
  List children = element.getChildren(name, ns);
  if (required && children.isEmpty())
  {
    String error = name + " element not found in " + element.getName();
    throw new ObservationParsingException(error);
  }
  return children;
}

代码示例来源:origin: apache/servicemix-bundles

public String peekNextChild() {
    List list = currentElement.getChildren();
    if (null == list || list.isEmpty()) {
      return null;
    }
    return decodeNode(((Element) list.get(0)).getName());
  }
}

代码示例来源:origin: com.theoryinpractise/halbuilder-xml

private void readProperties(Representation resource, Element element) {
  List<Element> properties = element.getChildren();
  for (Element property : properties) {
    if (!property.getName().matches("(link|resource)")) {
      if (property.getAttribute("nil", XSI_NAMESPACE) != null) {
        resource.withProperty(property.getName(), null);
      } else {
        resource.withProperty(property.getName(), property.getValue());
      }
    }
  }
}

相关文章

微信公众号

最新文章

更多