Modifica

Condividi tramite


XMLMapping.SetMappingByNode(CustomXMLNode) Method

Definition

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 ("&lt;books&gt;&lt;book&gt;&lt;author&gt;Matt Hink&lt;/author&gt;" &amp; _































































































































    "&lt;title&gt;Migration Paths of the Red Breasted Robin&lt;/title&gt;&lt;genre&gt;non-fiction&lt;/genre&gt;" &amp; _































































































































    "&lt;price&gt;29.95&lt;/price&gt;&lt;pub_date&gt;2007-02-01&lt;/pub_date&gt;&lt;abstract&gt;" &amp; _































































































































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































































































































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































































































































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































































































































    "in the spring.&lt;/abstract&gt;&lt;/book&gt;&lt;/books&gt;")































































































































































































































































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.

Applies to