Page 1 of 1

Simple template tag addition

PostPosted: Thu Aug 26, 2010 10:09 am
by desau
Hi all,

I have a requirement to parse a docx file, looking for user-supplied tags and substitute images or text.

As noted in the getting started guide, searching for text is problematic because the text could be broken across multiple runs.

I'm wondering if there's a way to (using Word) insert some sort of tag that's easy to parse for in the XML (using docx4j).

One possible solution I found: Insert a hidden HTML element. This allows me to specify arbitrary text, but the XML that's created for a single HTML hidden field is a bit much.

I also thought of inserting a bookmark, but the text for a bookmark is quite constricted (no spaces, no delimiters except underscore).

Any other suggestions for something that I could use as a "tag" in word that I could search for and substitue in the XML?


Re: Simple template tag addition

PostPosted: Thu Aug 26, 2010 10:38 am
by jason
Off the top of my head, I'd be inclined to use content controls.

Yes, the XML is a bit verbose, but ...

1 this is what they are designed for

2 they can go pretty much anywhere, including inline

3 you can put an id and title on them if you want to, and use the tag for arbitrary non-visible data (docx4j has a class which uses the query string format to store the data)

4 there is a type specifically for pictures/images

5 you could if you wanted to, go the whole way, and use XML data binding to insert your text in the controls (ie add an XML file containing your data, and let Word or docx4j place it in the controls). You can insert/manipulate the controls in Word, but you do need the content control toolkit or similar to establish the bindings (if you want this as well)