How to detect if a single Word XML bracket is selected?

R

Rob Stewart

I think I have stumbled onto a way for this in the past, but cannot recall it
- so I'm pretty sure it is possible...

In Word 2003, if you have a current cursor selection of 1 character length,
and that character is either a single opening or closing bracket of an XML
tag (i.e. no text selected, just one of the purple/white brackets), how can
you detect that?

asc( Selection ) produces an error as the bracket does not have an ASCII
value, and Selection.Text returns no value (and is not null).

There must be a way to detect this? FYI I need to do this in C#, but I'd
think that would be irrelevant.

Cheers,
Rob
 
P

Peter Huang

Hi Rob,

Now I am research the issue.
Can you tell me why you need to do that? Maybe we will have another
solution.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
R

Rob Stewart

Hi Peter,

It's a bit long winded, but here goes ... !

I need to do this because our application divides large blocks of text (that
are contained in XML tags) up into smaller segments. It does this by counting
(i.e. extending the selection) one word at a time, until a predefined segment
length (e.g. 100 words) is reached.

Once the 100 words has been reached, the segment must end on the next full
stop (so that a sentence isn't cut in half), so the selection keeps extending
word by word until a full stop is selected as the last charater.

Each time the selection extends, the last character of the selection is
examined for it's ASCII code, to determine whether or not it is a full stop.
This is fine most of the time. However, we have rules that a segment cannot
go across a new paragraph, or across XML tags, so as soon as either is
reached, the current segment is ended, regardless of whether or not a full
stop is reached.

I can detect both the full stop & the paragraph marker, however in rare
instances where the current XML tag ends before a full stop/paragraph (and
therefore the selection now contains a closing XML bracket as it's last
"character"), I am running into this error as I cannot "recognise" the
closing bracket.

====================
e.g. (using a segment length of 5 words)

<paragraph1>The black cat sat on the mat and ate a rat.</paragraph1>

This would be broken up as follows:
<paragraph1><segment>The black cat sat on </segment><segment>the mat and ate
a rat.</segment></paragraph1>

However, if there was no fullstop after "rat", the selection extends to
include the </paragraph> bracket, and this is where I'm having the problem.
====================

This functionality is part of a major development project that is nearing
completion, so there isn't a lot of room for alternate solutions. This has
been working very well for 10 months, it's just that it's only now we are
encountering blocks of text that don't end in a full stop.

Any help appreciated, as always!

Regards,
Rob
 
P

Peter Huang

Hi Rob,

Thank you for you input.
So far I think you may try the code below.
If Selection.XMLNodes.Count = 1 and Selection.Start = Selection.End - 1
then
'*** exactly a single XML tag is selected
End if

The code is for VBA, I think you may need to translate into C#, if you
still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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