Here's an example using Traverse:
Using java Syntax Highlighting
public static void main
(String[] args
) throws Exception {
String inputfilepath
= System.
getProperty("user.dir") + "/sample-docs/word/sample-docx.docx";
WordprocessingMLPackage
wordMLPackage = WordprocessingMLPackage.
load(new java.
io.
File(inputfilepath
));
MainDocumentPart documentPart
= wordMLPackage.
getMainDocumentPart();
PropertiesFinder finder
= new PropertiesFinder
();
new TraversalUtil
(documentPart.
getContent(), finder
);
// Results
System.
out.
println("got " + finder.
results.
size() );
for (Object o
: finder.
results) {
System.
out.
println( XmlUtils.
marshaltoString(o,
true,
true));
// You can access the parent Run
System.
out.
println( "parent: " + ((Child
)o
).
getParent().
getClass().
getName() );
}
}
public static class PropertiesFinder
extends CallbackImpl
{
public List
<RPr
> results
= new ArrayList
<RPr
>();
@Override
public List
<Object
> apply
(Object o
) {
if (o
instanceof R
&& ((R
)o
).
getRPr()!=null ) {
results.
add( ((R
)o
).
getRPr() );
}
return null;
}
}
Parsed in 0.017 seconds, using
GeSHi 1.0.8.4
Alternatively you could see whether XPath works for you. See the comments in
https://github.com/plutext/docx4j/blob/ ... Query.java for possible limitations.
You can use xpath "//w:rPr".
You may need to do some research / experimentation to see whether the warning apply to your use case. If you do, please let us know what you find (including which JAXB you are using and/or Java version).