DOCX4J XML如何获得“价值”一个JAXBNodes [英] DOCX4J XML how to get the "value" of a JAXBNodes
本文介绍了DOCX4J XML如何获得“价值”一个JAXBNodes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在docx文件中绑定一些XML变量(我的var在那个模式$ varname $中)。所以我使用一个函数返回 List< Object>
,其结果是我对文档的搜索。
I want to bind some XML variable in a docx file (my var are in that pattern $varname$). So I use a function which return a List<Object>
with the result of my search over the document.
String xpath = "//w:r[w:t[starts-with(text(), '$')]]";
List<Object> list = this.getDocumentPart().getJAXBNodesViaXPath(xpath, false);
if(!list.isEmpty()){
for(int i = 0; i < list.size(); ++i){
System.out.println(list.get(i).getClass());
}
}
打印结果为:
class org.docx4j.wml.R
class org.docx4j.wml.R
class org .docx4j.wml.R
class org.docx4j.wml.R
class org.docx4j.wml.R
class org.docx4j.wml.R
但是现在我想得到值即$ varname $来将它与地图进行比较(关键是每个变量的名称)?
But now I want to get the "value" ie $varname$ to compare it with a map (the key is the name of each variable) ?
推荐答案
我找到解决方案:
if(!list.isEmpty()){
List<Object> listObjNode;
for(int i = 0; i < list.size(); ++i){
List<Object> r = ((R)list.get(i)).getContent();
for(int j = 0; j < r.size(); ++j){
javax.xml.bind.JAXBElement jaxb = (javax.xml.bind.JAXBElement)r.get(j);
org.docx4j.wml.Text t = (org.docx4j.wml.Text)jaxb.getValue();
System.out.println(t);
}
}
}
这篇关于DOCX4J XML如何获得“价值”一个JAXBNodes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文