SC,
I am far from an expert in this arena and agree with your "bit of a black box," but this aspect isn't as mystical as it may seem.
It isn't that Words CustomXMLParts insists on creating prefixes, it is if your XML uses a names space then to access the nodes you must reference the namespace prefix. If you don't name it something then Word automatically uses the default namespace prefix ns0.
Run this little demo and you can see for yourself:
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 with an unprefixed namespace.
strXML = "<Root xmlns='SomeNameSpace'><NodeA></NodeA><NodeB></NodeB></Root>"
Set oXMLPart = ActiveDocument.CustomXMLParts.Add(strXML)
'Then you must use the default namespace prefix.
oXMLPart.SelectSingleNode("/*/ns0:NodeA[1]").Text = "Some Value"
MsgBox oXMLPart.SelectSingleNode("/*/ns0:NodeA[1]").Text
On Error GoTo Err_Handler:
oXMLPart.SelectSingleNode("/*/NodeB[1]").Text = "Some Value"
MsgBox oXMLPart.SelectSingleNode("/*/NodeA[B]").Text
lbl_ReEntry:
Stop
'Create a simple XMLPart without a namespace:
strXML = "<Root><NodeA></NodeA><NodeB></NodeB></Root>"
Set oXMLPart = ActiveDocument.CustomXMLParts.Add(strXML)
oXMLPart.SelectSingleNode("/*/NodeA[1]").Text = "See, no namespace prefix required"
MsgBox oXMLPart.SelectSingleNode("/*/NodeA[1]").Text
lbl_Exit:
Exit Sub
Err_Handler:
MsgBox Err.Number & " " & Err.Description
Resume lbl_ReEntry
End Sub