Apply formatting to XML Tag

A

Alicia

Hi,
Could anyone help me with these please

I have the following situation:
The user has a blank word document with a schema attached and has to add
text to that document and tag the text accordingly. Now, i want to show each
tag he adds with a different style. For eg, if he tags text with the <title>
tag, i would like these texts to be displayed in bold with green highlight.
he tags text with the <subtitle> tag, i would like these texts to be
displayed in italic.

Is there a way to achieve this?

Thanks
Alicia
 
A

Alicia

I have used the following VBA code in word 2003 , to try to assign
userdefined styles to each tag.

Private Sub Document_XMLAfterInsert(ByVal NewXMLNode As XMLNode, ByVal
InUndoRedo As Boolean)
If NewXMLNode.BaseName = "Title" Then
NewXMLNode.Range.Style = ActiveDocument.Styles("StyleTitle")
End If
If NewXMLNode.BaseName = "Subtitle" Then
NewXMLNode.Range.Style = ActiveDocument.Styles("StyleSubtitle")
End If
End Sub

Using this approach, a particular style is selected when i insert a tag. it
works if I tag some text as Title and then tag some other text as SubTitle.
But if i insert a Title tag ,then a Subtitle Tag, and then proceed to enter
the text in those two tags, the formatting of the title tag is that of the
subtitle tag.( The code does not set the style for a particular tag's range
as i thought it would). Moreover, if i enter text in any other tag for which
the style is not defined, the style is the same as the last programmatically
applied style.
This is my first attempt at VBA.I dont know if i've missed anything.

I was also wondering whether it is possible to have a macro which sets the
style each time i click inside an xml tag od whether it is possible to do
that through code.

Could anyone help me with this please?
Any help will be greatly appreciated.

Desperately
Alicia
 

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