Teilen über


XMLMapping.SetMappingByNode-Methode (Word)

Ermöglicht das Erstellen oder Ändern der XML-Datenzuordnung für ein Inhaltssteuerelement. Gibt True zurück, wenn Microsoft Word das Inhaltssteuerelement einem benutzerdefinierten XML-Knoten im benutzerdefinierten XML-Datenspeicher des Dokuments zuordnet.

Syntax

Ausdruck. SetMappingByNode( _Node_ )

Ausdruck Ein Ausdruck, der ein XMLMapping-Objekt zurückgibt.

Parameter

Name Erforderlich/Optional Datentyp Beschreibung
Knoten Erforderlich CustomXMLNode Gibt den XML-Knoten an, dem das aktuelle Inhaltssteuerelement zugeordnet werden soll.

Rückgabewert

Boolesch

Bemerkungen

Wenn die XML-Zuordnung bereits vorhanden ist, ersetzt Word die vorhandene XML-Zuordnung, und der Text des Inhaltssteuerelements wird durch den Inhalt des neu zugeordneten XML-Knotens ersetzt. Siehe auch die SetMapping-Methode .

Hinweis

Beim Erstellen einer Zuordnung für ein Rich-Text-Inhaltssteuerelement tritt ein Laufzeitfehler auf.

Beispiel

Im folgenden Beispiel wird die integrierte Dokumenteigenschaft für den Autor des Dokuments festgelegt, ein neues Inhaltssteuerelement in das aktive Dokument eingefügt und dann die XML-Zuordnung für das Steuerelement auf die integrierte Dokumenteigenschaft festgelegt.

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)

Im folgenden Beispiel werden zunächst eine benutzerdefinierte XML-Komponente und dann zwei Inhaltssteuerelemente erstellt. Daraufhin werden die Inhaltssteuerelemente einem bestimmten Knoten im benutzerdefinierten XML-Code zugeordnet.

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.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

Siehe auch

XMLMapping-Objekt

Support und Feedback

Haben Sie Fragen oder Feedback zu Office VBA oder zu dieser Dokumentation? Unter Office VBA-Support und Feedback finden Sie Hilfestellung zu den Möglichkeiten, wie Sie Support erhalten und Feedback abgeben können.