Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #13  
Old 06-15-2017, 04:45 PM
gmaxey gmaxey is offline Problem adding a namespace for customxml Windows 7 32bit Problem adding a namespace for customxml Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem batch adding autotext using Greg Maxey's Building Blocks Add-In Genuine Gin Word VBA 5 12-16-2015 10:20 AM
Problem Sending Command to the Program - Office or Windows Problem ?? JosieNurse Office 0 04-21-2015 11:49 AM
Problem adding a namespace for customxml Problem with Resolution when adding a picture in 2010 Zimm PowerPoint 1 11-13-2013 12:15 PM
Problem adding a namespace for customxml Problem with adding a footnote in Word Swarles_Barkley Word 1 11-12-2013 11:42 PM
Problem adding a namespace for customxml Adding Image into a excel cell and adding a hyperlink to the image saravananiyyanar Excel 3 05-04-2011 08:31 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:01 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft