Page 1 of 1

is there an easy way to browse the headings?

PostPosted: Fri Sep 23, 2011 9:08 pm
by leon
hi all,
i wonder if there's an easy way by docx4j to browse the headings with the hierarchy in docx file? for example:
<w:p w:rsidR="00A02F85" w:rsidRDefault="00A02F85" w:rsidP="00A02F85">
<w:pPr>
<w:pStyle w:val="Heading2" />
</w:pPr>
<w:r>
<w:t>Chapter1</w:t>
</w:r>
</w:p>
<w:p w:rsidR="00A02F85" w:rsidRDefault="00A02F85" w:rsidP="00A02F85">
<w:pPr>
<w:pStyle w:val="Heading2" />
</w:pPr>
<w:r>
<w:t>Chapter2</w:t>
</w:r>
</w:p>
<w:p w:rsidR="00A02F85" w:rsidRDefault="00A02F85" w:rsidP="00A02F85">
<w:pPr>
<w:pStyle w:val="Heading3" />
</w:pPr>
<w:r>
<w:t>Chapter2.1</w:t>
</w:r>
</w:p>

any help is appreicated!

Re: is there an easy way to browse the headings?

PostPosted: Sat Sep 24, 2011 6:00 pm
by jason
Use an XPath expression, or TraversalUtil. See Getting Started for more details.

Re: is there an easy way to browse the headings?

PostPosted: Mon Sep 26, 2011 7:03 pm
by leon
hi Jason,
i tried both ways (XPath and TraversalUtil), yes i can traverse all the nodes in the docx, but it's difficult to filter out the headings, especially the hadings in hierarchy...
what i did is check each paragraph if there's w:pPr subnode in it, at the same time there's a w:pStyle in the w:pPr, then draw the w:t of this paragraph. i think it's a little bit troublesome, and also i cannot get the hierarchy relations among those headings, for example:
Chapter1
Chapter2
Chapter2.1
Chapter2.2
what i got is plain, how can i know that the chapter2.1 and 2.2 is the children of Chapter2?
i'm new on docx4j, could you please explain a little bit in detail how to implement the request? thanks in advance.

Re: is there an easy way to browse the headings?

PostPosted: Thu Oct 06, 2011 12:50 am
by leon
hi Jason,
could you help me on this? it's really appreciated.