I don't know this stuff in detail either.
But very briefly,
a. the Word macro recorder is your friend. If you switch it on, select
some text and apply an element, you will see that it records something like
Activedocument.XMLNodes.Add "elementname", "schemaname"
b. typically any kind of automated operation along the lines you
mention requires that you
- look up the help/documentation for any objects you are unfamiliar
with - e.g. the XMLNodes collection)
- experiment to discover whether you can Add objects by applying them
to a Range object, or if that is not possible, the Selection object
- work out how you are going to specify those Range objects, or make
the necessary Selections. If you can Add an object to a Range, you will
typically be able to do it by using Selection.Range as well.
- experiment to discover other practical difficulties. e.g. if you
nest a second element, the recorder does not record the schemaname and
in fact providing it causes an error (which does not appear either to be
what the documentation claims or a particularly sensible way to do
things, but there you go)
So in the example you mention, you start with something like
Sub ApplyElements()
' Assume your schema is called "myschema"
' "Content" is a range that specifies
' the entire content of the document body
ActiveDocument.Content.XMLNodes.Add "doc", "myschema"
ActiveDocument.Paragraphs(1).Range.XMLNodes.Add "h1", ""
ActiveDocument.Paragraphs(2).Range.XMLNodes.Add "p", ""
End Sub
A simple refinement that may help clarity is
Sub ApplyElements()
' Assume your schema is called "myschema"
' "Content" is a range that specifies
' the entire content of the document body
With ActiveDocument
.Content.XMLNodes.Add "doc", "myschema"
.Paragraphs(1).Range.XMLNodes.Add "h1", ""
.Paragraphs(2).Range.XMLNodes.Add "p", ""
Wend
End Sub
Beyond that, it's up to you to work how to do what you /really/ want
Peter Jamieson
http://tips.pjmsn.me.uk
Visit Londinium at
http://www.ralphwatson.tv