Page 1 of 1

Read text from Text includes w:instrText content also

PostPosted: Tue Jul 28, 2020 10:10 am
by arulface
Hi,

While i read text value from Text node I am getting the text value, however we are getting values from <w:instrText> also which is not required for us. we required only w:t value. Kindly do the needful. Thanks in advance.

Our code:
else if (o instanceof Text) {
Text textNode = (Text) o;
String textContent = textNode.getValue();
if (ACEUtil.containsValidData(textContent)) {
prevNodeType = "Text";
}
}
what this code does is:
While iterating TraverseUtil, we have been trying to read the values from RunIns, RunDel and Text. But while reading text we have been using Text textNode = (Text) obj; then textNoge.getValue().

Sample xml:

<w:r w:rsidR="0005316A" w:rsidRPr="00536F9C">
<w:rPr>
<w:rStyle w:val="au"/>
<w:color w:val="auto"/>
<w:sz w:val="24"/>
<w:szCs w:val="24"/>
<w:u w:val="thick" w:color="FF0000"/>
<w:vertAlign w:val="superscript"/>
</w:rPr>
<w:t>,</w:t>
</w:r>
<w:proofErr w:type="gramEnd"/>
<w:r w:rsidR="003A5909" w:rsidRPr="00536F9C">
<w:fldChar w:fldCharType="begin"/>
</w:r>
<w:r w:rsidR="003A5909" w:rsidRPr="00536F9C">
<w:instrText xml:space="preserve"> HYPERLINK "orcid:0000-0001-5497-4482" \o "orcid:0000-0001-5497-4482" </w:instrText>
</w:r>

Re: Read text from Text includes w:instrText content also

PostPosted: Tue Aug 04, 2020 7:06 pm
by jason
You have

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
        new TraversalUtil(documentPart, new TraversalUtil.CallbackImpl() {
            @Override
            public List<Object> apply(Object o) {
:
 
Parsed in 0.014 seconds, using GeSHi 1.0.8.4


but you use the provided implementation of walkJAXBElements(Object parent)

For a given child, that code says:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting

                                        if (o instanceof javax.xml.bind.JAXBElement) {
                                                o2 = ((JAXBElement)o).getValue();
 
Parsed in 0.013 seconds, using GeSHi 1.0.8.4


then passes o2 to apply ie apply(o2). ((JAXBElement)o).getValue() is what XmlUtils.unwrap does.

For your application, you need to look at the original JAXBElement object,
so use:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
                @Override
                public void walkJAXBElements(Object parent) {
                       
                        List children = getChildren(parent);
                        if (children != null) {

                                for (Object o : children) {

                                        this.apply(o);

                                        if (this.shouldTraverse(o)) {
                                                walkJAXBElements(o);
                                        }

                                }
                        }
                }
 
Parsed in 0.014 seconds, using GeSHi 1.0.8.4


and in your apply method have a look at what ((JAXBElement)o).getDeclaredType().getName() and/or ((JAXBElement)o).getName() report.