Page 1 of 1

Bulleted Lists and <w:listPr>

PostPosted: Tue Apr 20, 2010 11:42 pm
by alla

I need to identify bulleted (and numbered) lists in a document. Numbered lists are easy enough:
Code: Select all
org.docx4j.wml.PPr ppr = ((org.docx4j.wml.P)o).getPPr(); // get paragraph propertires
PPrBase.NumPr numPr = ppr.getNumPr();
if( numPr != null) { // This paragraph is numbered
        System.out.println("This paragraph has numbering level: " + numPr.getIlvl().getVal());

The XML for bulleted list item looks like this:
Code: Select all
   <w:listPr><w:ilvl w:val="0"/><!--skip-->
<w:r><w:t>Bulleted item 1</w:t></w:r>

I expected that I could do something like
Code: Select all
listPr = ppr.getListPr()
, but org.docx4j.wml.PPr does not have a method getListPr().

Is there any way around it, i.e. getting all XML children of ppr and finding <w:listPr> element?

Re: Bulleted Lists and <w:listPr>

PostPosted: Wed Apr 21, 2010 11:48 pm
by jason
listPr is an Office 2003 XML element, and not part of OpenXML AFAIK, so it is not understood by docx4j.

You'll need to convert your document to OpenXML before docx4j can interpret it. You might use XSLT to convert 2003 XML to the Flat OPC XML format, which docx4j can ingest.

Re: Bulleted Lists and <w:listPr>

PostPosted: Thu Apr 22, 2010 11:02 pm
by alla
Hello Jason,

Thanks, you are right. I was looking at .xml file instead of unzipping .docx and looking at the document.xml inside it. Indeed in Word 2007 both bulleted and numbered lists have numPRs.