Page 1 of 1

Adding special characters in custom XML

PostPosted: Tue Oct 19, 2010 8:27 am
by dcole
Hi,

If I am looking to add special characters to my custom XML that I am injecting into a word doc, what is the preferred method? Is it possible through docx4j, or string manipulation, or what?

I am marshalling a string to XML coming from a Java object, and it has a string token in it. I would like to replace the token in the word document with a bulleted list OR simply a carriage return or something else. I tried to do a string.replace("|","\n\r") on the string, then outputting the XML, injecting to the doc. In my word document the text was all still part of the same line.

Thanks

Derek

Re: Adding special characters in custom XML

PostPosted: Tue Oct 19, 2010 9:03 am
by jason
Hi Derek

Whichever way you do it, you'll need to end up with distinct bits of XML for each token.

I say this because even what is in Word called a manual line break (^l) results in a snippet of XML - albeit a simple one, w:cr: http://www.documentinteropinitiative.or ... e68f9.aspx

You could easily create a <w:t> containing <w:cr> using unmarshalString, but that won't be bulleted. Bullets require a <w:p> for each bulleted item.

You could process <javaobject> using docx4j to programmatically insert paragraphs. This would avoid altering the custom xml.

To do what you want via Custom XML, you need your own step which converts

Code: Select all
<javaobject>your string</javaobject>

to

Code: Select all
<tokens>
    <token>t1</token>
    <token>t2</token>
    :
</tokens>


and injects that into your custom xml.

Then you can handle this with a repeat content control containing a regular bind content control.

.. Jason

Re: Adding special characters in custom XML

PostPosted: Wed Oct 20, 2010 12:23 am
by dcole
Gotcha. I figured I would probably have to do it the way you're saying - with a repeat binding control. I was hoping for something simple like a string there might be another way to make it put the text in different runs. Thanks for the reply