SC,
I tinkered a bit and thought I would share the findings:
Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim strXML As String
Dim oXMLPart As CustomXMLPart
Dim lngIndex As Long
For lngIndex = ActiveDocument.CustomXMLParts.Count To 4 Step -1
ActiveDocument.CustomXMLParts(lngIndex).Delete
Next
'Create a simple XMLPart without a namespace.
strXML = "<Root><NodeA>No namespace prefix required in XPath</NodeA></Root>"
Set oXMLPart = ActiveDocument.CustomXMLParts.Add(strXML)
MsgBox oXMLPart.SelectSingleNode("/*/NodeA[1]").Text
'Create a simple XMLPart with an unprefixed default namespace.
strXML = "<Root xmlns='SomeNameSpace'><NodeA>Default prefix ns0 required in xPath</NodeA></Root>"
Set oXMLPart = ActiveDocument.CustomXMLParts.Add(strXML)
'Then you must use the default namespace prefix.
MsgBox oXMLPart.SelectSingleNode("/*/ns0:NodeA[1]").Text
'Create a simple XMLPart with a prefixed namespace:
strXML = "<Root xmlns:a='SomeNameSpace'><a:NodeA>You can use the default prefix ns0</a:NodeA><a:NodeB></a:NodeB></Root>"
Set oXMLPart = ActiveDocument.CustomXMLParts.Add(strXML)
MsgBox oXMLPart.SelectSingleNode("/*/ns0:NodeA[1]").Text
On Error Resume Next
MsgBox oXMLPart.SelectSingleNode("/*/a:NodeC[1]").Text
If Err.Number <> 0 Then
oXMLPart.NamespaceManager.AddNamespace "a", "SomeNameSpace"
oXMLPart.SelectSingleNode("/*/a:NodeA[1]").Text = "Before using your custom namespace prefixe you must add it to the XMLPart with the NamespaceManager"
MsgBox oXMLPart.SelectSingleNode("/*/a:NodeA[1]").Text
End If
lbl_Exit:
Exit Sub
End Sub