Hi Cindy,
I want my user to write a "template" in word and save it as xml. This
template will later be used for our own mailmerge system.
Therefore if my users open a new document and enters the field
@customoername@, the wordml will look like this...
...<w:p><w:r><w:t>@customername@</w:t></w:r>....
This is very easy to open the xml file in our .net-crm application and
do a search/replace on the variable @customername@.
But if the user wants to make it bold and by mistake forgets to
highlight the last @, the wordml will look like this...
<w:rPr><w:b/></w:rPr><w:t>@customername</w:t></w:r><w:r><w:t>@</w:t>
Then I will not be able to from my .net-crm application to open the word
as a tectfile and do a search/replace on the @customername@, because
it's now called...
@customername</w:t></w:r><w:r><w:t>@
I would like my users to be able to enter a fieldname like @customernam@
in word and no matter what formatting they do on the field, the
@customername@ must be intact.
Hope you get what I mean.
:o)
Thanks for still trying to help me out here!!
Mojo
Cindy M -WordMVP- skrev:
> Hi Mojo,
>
[quoted text clipped - 27 lines]
> This reply is posted in the Newsgroup; please post any follow question or
> reply in the newsgroup and not by e-mail :-)
Peter Jamieson - 31 Jul 2006 09:15 GMT
I don't believe there is any way you can force Word to fix this at the point
when you save the document, unless you know how to write a transform that
could do it (I don't), particularly...
> I would like my users to be able to enter a fieldname like @customernam@
> in word and no matter what formatting they do on the field, the
> @customername@ must be intact.
...when you want that much flexibility. What you're implying is that there
could be any number of formatting tags within the @customername@ "tag". Nor
is it going to be simple even to identify what is and what is not a tag,
partly because a character such as "@" is quite likely to be used in other
ways in a document (especially in e-mail addresses), and partly because the
user may accidentally omit an "@".
Personally I would consider two approaches to solving this:
a. either provide a macro that the user either invokes or is invoked
automatically when the document is closed, or can be run as a check after
closing, to go through the document looking for @tag@ tags, reporting on any
"solitary" "@" characters it can find, then applying (or more likely,
removing) consistent formatting, in a way that you have determined by
experiment leaves you with <w:t>@tag@</w:t>
b. or postprocess the resulting XML, using any appropriate language, in a
three-stage process:
- make a copy of the XML and strip all XML tags so that the user-defined
@tag@ tags are reconstituted
- perform much the same checking for "solitary" "@" chaaracters as in (a)
and flag any stuff you cannot recognise
- if all is OK, reprocess the original XML by identifying the start and
end of @tag@ tags and successively swapping the positions of XML tags and
plain text until the @tag@ is reconsituted.
If (a) is feasible, it looks an awful lot simpler to me than (b). I also
suspect it might be a whole lot more reliable if you didn't use a common
character such as "@" as your tag marker, or doubled it up to @@. Personally
I like "¬" (who on earth uses that?), but that's primarily because it's
available on a UK keyboard. Of course th logical problem remains whatever
you use.
Peter Jamieson
> Hi Cindy,
>
[quoted text clipped - 57 lines]
>> This reply is posted in the Newsgroup; please post any follow question or
>> reply in the newsgroup and not by e-mail :-)
Cindy M -WordMVP- - 31 Jul 2006 11:12 GMT
Hi Mojo,
I get what you mean. And I agree with Peter's analysis.
The only additional thought I have is that it should be possible to use
XPath rather than a text search. XPath should let you extend what's picked
up until you hit the "end symbol", and to pick up only the <t> tag's
contents. As long as you're using XML, make the most of it and use the
tools that are available for working with it :-) XML wasn't designed to be
worked with in "text editor"...
> I want my user to write a "template" in word and save it as xml. This
> template will later be used for our own mailmerge system.
[quoted text clipped - 23 lines]
>
> Hope you get what I mean.
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
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 :-)
M O J O - 31 Jul 2006 20:45 GMT
Hi Peter and Cindy,
Thank you both for the elaborating answers.
I will try to parse the file as an xml file.
Thanks again!!
Mojo
M O J O skrev:
> Hi Cindy,
>
[quoted text clipped - 63 lines]
>> This reply is posted in the Newsgroup; please post any follow question
>> or reply in the newsgroup and not by e-mail :-)