jOOXを使用してから書くことができます
List<Element> elements = $(doc).find("b").children().get();
またはDOMで:
// Beware, this list also contains the blank text nodes around the <c/> elements,
// if your document is formatted.
NodeList list = doc.getElementsByTagName("b").item(0).getChildNodes();
更新: DOM ドキュメントをさらにトラバースする場合 (つまり"c"
、コメントで言及したように子ノードを取得する場合は、jOOX をお勧めします:
// This will find all "c" elements, and then return all children thereof
$(doc).find("c").children();
// This will return "d", "f", "d", "f", "d", "f":
List<String> tags = $(doc).find("c").children().tags();
// This will return "1", "2", "2, "2", "v", "d":
List<String> texts = $(doc).find("c").children().texts();
DOM で同じことを行うと、非常に冗長になります。
List<Element> elements = new ArrayList<Element>();
List<String> tags = new ArrayList<String>();
List<String> texts = new ArrayList<String>();
NodeList c = doc.getElementsByTagName("c");
for (int i = 0; i < c.getLength(); i++) {
if (c.item(i) instanceof Element) {
NodeList children = c.item(i).getChildNodes();
for (int j = 0; j < children.getLength(); j++) {
if (children.item(j) instanceof Element) {
elements.add((Element) children.item(j));
tags.add(((Element) children.item(j)).getTagName());
texts.add(children.item(j).getTextContent());
}
}
}
}
更新 2 (今後の質問を具体的にしてください...!) : XPath を使用して、次のようにします。
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expression = xpath.compile("//c/*");
NodeList nodes = (NodeList) expression.evaluate(
document.getDocumentElement(), XPathConstants.NODESET);