Replacing tags inside word doc effiiciently

T

Tim Mavers

I am looking for ways of replacing tags a user has entered in Word and saved
to XML. Basically the user can enter all these tags marked with a special
token I look for. These fields are then replaced by data from a database.
It's a little more complicated than I explain, but this the basic concept.

This happens through a user-initated call from a web application. The
server uses C# (ASP.NET) to load up the Word doc and then uses the Word
interop libraries to search and replace. This is very, very slow.

I am looking for alternatives, namely with XML. The document itself is
considered a "template" and stored in the system as XML (saved from Word).
I can parse through the XML with an XML parser, but content seems to be
chunked out and thus my custom tags could be separated between two WML tags
(i.e. @MYTAG@ may be broken up between the Y and T preventing be for
searching for the exact phrase MYTAG).

Are there efficient ways to transform these documents without needed to
actually load Word?

Thanks,
 
C

Cindy M -WordMVP-

Hi Tim,

Since you're in control of the original document you should be able to use the
new Word 2003 protection feature to set the ranges (areas) where the user is
allowed to enter text. Display the "Protect document" task pane, activate
"Allow only this type of editing in the document" for "Read only". Do Step 3,
giving permission to "everyone" for the areas where the user may type.

When the user saves this as XML, you should be able to pick up these tags
(within your tags, assuming you're allowing mixed content).

BTW, the better place to get an answer to XML questions would probably be the
office.xml group.
I am looking for ways of replacing tags a user has entered in Word and saved
to XML. Basically the user can enter all these tags marked with a special
token I look for. These fields are then replaced by data from a database.
It's a little more complicated than I explain, but this the basic concept.

This happens through a user-initated call from a web application. The
server uses C# (ASP.NET) to load up the Word doc and then uses the Word
interop libraries to search and replace. This is very, very slow.

I am looking for alternatives, namely with XML. The document itself is
considered a "template" and stored in the system as XML (saved from Word).
I can parse through the XML with an XML parser, but content seems to be
chunked out and thus my custom tags could be separated between two WML tags
(i.e. @MYTAG@ may be broken up between the Y and T preventing be for
searching for the exact phrase MYTAG).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top