XMLMapping.SetMappingByNode Method

Allows creating or changing the XML data mapping on a content control. Returns True if Microsoft Office Word maps the content control to a custom XML node in the document’s custom XML data store.

Namespace:  Microsoft.Office.Interop.Word
Assembly:  Microsoft.Office.Interop.Word (in Microsoft.Office.Interop.Word.dll)

Syntax

'Declaration
Function SetMappingByNode ( _
    Node As CustomXMLNode _
) As Boolean
'Usage
Dim instance As XMLMapping
Dim Node As CustomXMLNode
Dim returnValue As Boolean

returnValue = instance.SetMappingByNode(Node)
bool SetMappingByNode(
    CustomXMLNode Node
)

Parameters

  • Node
    Type: CustomXMLNode
    Specifies the XML node to which to map the current content control.

Return Value

Type: System.Boolean
Boolean

Remarks

If the XML mapping already exists, then Word replaces the existing XML mapping, and the contents of the new mapped XML node replaces the text of the content control. See also the SetMapping(String, String, CustomXMLPart) method.

Note

Creating a mapping for a rich-text content control causes a run-time error.

Examples

The following example sets the built-in document property for the document author, inserts a new content control into the active document, and then sets the XML mapping for the control to the built-in document property.

Dim objcc As ContentControl































































































































Dim objNode As CustomXMLNode































































































































Dim objMap As XMLMapping































































































































Dim blnMap As Boolean































































































































































































































































ActiveDocument.BuiltInDocumentProperties("Author").Value = "David Jaffe"































































































































































































































































Set objcc = ActiveDocument.ContentControls.Add _































































































































    (wdContentControlDate, ActiveDocument.Paragraphs(1).Range)































































































































    































































































































Set objNode = ActiveDocument.CustomXMLParts.SelectByNamespace _































































































































    ("https://schemas.openxmlformats.org/package/2006/metadata/core-properties") _































































































































    (1).DocumentElement.ChildNodes(1)































































































































































































































































Set objMap = objcc.XMLMapping































































































































blnMap = objMap.SetMappingByNode(objNode)

The following example creates a custom XML part, and then creates two content controls and maps each content control to a specific node within the custom XML.

Dim objRange As Range































































































































Dim objCustomPart As CustomXMLPart































































































































Dim objCustomControl As ContentControl































































































































Dim objCustomNode As CustomXMLNode































































































































































































































































Set objCustomPart = ActiveDocument.CustomXMLParts.Add































































































































objCustomPart.LoadXML ("<books><book><author>Matt Hink</author>" & _































































































































    "<title>Migration Paths of the Red Breasted Robin</title><genre>non-fiction</genre>" & _































































































































    "<price>29.95</price><pub_date>2007-02-01</pub_date><abstract>" & _































































































































    "You see them in the spring outside your windows.  You hear their lovely " & _































































































































    "songs wafting in the warm spring air.  Now follow the path of the red breasted robin " & _































































































































    "as it migrates to warmer climes in the fall, and then back to your back yard " & _































































































































    "in the spring.</abstract></book></books>")































































































































































































































































ActiveDocument.Range.InsertParagraphBefore































































































































Set objRange = ActiveDocument.Paragraphs(1).Range































































































































Set objCustomNode = objCustomPart.SelectSingleNode _































































































































    ("/books/book/title")































































































































Set objCustomControl = ActiveDocument.ContentControls _































































































































    .Add(wdContentControlText, objRange)































































































































objCustomControl.XMLMapping.SetMappingByNodeobjCustomNodeobjRange.InsertParagraphAfterSet objRange = ActiveDocument.Paragraphs(2).RangeSet objCustomNode = objCustomPart.SelectSingleNode _    ("/books/book/abstract")Set objCustomControl = ActiveDocument.ContentControls _    .Add(wdContentControlText, objRange)objCustomControl.XMLMapping.SetMappingByNodeobjCustomNode

See Also

Reference

XMLMapping Interface

XMLMapping Members

Microsoft.Office.Interop.Word Namespace