편집

다음을 통해 공유


XMLMapping Interface

Definition

Represents the XML mapping on a ContentControl object between custom XML and a content control. An XML mapping is a link between the text in a content control and an XML element in the custom XML data store for this document.

public interface class XMLMapping
[System.Runtime.InteropServices.Guid("0C1FABE7-F737-406F-9CA3-B07661F9D1A2")]
public interface XMLMapping
type XMLMapping = interface
Public Interface XMLMapping
Attributes

Remarks

Use the SetMapping(String, String, CustomXMLPart) method to add or change the XML mapping for a content control using an XPath string. 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 objMap As XMLMapping































































































































Dim blnMap As Boolean































































































































































































































































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































































































































































































































































Set objcc = ActiveDocument.ContentControls.Add _































































































































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































































































































































































































































Set objMap = objcc.XMLMapping































































































































blnMap = objMap.SetMapping(XPath:="/ns1:coreProperties[1]/ns0:createdate[1]")































































































































































































































































If blnMap = False Then































































































































    MsgBox "Unable to map the content control."































































































































End If</span>

Use the SetMappingByNode(CustomXMLNode) method to add or change the XML mapping for a content control using a CustomXMLNode object. The following example does the same thing as the previous example, but uses the SetMappingByNode method.

<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 new CustomXMLPart object, loads custom XML into it, and then creates two new content controls and maps each to a different XML element 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;" &amp; _































































































































    "&lt;genre&gt;non-fiction&lt;/genre&gt;&lt;price&gt;29.95&lt;/price&gt;" &amp; _































































































































    "&lt;pub_date&gt;2/1/2007&lt;/pub_date&gt;&lt;abstract&gt;You see them in " &amp; _































































































































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































































































































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































































































































    "of the red breasted robin as it migrates to warmer climes " &amp; _































































































































    "in the fall, and then back to your back yard in the spring." &amp; _































































































































    "&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.SetMappingByNode objCustomNode































































































































































































































































objRange.InsertParagraphAfter































































































































Set objRange = ActiveDocument.Paragraphs(2).Range































































































































Set objCustomNode = objCustomPart.SelectSingleNode _































































































































    ("/books/book/abstract")































































































































Set objCustomControl = ActiveDocument.ContentControls _































































































































    .Add(wdContentControlText, objRange)































































































































objCustomControl.XMLMapping.SetMappingByNode objCustomNode































































































































































































































































MsgBox objCustomControl.XMLMapping.IsMapped</span>

Use the Delete() method to remove the XML mapping for a content control. Deleting the XML mapping for a content control deletes only the connection between the content control and the XML data. Both the content control and the XML data remain in the document. The following example deletes the XML mapping for all content controls in the active document that are currently mapped.

<span class="label">Dim objCC As ContentControl































































































































































































































































For Each objCC In ActiveDocument.ContentControls































































































































    If objCC.XMLMapping.IsMapped Then































































































































        objCC.XMLMapping.Delete































































































































    End If































































































































Next</span>

Use the IsMapped property to determine if a content control is mapped to an XML node in the document's data store. The following example deletes the XML mapping for all mapped content controls in the active document.

<span class="label">Dim objCC As ContentControl































































































































































































































































For Each objCC In ActiveDocument.ContentControls































































































































    If objCC.XMLMapping.IsMapped Then































































































































        objCC.XMLMapping.Delete































































































































    End If































































































































Next</span>

Use the CustomXMLNode property to access the XML node to which a content control maps. Use the CustomXMLPart property to access the XML part to which a content control maps. For more information about working with CustomXMLNode and CustomXMLPart objects, see the respective object topics.

Properties

Application

Returns an _Application object that represents the Microsoft Word application.

Creator

Returns a 32-bit integer that indicates the application in which the add-in was created. Read-only Long.

CustomXMLNode

Returns a CustomXMLNode object that represents the custom XML node in the data store to which the content control in the document maps.

CustomXMLPart

Returns a CustomXMLPart object that represents the custom XML part to which the content control in the document maps.

IsMapped

Returns a Boolean that represents whether the content control in the document is mapped to an XML node in the document’s XML data store. Read-only.

Parent

Returns an Object that represents the parent object of the specified XMLMapping object.

PrefixMappings

Returns a String that represents the prefix mappings used to evaluate the XPath for the current XML mapping. Read-only.

XPath

Returns a String that represents the XPath for the XML mapping, which evaluates to the currently mapped XML node. Read-only.

Methods

Delete()

Deletes the XML mapping from the parent content control.

SetMapping(String, String, CustomXMLPart)

Allows creating or changing the XML 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.

SetMappingByNode(CustomXMLNode)

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.

Applies to