Page 1 of 1

Get "R" for a "Text" node?

PostPosted: Sat Aug 28, 2010 5:04 pm
by desau
Given a Text node (and/or its JAXBElement parent), is there any way to get the R node that it belongs to?

Re: Get "R" for a "Text" node?

PostPosted: Sat Aug 28, 2010 7:53 pm
by jason
getParent()

Re: Get "R" for a "Text" node?

PostPosted: Sun Aug 29, 2010 2:06 am
by desau
That would be perfect, however that's not the case here.

Perhaps I should be more specific.

Given a Text node, obtained from:
Code: Select all
Object objNode = documentPart.getJAXBNodesViaXPath("//w:t").get(0);


How do I get the R parent node?

The Object is a JAXBElement<T> node, its value is an org.docx4j.wml.Text node.

As you've written on the getting started guide, I can cast the value to a Text node:
Code: Select all
JAXBElement jNode = (JAXBNode) objNode;
Text textNode = (Text) objNode.getValue();


However, calling getParent() on the textNode will only give me back the JAXBElement node.

Re: Get "R" for a "Text" node?

PostPosted: Sun Aug 29, 2010 9:48 am
by jason
I've verified your observation.

That seems to be a bug in the parent pointer plugin. I'll email its author.

In the meantime, can you use an XPath expression to find the relevant w:r directly, as per your earlier post?

Or you could try fixing it yourself, http://fisheye5.atlassian.com/browse/ja ... ter-plugin

Re: Get "R" for a "Text" node?

PostPosted: Sun Aug 29, 2010 3:13 pm
by desau
Ah.. interesting. I wasn't aware that this was a bug. That makes sense.

Yeah-- it's not as a easy, but I can manage a hashmap for a Text to parent R mapping.

Thanks!

Re: Get "R" for a "Text" node?

PostPosted: Tue Apr 01, 2014 8:36 pm
by trucmuche
It seems this bug is still present.
Or is it really a bug?

I have the same problem here, given a text node, I'm trying to get its parent R node but all I get is the JAXBElement.
Any way to get the R node?

Thanks in advance.

Re: Get "R" for a "Text" node?

PostPosted: Tue Apr 01, 2014 9:41 pm
by jason
One way around the problem: If you traverse the document (before doing whatever it is you want to do), CallbackImpl will set the parent values correctly.

Re: Get "R" for a "Text" node?

PostPosted: Tue Apr 01, 2014 9:46 pm
by trucmuche
Thanks for the fast reply Jason.

I just tried the code posted by Richard here:
docx-java-f6/parent-of-ctcustomxmlblock-t616.html#p1890

It fixed the problem.