Node obtained by NextPreOrder does not include newline

Hello,

The method GetText() on the attached document returns this:

A list of items:
MERGEFIELD RESWARE_CD_Conditional Field 2_3 ITEM1
ITEM2
ITEM3
And there you go.

NextPreOrder on the field start node of the merge field above (containing “ITEM1\rITEM2\rITEM3”) returns a node with the text “ITEM1”. This does NOT include the newline that follows ITEM1.

NextPreOrder on the node obtained above returns a node with text “ITEM2\r”. This DOES include the newline that follows ITEM2.

Shouldn’t NextPreOrder in both cases return a node with text that includes the “\r” after the item?

Thanks,
Kris

Hi Kris,


Thanks for your inquiry.

NextPreOrder will move to the next node in the document tree or based off which ever parent node you pass to the method.

In your case, what is most likely happening in your code is that the Run node is visited first. This contains just the formatted text content of the paragraph. Next it will move to the paragraph. If you get the text of this node it will return both the line break and the text of child run. This is why you receive both the line break and the text.

If you want to avoid the line break when retrieving the text of a paragraph, you can simply call Trim on it.

Thanks,