Page 1 of 1

parent of Text

PostPosted: Sun Jun 12, 2016 2:39 am
by wschofield
Either I am doing it wrong or this is still a bug. I am attempting to start with a Text element and climb up to the ContentAccessor of the Paragraph that contains it. It seems like a reasonable plan but getting the parent object of the Text element returns another Text element it seems. The method I am using is below. I call it with a Text element and it is written to recurse up the tree till it finds what I'm looking for.

Code: Select all
     private List<Object> getContentList(Object o)
     {   
        List<Object> content = null;
        Object p = null;
        if (o instanceof Text)
        {
           p = ((Text) o).getParent();
        }
        else if (o instanceof R)
        {
           p = ((R) o).getParent();
        }
        else if (o instanceof P)
        {
           p = ((P) o).getParent();
        }
        else if (o instanceof Body)
        {
           p = o;   // at the top
        }
       
        boolean contentHolder = (p instanceof ContentAccessor && !(o instanceof P));
        if (!contentHolder)
        {
           if (p != null)
              content = getContentList(p);          
        }
        else
        {
           content = ((ContentAccessor) p).getContent();
        }          
        return content;        
     }

Re: parent of Text

PostPosted: Sun Jun 12, 2016 6:49 pm
by jason
What version of docx4j are you using?

Perhaps try a 3.3.1 nightly, from after 2 May, from http://www.docx4java.org/docx4j/

These contain https://github.com/plutext/docx4j/commi ... d75fa0053f