Group:  General » microsoft.public.office.xml
Thread: Search and replace my custom tags in WordML??

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Search and replace my custom tags in WordML??
M O J O <na[ at ]na.na> 27.07.2006 12:01:02
Hi,

I need to open a wordml document and search/replace some custom tags.

The problem is, that when I open a wordml doc, the tags are messed up.

My text look likes this "Dear [ at ]customername[ at ], ....", but when I open the
wordml doc, it can look like this....

<w:rPr>Dear <w:b/>[ at ]</w:rPr><w:t>customername</w:t>[ at ]</w:r>
or
<w:rPr>Dear <w:b/></w:rPr>[ at ]<w:t>customername[ at ]</w:t></w:r>
etc.

I want to keep the [ at ] and unsername together like this...

<w:rPr>Dear <w:b/></w:rPr><w:t>[ at ]customername[ at ]</w:t></w:r>

Is that possible???

Thanks!

Mojo


Re: Search and replace my custom tags in WordML??
Cindy M -WordMVP- <C.Meister-C[ at ]hispeed.ch> 27.07.2006 15:10:12
Hi M,

[Quoted Text]
> I need to open a wordml document and search/replace some custom tags.
>
> The problem is, that when I open a wordml doc, the tags are messed up.
>
> My text look likes this "Dear [ at ]customername[ at ], ....", but when I open the
> wordml doc, it can look like this....
>
> <w:rPr>Dear <w:b/>[ at ]</w:rPr><w:t>customername</w:t>[ at ]</w:r>
> or
> <w:rPr>Dear <w:b/></w:rPr>[ at ]<w:t>customername[ at ]</w:t></w:r>
> etc.
>
> I want to keep the [ at ] and unsername together like this...
>
> <w:rPr>Dear <w:b/></w:rPr><w:t>[ at ]customername[ at ]</w:t></w:r>
>
> Is that possible???
>
I very much doubt that the WordML you're getting when you save a Word 2003
document looks like the samples you're showing us above. "Dear " would
certainly have to be within <w:t> tags; the [ at ] as well. I'm guessing that
you may be formatting the customername characters differently than the
surrounding [ at ]? That would break up the text run...

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 :-)

Re: Search and replace my custom tags in WordML??
M O J O <na[ at ]na.na> 27.07.2006 20:02:11
Hi Cindy,

My point was just to show that the '[ at ]' signs wasn't always together with
the customername. :o)

Let's say I want to load the xml file into Notepad and do a search and
replace (I don't want to use word to do the search and replace ... it
will be done on a computer that does not have word installed).

How can I make my own "tags" that will not be messed up by wordml-tags?

I want my user to create a word doc, type in text and add variables like
[ at ]customername[ at ]. Then my own .net application must open the xml file and
do a search and replace. Therefore the [ at ]customername[ at ] must stick together.

Hope you understand what I mean.

This is a BIG problem for me. :o(

Thanks!

Mojo


Cindy M -WordMVP- skrev:
[Quoted Text]
> Hi M,
>
>> I need to open a wordml document and search/replace some custom tags.
>>
>> The problem is, that when I open a wordml doc, the tags are messed up.
>>
>> My text look likes this "Dear [ at ]customername[ at ], ....", but when I open the
>> wordml doc, it can look like this....
>>
>> <w:rPr>Dear <w:b/>[ at ]</w:rPr><w:t>customername</w:t>[ at ]</w:r>
>> or
>> <w:rPr>Dear <w:b/></w:rPr>[ at ]<w:t>customername[ at ]</w:t></w:r>
>> etc.
>>
>> I want to keep the [ at ] and unsername together like this...
>>
>> <w:rPr>Dear <w:b/></w:rPr><w:t>[ at ]customername[ at ]</w:t></w:r>
>>
>> Is that possible???
>>
> I very much doubt that the WordML you're getting when you save a Word 2003
> document looks like the samples you're showing us above. "Dear " would
> certainly have to be within <w:t> tags; the [ at ] as well. I'm guessing that
> you may be formatting the customername characters differently than the
> surrounding [ at ]? That would break up the text run...
>
> 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 :-)
>
Re: Search and replace my custom tags in WordML??
"Dr. Eckehard Pfeifer" <privat[ at ]dr-e-pfeifer.newsgroup.de> 28.07.2006 12:37:22
Hi, I dont know, If I understand you correctly. Whats about your own
namespace concerning the parameters you signed as [ at ]parameter[ at ]? Like
<param xmlns="myNamespace">value</param>.

--
MfG EP
Entwicklung - Beratung - Training (www.dr-e-pfeifer.net)
(Microsoft Certified Application Developer)
neu: MS Office 2003 - Das Entwicklerbuch (ISBN 3-86063-688-X)

Re: Search and replace my custom tags in WordML??
Cindy M -WordMVP- <C.Meister-C[ at ]hispeed.ch> 28.07.2006 14:26:41
Hi Mojo,

But you see, on my machine the [ at ] signs aren't separated from the rest of the
text. Unless I format them differently or use Insert/Symbol. So it would be
important for you to show us EXACTLY what the problem is that you're
encountering - the WordML you're struggling with.

[Quoted Text]
> My point was just to show that the '[ at ]' signs wasn't always together with
> the customername. :o)
>
> Let's say I want to load the xml file into Notepad and do a search and
> replace (I don't want to use word to do the search and replace ... it
> will be done on a computer that does not have word installed).
>
> How can I make my own "tags" that will not be messed up by wordml-tags?
>
> I want my user to create a word doc, type in text and add variables like
> [ at ]customername[ at ]. Then my own .net application must open the xml file and
> do a search and replace. Therefore the [ at ]customername[ at ] must stick together.
>
> Hope you understand what I mean.
>
> This is a BIG problem for me. :o(
>

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 :-)

Re: Search and replace my custom tags in WordML??
M O J O <na[ at ]na.na> 31.07.2006 05:23:57
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
[ at ]customoername[ at ], the wordml will look like this...

....<w:p><w:r><w:t>[ at ]customername[ at ]</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 [ at ]customername[ at ].

But if the user wants to make it bold and by mistake forgets to
highlight the last [ at ], the wordml will look like this...

<w:rPr><w:b/></w:rPr><w:t>[ at ]customername</w:t></w:r><w:r><w:t>[ at ]</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 [ at ]customername[ at ], because
it's now called...

[ at ]customername</w:t></w:r><w:r><w:t>[ at ]

I would like my users to be able to enter a fieldname like [ at ]customernam[ at ]
in word and no matter what formatting they do on the field, the
[ at ]customername[ at ] must be intact.

Hope you get what I mean.

:o)

Thanks for still trying to help me out here!!

Mojo

Cindy M -WordMVP- skrev:
[Quoted Text]
> Hi Mojo,
>
> But you see, on my machine the [ at ] signs aren't separated from the rest of the
> text. Unless I format them differently or use Insert/Symbol. So it would be
> important for you to show us EXACTLY what the problem is that you're
> encountering - the WordML you're struggling with.
>
>> My point was just to show that the '[ at ]' signs wasn't always together with
>> the customername. :o)
>>
>> Let's say I want to load the xml file into Notepad and do a search and
>> replace (I don't want to use word to do the search and replace ... it
>> will be done on a computer that does not have word installed).
>>
>> How can I make my own "tags" that will not be messed up by wordml-tags?
>>
>> I want my user to create a word doc, type in text and add variables like
>> [ at ]customername[ at ]. Then my own .net application must open the xml file and
>> do a search and replace. Therefore the [ at ]customername[ at ] must stick together.
>>
>> Hope you understand what I mean.
>>
>> This is a BIG problem for me. :o(
>>
>
> 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 :-)
>
Re: Search and replace my custom tags in WordML??
"Peter Jamieson" <pjj[ at ]KillmapSpjjnet.demon.co.uk> 31.07.2006 08:15:40
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...

[Quoted Text]
> I would like my users to be able to enter a fieldname like [ at ]customernam[ at ]
> in word and no matter what formatting they do on the field, the
> [ at ]customername[ at ] 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 [ at ]customername[ at ] "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 "[ at ]" 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 "[ at ]".

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 [ at ]tag[ at ] tags, reporting on any
"solitary" "[ at ]" 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>[ at ]tag[ at ]</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
[ at ]tag[ at ] tags are reconstituted
- perform much the same checking for "solitary" "[ at ]" 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 [ at ]tag[ at ] tags and successively swapping the positions of XML tags and
plain text until the [ at ]tag[ at ] 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 "[ at ]" as your tag marker, or doubled it up to [ at ][ at ]. 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

"M O J O" <na[ at ]na.na> wrote in message
news:OS7HHGGtGHA.4324[ at ]TK2MSFTNGP05.phx.gbl...
> 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
> [ at ]customoername[ at ], the wordml will look like this...
>
> ...<w:p><w:r><w:t>[ at ]customername[ at ]</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 [ at ]customername[ at ].
>
> But if the user wants to make it bold and by mistake forgets to highlight
> the last [ at ], the wordml will look like this...
>
> <w:rPr><w:b/></w:rPr><w:t>[ at ]customername</w:t></w:r><w:r><w:t>[ at ]</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 [ at ]customername[ at ], because it's
> now called...
>
> [ at ]customername</w:t></w:r><w:r><w:t>[ at ]
>
> I would like my users to be able to enter a fieldname like [ at ]customernam[ at ]
> in word and no matter what formatting they do on the field, the
> [ at ]customername[ at ] 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, But you see, on my machine the [ at ] signs aren't separated from the
>> rest of the text. Unless I format them differently or use Insert/Symbol.
>> So it would be important for you to show us EXACTLY what the problem is
>> that you're encountering - the WordML you're struggling with.
>>> My point was just to show that the '[ at ]' signs wasn't always together with
>>> the customername. :o)
>>> Let's say I want to load the xml file into Notepad and do a search and
>>> replace (I don't want to use word to do the search and replace ... it
>>> will be done on a computer that does not have word installed).
>>> How can I make my own "tags" that will not be messed up by wordml-tags?
>>> I want my user to create a word doc, type in text and add variables
>>> like [ at ]customername[ at ]. Then my own .net application must open the xml file
>>> and do a search and replace. Therefore the [ at ]customername[ at ] must stick
>>> together.
>>> Hope you understand what I mean.
>>> This is a BIG problem for me. :o(
>>>
>>
>> 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 :-)
>>


Re: Search and replace my custom tags in WordML??
Cindy M -WordMVP- <C.Meister-C[ at ]hispeed.ch> 31.07.2006 10:12:53
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"...

[Quoted Text]
> 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
> [ at ]customoername[ at ], the wordml will look like this...
>
> ....<w:p><w:r><w:t>[ at ]customername[ at ]</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 [ at ]customername[ at ].
>
> But if the user wants to make it bold and by mistake forgets to
> highlight the last [ at ], the wordml will look like this...
>
> <w:rPr><w:b/></w:rPr><w:t>[ at ]customername</w:t></w:r><w:r><w:t>[ at ]</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 [ at ]customername[ at ], because
> it's now called...
>
> [ at ]customername</w:t></w:r><w:r><w:t>[ at ]
>
> I would like my users to be able to enter a fieldname like [ at ]customernam[ at ]
> in word and no matter what formatting they do on the field, the
> [ at ]customername[ at ] must be intact.
>
> 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 :-)

Re: Search and replace my custom tags in WordML??
M O J O <na[ at ]na.na> 31.07.2006 19:45:20
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:
[Quoted Text]
> 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
> [ at ]customoername[ at ], the wordml will look like this...
>
> ...<w:p><w:r><w:t>[ at ]customername[ at ]</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 [ at ]customername[ at ].
>
> But if the user wants to make it bold and by mistake forgets to
> highlight the last [ at ], the wordml will look like this...
>
> <w:rPr><w:b/></w:rPr><w:t>[ at ]customername</w:t></w:r><w:r><w:t>[ at ]</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 [ at ]customername[ at ], because
> it's now called...
>
> [ at ]customername</w:t></w:r><w:r><w:t>[ at ]
>
> I would like my users to be able to enter a fieldname like [ at ]customernam[ at ]
> in word and no matter what formatting they do on the field, the
> [ at ]customername[ at ] 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,
>> But you see, on my machine the [ at ] signs aren't separated from the rest
>> of the text. Unless I format them differently or use Insert/Symbol. So
>> it would be important for you to show us EXACTLY what the problem is
>> that you're encountering - the WordML you're struggling with.
>>> My point was just to show that the '[ at ]' signs wasn't always together
>>> with the customername. :o)
>>>
>>> Let's say I want to load the xml file into Notepad and do a search
>>> and replace (I don't want to use word to do the search and replace
>>> ... it will be done on a computer that does not have word installed).
>>>
>>> How can I make my own "tags" that will not be messed up by wordml-tags?
>>>
>>> I want my user to create a word doc, type in text and add variables
>>> like [ at ]customername[ at ]. Then my own .net application must open the xml
>>> file and do a search and replace. Therefore the [ at ]customername[ at ] must
>>> stick together.
>>>
>>> Hope you understand what I mean.
>>>
>>> This is a BIG problem for me. :o(
>>>
>>
>> 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 :-)
>>

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net