Search and replace my custom tags in WordML??

M

M O J O

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 @customername@, ....", but when I open the
wordml doc, it can look like this....

<w:rPr>Dear <w:b/>@</w:rPr><w:t>customername</w:t>@</w:r>
or
<w:rPr>Dear <w:b/></w:rPr>@<w:t>customername@</w:t></w:r>
etc.

I want to keep the @ and unsername together like this...

<w:rPr>Dear <w:b/></w:rPr><w:t>@customername@</w:t></w:r>

Is that possible???

Thanks!

Mojo
 
C

Cindy M -WordMVP-

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 @customername@, ....", but when I open the
wordml doc, it can look like this....

<w:rPr>Dear <w:b/>@</w:rPr><w:t>customername</w:t>@</w:r>
or
<w:rPr>Dear <w:b/></w:rPr>@<w:t>customername@</w:t></w:r>
etc.

I want to keep the @ and unsername together like this...

<w:rPr>Dear <w:b/></w:rPr><w:t>@customername@</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 @ as well. I'm guessing that
you may be formatting the customername characters differently than the
surrounding @? 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 :)
 
M

M O J O

Hi Cindy,

My point was just to show that the '@' signs wasn't always together with
the customername. :eek:)

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
@customername@. Then my own .net application must open the xml file and
do a search and replace. Therefore the @customername@ must stick together.

Hope you understand what I mean.

This is a BIG problem for me. :eek:(

Thanks!

Mojo


Cindy M -WordMVP- skrev:
 
D

Dr. Eckehard Pfeifer

Hi, I dont know, If I understand you correctly. Whats about your own
namespace concerning the parameters you signed as @parameter@? Like
<param xmlns="myNamespace">value</param>.
 
C

Cindy M -WordMVP-

Hi Mojo,

But you see, on my machine the @ 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 '@' signs wasn't always together with
the customername. :eek:)

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
@customername@. Then my own .net application must open the xml file and
do a search and replace. Therefore the @customername@ must stick together.

Hope you understand what I mean.

This is a BIG problem for me. :eek:(

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

M O J O

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.

:eek:)

Thanks for still trying to help me out here!!

Mojo

Cindy M -WordMVP- skrev:
 
P

Peter Jamieson

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
 
C

Cindy M -WordMVP-

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.

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.

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

M O J O

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:
 

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