XMLMapping.SetMappingByNode(CustomXMLNode) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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.
public:
bool SetMappingByNode(Microsoft::Office::Core::CustomXMLNode ^ Node);
public bool SetMappingByNode (Microsoft.Office.Core.CustomXMLNode Node);
abstract member SetMappingByNode : Microsoft.Office.Core.CustomXMLNode -> bool
Public Function SetMappingByNode (Node As CustomXMLNode) As Boolean
Parameters
- Node
- CustomXMLNode
Specifies the XML node to which to map the current content control.
Returns
Boolean
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.
<span class="label">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 _
("http://schemas.openxmlformats.org/package/2006/metadata/core-properties") _
(1).DocumentElement.ChildNodes(1)
Set objMap = objcc.XMLMapping
blnMap = objMap.SetMappingByNode(objNode)</span>
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.
<span class="label">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.</span>
<span class="label">SetMappingByNode</span>
<span class="label">objCustomNodeobjRange.InsertParagraphAfterSet objRange = ActiveDocument.Paragraphs(2).RangeSet objCustomNode = objCustomPart.SelectSingleNode _ ("/books/book/abstract")Set objCustomControl = ActiveDocument.ContentControls _ .Add(wdContentControlText, objRange)objCustomControl.XMLMapping.</span>
<span class="label">SetMappingByNode</span>
<span class="label">objCustomNode</span>
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.