Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-21-2012, 01:44 PM
gmaxey gmaxey is offline CustomXMLParts.SelectByNamespace Windows 7 32bit CustomXMLParts.SelectByNamespace Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,598
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Maybe this will help:

PHP Code:
Sub DemoXYZ()
Dim oDoc As Word.Document
Dim oCustXMLPart As Office.CustomXMLPart
Dim oNode As CustomXMLNode
Dim lngIndex As Long
  Set oDoc = ActiveDocument
  'Kill any existing XMLPart used previously for mapping.
  On Error Resume Next
  oDoc.CustomXMLParts.SelectByNamespace("http://nsDemo").Item(1).Delete
  On Error GoTo 0
  'Create a basic XML Part with namespace.
  Set oCustXMLPart = ActiveDocument.CustomXMLParts.Add("<?xml version='1.0' encoding='utf-8'?><Root_Node xmlns='http://nsDemo'></Root_Node>")
  For lngIndex = 1 To 3
    oCustXMLPart.AddNode oCustXMLPart.SelectSingleNode("/ns0:Root_Node"), "Node_" & lngIndex
    Set oNode = oCustXMLPart.SelectSingleNode("/ns0:Root_Node[1]/Node_" & lngIndex & "[1]")
    oNode.Text = "Demo text " & lngIndex
  Next lngIndex
  'This is what you've got:
  Debug.Print oCustXMLPart.XML
  Set oCustXMLPart = Nothing
  'Set part by namespace
  Set oCustXMLPart = oDoc.CustomXMLParts.SelectByNamespace("http://nsDemo").Item(1)
  For Each oNode In oCustXMLPart.DocumentElement.ChildNodes
    Debug.Print "My text is: " & oNode.Text & ". My xPath is: " & oNode.XPath
  Next oNode
  'Or
  Set oNode = oCustXMLPart.SelectSingleNode("/ns0:Root_Node/Node_1[1]")
  MsgBox oNode.Text
lbl_Exit:
  Exit Sub
End Sub

__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply



Other Forums: Access Forums

All times are GMT -7. The time now is 11:29 AM.


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