- Code: Select all
public static void main(String[] args) throws Exception {
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
StyleDefinitionsPart sdp = new StyleDefinitionsPart();
sdp.unmarshalDefaultStyles();
mdp.addTargetPart(sdp);
Styles styles = sdp.getJaxbElement();
java.util.List<Object> nodeList = mdp.getJAXBNodesViaXPath("//styles/style",styles,false);
for (int i = 0; i < nodeList.size(); i++) {
Style style = (Style) nodeList.get(i);
String styleId = style.getStyleId();
System.out.println(styleId);
}
}
What the code is suppose to do is create a StylesDefinitionsPart, then populate it with defalut styles, then find all the style elements and print their style id. Why is it not working and giving me a null pointer exception ? The exception happens on the line with the call to getJAXBNodesViaXPath.
/Simon