btw, i changed a little bit:


unreal wrote
> 
> ...
> public String procParasForBookmarkText(List<XWPFParagraph> paraList, 
>         String bookmarkName) throws XmlException, IOException { 
>         Iterator<XWPFParagraph> paraIter = null; 
>         XWPFParagraph para = null;         
>         List<CTBookmark> bookmarkList = null; 
>         Iterator<CTBookmark> bookmarkIter = null; 
>         CTBookmark bookmark = null; 
>         Node nextNode = null;         
>         
>         // Get an Iterator to step through the contents of the paragraph
> list. 
>         paraIter = paraList.iterator(); 
>         while(paraIter.hasNext()) { 
>             // Get the paragraph, a llist of CTBookmark objects and an
> Iterator 
>             // to step through the list of CTBookmarks. 
>             para = paraIter.next(); 
>             bookmarkList = para.getCTP().getBookmarkStartList(); 
>             bookmarkIter = bookmarkList.iterator(); 
>             
>             while(bookmarkIter.hasNext()) { 
>                 // Get a Bookmark and check it's name. If the name of the 
>                 // bookmark matches the name the user has specified... 
>                 bookmark = bookmarkIter.next(); 
>                 if(bookmark.getName().equals(bookmarkName)) {                 
>                     
>                     // Now, we need to step through any nodes that may
> exist 
>                     // inbetween the two bookmark tags. So, get the next
> sibling 
>                     // node from the pargraph 
>                     nextNode = bookmark.getDomNode().getNextSibling(); 
>                    
> while(!(nextNode.getNodeName().contains("bookmarkEnd"))) { 
>                         
>                         // ...and if it is a run, create a CTR object from
> that 
>                         // node and then gat at the raw XML markup the
> node 
>                         // encapsulates. Process that using brute force
> java 
>                         // String operations as it does not seem to be
> possible 
>                         // top get at the text content of the node from
> the 
>                         // CTText nodes the run contains. Odd!! 
>                         if(nextNode.getNodeName().equals("w:r")) { 
>                          
>                             *NodeList nodelist = nextNode.getChildNodes();    
>     
>                             for (int i = 0; i < nodelist.getLength(); i++) 
>                             {   
>                                 Node childnode = nodelist.item(i);  
>                                 NodeList childnodelist =
> childnode.getChildNodes();
>                                 
>                                 for (int j = 0; j <
> childnodelist.getLength(); j++) {                                    
>                                     //  Is Node a Datatype?
>                                     if
> (childnodelist.item(j).getNodeType() == 3) { 
>                                         //  gotscha !
>                                         return
> childnodelist.item(j).getNodeValue().trim();
>                                     }
>                                 }
>                             }*
>                             
>                         } 
>                         nextNode = nextNode.getNextSibling(); 
>                     } 
>                 } 
>             } 
>         } 
>         
>         return ""; 
>     } 
> ...
> 

--
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/How-to-read-the-value-of-bookmarks-docx-tp5710184p5710222.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to