Need to associate content control binding with correct custom XML part
-
mercredi 1 août 2012 21:57
I have a program manipulating (Word 2007/2010) documents that have multiple custom xml parts. 2 of these custom xml parts are identified by namespaces that are known to my program. Other parts may or may not have namespace identifications and my program does not want or need to access to those at all.
The document contains content controls with bindings to any one the custom xml parts. During processing, my program selects certain content controls and changes the bindings. But I only want to touch the bindings that link to custom xml parts I know about.
I see that in the w:dataBinding node there is a w:storeItemID attribute in addition the the w:xpath and it appears that it is identifying a particular custom XML part. What I can't figure out is how I find which storeItemID value(s) is associated with the custom XML part(s) that I care about. I'm guesing that I need to access some metadata about my custom xml parts and the storeItemID will be part of that.
Here is some code that I would change to limit the selection to the w:storeItemIDs that I care about, once I figure out what they are.
XmlNodeList lcXPathBindingNodeList = pcDocPkgPartXml.SelectNodes(".//w:sdt/w:sdtPr/w:dataBinding", mcNsMgr);
Any ideas?
Toutes les réponses
-
vendredi 3 août 2012 04:42Modérateur
Hi scw-tzg,
Thanks for posting in the MSDN Forum.
I will involve some experts into your issue to see whether them can help you. There might be some time delay, appreciate for your patience.
Have a good day,
TomTom Xu [MSFT]
MSDN Community Support | Feedback to us
-
lundi 6 août 2012 19:32Modérateur
Hi scw-tzg
In the content in the MSDN article -
XMLMapping.CustomXMLPart Property (Microsoft.Office.Interop.Word)
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.xmlmapping.customxmlpart.aspxThere is simple VBA code to retrieve the binding - this is the code:
Dim objCC As ContentControl
Dim objPart As CustomXMLPart
im objNode As CustomXMLNode
Set objCC = ActiveDocument.ContentControls(1)
Set objPart = objCC.XMLMapping.CustomXMLPartSet objNode = objPart.SelectSingleNode("/books/book/title")objNode.Text = "Mystery of the Empty Chair"Other content and links that may help you determine how to identify the custom parts mapped to controls in your documents are in the list below.
DataBinding Properties
http://msdn.microsoft.com/en-us/library/office/documentformat.openxml.wordprocessing.databinding_properties.aspxDataBinding Class (DocumentFormat.OpenXml.Wordprocessing)
http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.databinding.aspxSee the content in the following Forum Thread:
How to get the value of a content control in word document using XML
http://social.msdn.microsoft.com/Forums/en-US/oxmlsdk/thread/ddeed0c3-d532-49c4-b9b1-c193fe94d2a4Walkthrough: Binding Content Controls to Custom XML Parts
http://msdn.microsoft.com/en-us/library/bb398244.aspxTaking Advantage of Bound Content Controls - Brian Jones: Office ...
http://blogs.msdn.com/b/brian_jones/archive/2009/01/05/taking-advantage-of-bound-content-controls.aspxAlso See:
Word Content Control Toolkit
http://WWW.Codeplex.com/wikipage?projectName=dbe
And:
Open XML SDK Code behind the Custom XML Markup Detection Tool ...
http://blogs.msdn.com/b/brian_jones/archive/2010/01/27/open-xml-sdk-code-behind-the-custom-xml-markup-detection-tool.aspxPlease remember to mark the replies as answer if they help and unmark them if they provide no help. and click "Vote as Helpful" this and other helpful posts, so other users will see your thread as useful. Best Regards, Chris Jensen
- Marqué comme réponse scw-tzg mardi 7 août 2012 21:01
-
mardi 7 août 2012 21:01
Here's what I ended up doing to find data store item id:
IEnumerable<CustomXmlPart> customParts = myDoc.MainDocumentPart.CustomXmlParts; foreach (var customPart in customParts) { if (customPart.CustomXmlPropertiesPart.DataStoreItem.SchemaReferences.OuterXml.Contains(<NamespaceICareAbout>)) { _datastoreItemId = customPart.CustomXmlPropertiesPart.DataStoreItem.ItemId; break; } }
Then here's how I grabbed 'my' content control nodes:
XmlNodeList XPathBindingNodeList = DocPkgPartXml.SelectNodes(string.Format(".//w:sdt/w:sdtPr/w:dataBinding[@w:storeItemID='{0}']", _datastoreItemId), mcNsMgr);
Thanks for the links cjatms.
- Marqué comme réponse scw-tzg mardi 7 août 2012 21:01

