Java 尝试访问docx文件中的子节点

Java 尝试访问docx文件中的子节点,java,xml,docx,Java,Xml,Docx,我需要使用dom4j解析器访问docx XML文件中的子节点的帮助 我使用以下方法创建了节点列表: List<Node> nodes = document.selectNodes("/w:document/w:body/w:tbl/w:tr/w:tc"); List nodes=document.selectNodes(“/w:document/w:body/w:tbl/w:tr/w:tc”); 但是,我不知道如何找到selectNode组的子节点。 docx文件是一个列表,我

我需要使用dom4j解析器访问docx XML文件中的子节点的帮助

我使用以下方法创建了节点列表:

 List<Node> nodes = document.selectNodes("/w:document/w:body/w:tbl/w:tr/w:tc");
List nodes=document.selectNodes(“/w:document/w:body/w:tbl/w:tr/w:tc”);
但是,我不知道如何找到selectNode组的子节点。 docx文件是一个列表,我正在编辑并试图更新数据库

我需要保持在这个级别,因为我需要知道数据在哪一列。 我需要知道数量

我想在这个级别上得到Child。我需要确定任何列中是否缺少任何数据

谢谢你的帮助


要查找当前上下文节点的子节点,必须指定哪个不是以
'/'字符开头的。
char

for (Iterator iterator = nodes.iterator(); iterator.hasNext();) {
    Node node = (Node) iterator.next();
    node.selectNodes("w:tcPr");//="child::w:tcPr", child is the default axis of location path
    //The API return child nodes `w:tcPr`
}
节点。选择节点(“w:tcPr/w:shd”)

API返回1节点[/w:document/w:body/w:tbl/w:tr/w:tc/
w:tcPr/w:shd
]

node.selectNodes(“*/w:shd”)//选择上下文节点的孙子“w:shd”

API返回1节点[
w:tcPr/w:shd
];如果节点
w:p/w:shd
存在,则将选择该节点

selectNodes(“self::node()//w:shd”)//XPath=“self::node()/子代或self::node()/w:shd”

API返回2个节点[
w:tcPr/w:shd
w:p/w:pPr/w:shd
];如果节点
w:shd
存在,将选择该节点

node.selectNodes(“*//w:shd”)//XPath=“child::node()/子代或self::node()/w:shd”


API还返回2个节点[
w:tcPr/w:shd
w:p/w:pPr/w:shd
];但是如果节点
w:shd
存在,它将不被选中。

要查找当前上下文节点的子节点,您必须指定哪个节点不以
'/'字符开头

for (Iterator iterator = nodes.iterator(); iterator.hasNext();) {
    Node node = (Node) iterator.next();
    node.selectNodes("w:tcPr");//="child::w:tcPr", child is the default axis of location path
    //The API return child nodes `w:tcPr`
}
节点。选择节点(“w:tcPr/w:shd”)

API返回1节点[/w:document/w:body/w:tbl/w:tr/w:tc/
w:tcPr/w:shd
]

node.selectNodes(“*/w:shd”)//选择上下文节点的孙子“w:shd”

API返回1节点[
w:tcPr/w:shd
];如果节点
w:p/w:shd
存在,则将选择该节点

selectNodes(“self::node()//w:shd”)//XPath=“self::node()/子代或self::node()/w:shd”

API返回2个节点[
w:tcPr/w:shd
w:p/w:pPr/w:shd
];如果节点
w:shd
存在,将选择该节点

node.selectNodes(“*//w:shd”)//XPath=“child::node()/子代或self::node()/w:shd”


API还返回2个节点[
w:tcPr/w:shd
w:p/w:pPr/w:shd
];但是如果节点
w:shd
存在,它将不被选中。

您能给出您正在解析的XML的一个片段吗?您必须选择哪些子节点?能否给出正在解析的XML片段?您必须选择哪些子节点?如何选择子节点?选择答案?您的意思是什么?如果要获取文本节点
“Quantity”
,可以调用
节点。选择SingleNode(“w:p/w:r/w:t”).getText()
。我如何选择选择?选择答案是什么意思?如果要获取文本节点
“数量”
,可以调用
节点。选择SingleNode(“w:p/w:r/w:t”).getText()