本文整理了Java中org.jdom.Element.getChildren()
方法的一些代码示例,展示了Element.getChildren()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getChildren()
方法的具体详情如下:
包路径:org.jdom.Element
类名称:Element
方法名:getChildren
[英]This returns a List
of all the child elements nested directly (one level deep) within this element, as Element
objects. If this target element has no nested elements, an empty List is returned. The returned list is "live" in document order and changes to it affect the element's actual contents.
Sequential traversal through the List is best done with a Iterator since the underlying implement of List.size() may not be the most efficient.
No recursion is performed, so elements nested two levels deep would have to be obtained with:
Iterator itr = (currentElement.getChildren()).iterator();
while(itr.hasNext()) {
Element oneLevelDeep = (Element)itr.next();
List twoLevelsDeep = oneLevelDeep.getChildren();
// Do something with these children
}
[中]这将返回直接嵌套在该元素中的所有子元素的List
,作为Element
对象。如果此目标元素没有嵌套元素,则返回空列表。返回的列表在文档顺序中是“活动”的,对它的更改会影响元素的实际内容。
通过列表的顺序遍历最好使用迭代器完成,因为列表的底层实现是这样的。size()可能不是最有效的。
不执行递归,因此嵌套在两层深处的元素必须通过以下方式获得:
Iterator itr = (currentElement.getChildren()).iterator();
while(itr.hasNext()) {
Element oneLevelDeep = (Element)itr.next();
List twoLevelsDeep = oneLevelDeep.getChildren();
// Do something with these children
}
代码示例来源:origin: org.freemarker/freemarker
private void addChildren(Element element, List list) {
List children = element.getChildren();
Iterator it = children.iterator();
while (it.hasNext()) {
Element child = (Element) it.next();
list.add(child);
addChildren(child, list);
}
}
}
代码示例来源:origin: JetBrains/ideavim
public void readData(@NotNull Element element) {
final Element conflictsElement = element.getChild(SHORTCUT_CONFLICTS_ELEMENT);
if (conflictsElement != null) {
final java.util.List<Element> conflictElements = conflictsElement.getChildren(SHORTCUT_CONFLICT_ELEMENT);
for (Element conflictElement : conflictElements) {
final String ownerValue = conflictElement.getAttributeValue(OWNER_ATTRIBUTE);
ShortcutOwner owner = ShortcutOwner.UNDEFINED;
try {
owner = ShortcutOwner.fromString(ownerValue);
}
catch (IllegalArgumentException ignored) {
}
final Element textElement = conflictElement.getChild(TEXT_ELEMENT);
if (textElement != null) {
final String text = StringHelper.getSafeXmlText(textElement);
if (text != null) {
final KeyStroke keyStroke = KeyStroke.getKeyStroke(text);
if (keyStroke != null) {
shortcutConflicts.put(keyStroke, owner);
}
}
}
}
}
}
代码示例来源:origin: voldemort/voldemort
public static SerializerDefinition readSerializer(Element elmt) {
String name = elmt.getChild(STORE_SERIALIZATION_TYPE_ELMT).getText();
boolean hasVersion = true;
Map<Integer, String> schemaInfosByVersion = new HashMap<Integer, String>();
for(Object schemaInfo: elmt.getChildren(STORE_SERIALIZATION_META_ELMT)) {
Element schemaInfoElmt = (Element) schemaInfo;
String versionStr = schemaInfoElmt.getAttributeValue(STORE_VERSION_ATTR);
throw new IllegalArgumentException("Specified multiple schemas AND version=none, which is not permitted.");
Element compressionElmt = elmt.getChild(STORE_COMPRESSION_ELMT);
Compression compression = null;
if(compressionElmt != null)
代码示例来源:origin: jaxen/jaxen
Element node = (Element) contextNode;
if (namespaceURI == null) {
return node.getChildren(localName).iterator();
return node.getChildren(localName, Namespace.getNamespace(namespacePrefix, namespaceURI)).iterator();
if (!Namespace.getNamespace(namespacePrefix, namespaceURI).equals(el.getNamespace())) {
return JaxenConstants.EMPTY_ITERATOR;
else if(el.getNamespace() != Namespace.NO_NAMESPACE) {
return JaxenConstants.EMPTY_ITERATOR;
代码示例来源:origin: kaazing/gateway
private void checkForNoLongerSupported(Element root) throws Exception {
Namespace namespace = root.getNamespace();
List<Element> children = root.getChildren("service", namespace);
for (Element child : children) {
Element typeChild = child.getChild("type", namespace);
String type = typeChild.getText();
if (type.equals("management.snmp")) {
throw new Exception("snmp management type is no longer supported.");
} else if (type.equals("session")) {
throw new Exception("session service type is no longer supported.");
}
}
}
代码示例来源:origin: pl.edu.icm.bwmeta/bwmeta-2-foreign-transformers
@SuppressWarnings("unchecked")
static List<org.jdom.Element> getChildren(org.jdom.Element e, String name) {
if (e == null) {
return null;
}
Namespace ns = e.getNamespace();
return e.getChildren(name, ns);
}
代码示例来源:origin: org.freemarker/freemarker
private void getDescendants(Element node, List result) {
for (Iterator iter = node.getChildren().iterator(); iter.hasNext(); ) {
Element subnode = (Element) iter.next();
result.add(subnode);
getDescendants(subnode, result);
}
}
代码示例来源:origin: JetBrains/ideavim
private void readData(@NotNull Element element, String key) {
HistoryBlock block = histories.get(key);
if (block != null) {
return;
}
block = new HistoryBlock();
histories.put(key, block);
final Element root = element.getChild("history-" + key);
if (root != null) {
//noinspection unchecked
List<Element> items = root.getChildren("entry");
for (Element item : items) {
final String text = StringHelper.getSafeXmlText(item);
if (text != null) {
block.addEntry(text);
}
}
}
}
代码示例来源:origin: apache/oozie
/**
* Resolve datasets using job configuration.
*
* @param eAppXml : Job Element XML
* @throws Exception thrown if failed to resolve datasets
*/
@SuppressWarnings("unchecked")
private void resolveDataSets(Element eAppXml) throws Exception {
Element datasetList = eAppXml.getChild("datasets", eAppXml.getNamespace());
if (datasetList != null) {
List<Element> dsElems = datasetList.getChildren("dataset", eAppXml.getNamespace());
resolveDataSets(dsElems);
resolveTagContents("app-path", eAppXml.getChild("action", eAppXml.getNamespace()).getChild("workflow",
eAppXml.getNamespace()), evalNofuncs);
}
}
代码示例来源:origin: org.codehaus.mevenide/grammar
protected final org.jdom.Element findElement(org.jdom.Element parent, String name) {
List<org.jdom.Element> childs = parent.getChildren("element", parent.getNamespace()); //NOI18N
for (org.jdom.Element el : childs) {
if (name.equals(el.getAttributeValue("name"))) { //NOI18N
return el;
}
}
return null;
}
代码示例来源:origin: voldemort/voldemort
Element zoneReplicationFactorNode = store.getChild(STORE_ZONE_REPLICATION_FACTOR_ELMT);
if(zoneReplicationFactorNode != null) {
zoneReplicationFactor = new HashMap<Integer, Integer>();
for(Element node: (List<Element>) zoneReplicationFactorNode.getChildren(STORE_REPLICATION_FACTOR_ELMT)) {
int zone = Integer.parseInt(node.getAttribute(STORE_ZONE_ID_ELMT).getValue());
int repFactor = Integer.parseInt(node.getText());
if(preferredWritesStr != null)
preferredWrites = Integer.parseInt(preferredWritesStr);
SerializerDefinition keySerializer = readSerializer(store.getChild(STORE_KEY_SERIALIZER_ELMT));
if(keySerializer.getAllSchemaInfoVersions().size() > 1)
throw new MappingException("Only a single schema is allowed for the store key.");
SerializerDefinition valueSerializer = readSerializer(store.getChild(STORE_VALUE_SERIALIZER_ELMT));
RoutingTier routingTier = RoutingTier.fromDisplay(store.getChildText(STORE_ROUTING_TIER_ELMT));
代码示例来源:origin: banq/jdonframework
public void parse(Element root, Map<String, TargetMetaDef> mps) throws Exception {
Debug
.logVerbose("[JdonFramework] enter XmlPojoServiceParser .",
module);
List services = root.getChildren("services");
Iterator iter = services.iterator();
while (iter.hasNext()) {
Element service = (Element) iter.next();
if (service.getChildren("pojoService") != null) {
Iterator ii = service.getChildren("pojoService").iterator();
while (ii.hasNext()) {
Element pojoService = (Element) ii.next();
parsePOJOServiceConfig(pojoService, mps);
}
}
if (service.getChildren("component") != null) {
Iterator ii = service.getChildren("component").iterator();
while (ii.hasNext()) {
Element pojoService = (Element) ii.next();
parsePOJOServiceConfig(pojoService, mps);
}
}
}
}
代码示例来源:origin: JetBrains/ideavim
public void readData(@NotNull final Element element) {
logger.debug("readData");
final Element registersElement = element.getChild("registers");
if (registersElement != null) {
final List<Element> registerElements = registersElement.getChildren("register");
for (Element registerElement : registerElements) {
final char key = registerElement.getAttributeValue("name").charAt(0);
final Register register;
final Element textElement = registerElement.getChild("text");
final String typeText = registerElement.getAttributeValue("type");
final SelectionType type = SelectionType.fromValue(Integer.parseInt(typeText));
final Element keysElement = registerElement.getChild("keys");
final List<Element> keyElements = keysElement.getChildren("key");
final List<KeyStroke> strokes = new ArrayList<>();
for (Element keyElement : keyElements) {
代码示例来源:origin: org.apache.oozie/oozie-core
/**
* Resolve datasets using job configuration.
*
* @param eAppXml : Job Element XML
* @throws Exception thrown if failed to resolve datasets
*/
@SuppressWarnings("unchecked")
private void resolveDataSets(Element eAppXml) throws Exception {
Element datasetList = eAppXml.getChild("datasets", eAppXml.getNamespace());
if (datasetList != null) {
List<Element> dsElems = datasetList.getChildren("dataset", eAppXml.getNamespace());
resolveDataSets(dsElems);
resolveTagContents("app-path", eAppXml.getChild("action", eAppXml.getNamespace()).getChild("workflow",
eAppXml.getNamespace()), evalNofuncs);
}
}
代码示例来源:origin: pl.edu.icm.bwmeta/bwmeta-2-foreign-transformers
static List<org.jdom.Element> getDescendants(org.jdom.Element tel, String... names) {
ArrayList<org.jdom.Element> aktl=new ArrayList<>();
ArrayList<org.jdom.Element> newl=new ArrayList<>();
aktl.add(tel);
for (String n : names) {
for (org.jdom.Element e : aktl) {
if (e != null) {
Namespace ns = e.getNamespace();
newl.addAll(e.getChildren(n, ns));
}
}
aktl=newl;
newl=new ArrayList<>();
}
return aktl;
}
代码示例来源:origin: banq/jdonframework
public void parse(Element root, Map mps) throws Exception {
List components = root.getChildren("component");
Debug.logVerbose("[JdonFramework] found component size:" + components.size(), module);
Iterator iter = components.iterator();
while (iter.hasNext()) {
Element component = (Element) iter.next();
String name = component.getAttributeValue("name");
String className = component.getAttributeValue("class");
List mappings = component.getChildren("constructor");
String[] constructors = null;
if ((mappings != null) && (mappings.size() != 0)) {
constructors = new String[mappings.size()];
int j = 0;
Iterator i = mappings.iterator();
while (i.hasNext()) {
Element constructor = (Element) i.next();
String value = constructor.getAttributeValue("value");
Debug.logVerbose("[JdonFramework] component constructor=" + value, module);
代码示例来源:origin: hsz/idea-gitignore
/**
* Loads {@link UserTemplate} objects from the {@link Element}.
*
* @param element source
* @return {@link UserTemplate} list
*/
@NotNull
public static List<UserTemplate> loadTemplates(@NotNull Element element) {
final String key = KEY.USER_TEMPLATES.toString();
final List<UserTemplate> list = ContainerUtil.newArrayList();
if (!key.equals(element.getName())) {
element = element.getChild(key);
}
for (Element template : element.getChildren()) {
list.add(new UserTemplate(
template.getAttributeValue(KEY.USER_TEMPLATES_NAME.toString()),
template.getText()
));
}
return list;
}
代码示例来源:origin: apache/oozie
@SuppressWarnings("unchecked")
private Element getInputSetEvent(String name) throws JDOMException {
Element eAction = XmlUtils.parseXml(coordAction.getActionXml().toString());
Element inputList = eAction.getChild("input-events", eAction.getNamespace());
List<Element> eDataEvents = inputList.getChildren("data-in", eAction.getNamespace());
for (Element dEvent : eDataEvents) {
if (dEvent.getAttribute("name").getValue().equals(name)) {
return dEvent;
}
}
throw new RuntimeException("Event not found");
}
}
代码示例来源:origin: rome/rome
private boolean hasElementsFrom(Element root, Namespace namespace) {
boolean hasElements = false;
// boolean hasElements = namespace.equals(root.getNamespace());
if (!hasElements) {
List children = root.getChildren();
for (int i=0;!hasElements && i < children.size();i++) {
Element child = (Element) children.get(i);
hasElements = namespace.equals(child.getNamespace());
}
}
return hasElements;
}
}
代码示例来源:origin: banq/jdonframework
public void parse(Element root, Map mps) throws Exception {
List interceptors = root.getChildren("interceptor");
Debug.logVerbose("[JdonFramework] found interceptor size:" + interceptors.size(), module);
Iterator iter = interceptors.iterator();
while (iter.hasNext()) {
Element component = (Element) iter.next();
String name = component.getAttributeValue("name");
Debug.logVerbose("[JdonFramework] found interceptor name:" + name, module);
String className = component.getAttributeValue("class");
String pointcut = component.getAttributeValue("pointcut");
List mappings = component.getChildren("constructor");
String[] constructors = null;
if ((mappings != null) && (mappings.size() != 0)) {
constructors = new String[mappings.size()];
int j = 0;
Iterator i = mappings.iterator();
while (i.hasNext()) {
Element constructor = (Element) i.next();
String value = constructor.getAttributeValue("value");
Debug.logVerbose("[JdonFramework] interceptor " + name + "constructor=" + value, module);
内容来源于网络,如有侵权,请联系作者删除!