<w:bookmarkStart w:id="0" w:name="mybookmark"/><w:r><w:t>stuff</w:t></w:r><w:bookmarkEnd w:id="0"/> javax.xml.bind.JAXBElement
      {http://schemas.openxmlformats.org/wordprocessingml/2006/main}bookmarkStart <----- (JAXBElement)o).getName() 
      org.docx4j.wml.CTBookmark <----- (JAXBElement)o).getDeclaredType().getName()
  javax.xml.bind.JAXBElement
      {http://schemas.openxmlformats.org/wordprocessingml/2006/main}bookmarkEnd <----- (JAXBElement)o).getName() 
      org.docx4j.wml.CTMarkupRange <----- (JAXBElement)o).getDeclaredType().getName()
                if ( ((JAXBElement)o).getName().getLocalPart().equals("bookmarkStart") ) {
                    org.docx4j.wml.CTBookmark bs = (org.docx4j.wml.CTBookmark)((JAXBElement)o).getValue(); 
                    System.out.println(" .. bookmarkStart" );
                }
                
                if ( ((JAXBElement)o).getName().getLocalPart().equals("bookmarkEnd") ) {
                    org.docx4j.wml.CTMarkupRange be = (org.docx4j.wml.CTMarkupRange)((JAXBElement)o).getValue(); 
                    System.out.println(" .. bookmarkEnd" );
                }
    <xsd:group name="EG_RangeMarkupElements">
        <xsd:choice>
            <xsd:element name="bookmarkStart" type="CT_Bookmark">
                <xsd:annotation>
                    <xsd:documentation>Bookmark Start</xsd:documentation>
                </xsd:annotation>
            </xsd:element>
            <xsd:element name="bookmarkEnd" type="CT_MarkupRange">
                <xsd:annotation>
                    <xsd:documentation>Bookmark End</xsd:documentation>
                </xsd:annotation>
            </xsd:element>
   StringBuffer sb = new StringBuffer();
   boolean inBookmark = false;
   
   void walkList(List children){
            
      for (Object o : children ) {               
         if ( o instanceof javax.xml.bind.JAXBElement) {
            
            System.out.println( "\n" + XmlUtils.JAXBElementDebug((JAXBElement)o) );
            if ( ((JAXBElement)o).getName().getLocalPart().equals("bookmarkStart") ) {
               //org.docx4j.wml.CTBookmark bs = (org.docx4j.wml.CTBookmark)((JAXBElement)o).getValue(); 
               System.out.println(" .. bookmarkStart" );
               inBookmark = true;
            }
            
            if ( ((JAXBElement)o).getDeclaredType().getName().equals("org.docx4j.wml.Text") ) {
               
               org.docx4j.wml.Text t = (org.docx4j.wml.Text)((JAXBElement)o).getValue();
               
               if (inBookmark) {
                  sb.append( t.getValue() );
               }               
            }             
            
            
            if ( ((JAXBElement)o).getName().getLocalPart().equals("bookmarkEnd") ) {
               //org.docx4j.wml.CTMarkupRange be = (org.docx4j.wml.CTMarkupRange)((JAXBElement)o).getValue(); 
               System.out.println(" .. bookmarkEnd" );
               inBookmark = false;
            }
            
         } else {
            System.out.println("  " + o.getClass().getName() );
            if ( o instanceof org.docx4j.wml.R) {
               org.docx4j.wml.R  run = (org.docx4j.wml.R)o;
               walkList(run.getRunContent());                           
            } 
         }
//         else if ( o instanceof org.docx4j.jaxb.document.Text) {
//            org.docx4j.jaxb.document.Text  t = (org.docx4j.jaxb.document.Text)o;
//            System.out.println("      " +  t.getValue() );               
//         }
      }
   }
ostkurve wrote:how I can navigate to the paragraph object when I encounter CTBookmark or CTMarkupRange
The wml package classes each have a method getParent(), so you should be able to get from CTBookmark to P.
public static org.docx4j.wml.P findBookmarkedP(String name, MainDocumentPart documentPart) throws JAXBException {
    
    final String xpath = "//w:bookmarkStart";
    List<Object> objects = documentPart.getJAXBNodesViaXPath(xpath, false);
    CTBookmark ctb = (CTBookmark) XmlUtils.unwrap(objects.get(1));
    String hh = ctb .getName();
    P p = (P) ctb .getParent();
    return p;
}
Try to figure out what is the class of the parent (getClass())Users browsing this forum: Google Adsense [Bot], Majestic-12 [Bot] and 275 guests