#1
|
|||
|
|||
adding an item to XML Mapping schema
I have a document that I use XML mapping to auto-populate content control boxes throughout the document. I created the original XML Schema in the WORD 207 content control toolkit. The question I have is while in the DEVELOPER tab, and after clicking the XML Mapping Pane, how can I add an item to a selected CUSTOM XML part within word.
Once in the XML Mapping, select (no namespace) (2). This is the one I am trying to add to. Is this possible to do this within WORD or do I have to use the old 2007 Content Control toolkit. |
#2
|
||||
|
||||
The Word interface doesn't let you do it directly unless you are using the Repeating Section Content Control in which case you can create 2nd, 3rd etc instances of the same element. You don't NEED to use the content control toolkit but it might be easier than the alternatives.
Your choices when you don't have access to the Content Control Toolkit are: 1. Close the document and use a Zip file editor to edit the embedded xml file directly 2. Use a macro to add an element. I would recommend you add a namespace to the xml file so you don't keep adding xml files that are not explicitly findable.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Guessed,
Thank you for the response. What do you mean by Quote:
|
#4
|
||||
|
||||
A namespace allows Word (and you) to identify exactly which xml file you are looking at. Your sample document has two documents with no namespace - so the second one is shown as '(no namespace)(2)'. If the first one was deleted then it would likely appear as a different entry and possibly break all your linked CCs.
If you create the xml file and put it into the template, any new docs created from that template would already contain the xml file. I can give you code to work on your provided sample doc but you have a bunch of unnamed CCs and so there would be a lot of missing pieces until that is resolved. A better solution to make you self-sufficient would be to point you at Greg Maxey's site where he has a very slick tool which is very useful for this type of task. See Content Control Tools
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
||||
|
||||
If you wanted to look at a macro solution, the code that would remove your existing xml and introduce a new named xml file might look like the following. You could add to the sFields line to include more element names. Note that you will need to relink your existing CCs any time you change the namespace (the sNS value in this code).
Code:
Sub AddCustomPart() MsgBox fnCustomPart.XML, vbOKOnly, "Custom XML added" End Sub Function fnCustomPart() As Office.CustomXMLPart 'Creates/Recreates the standard CustomXmlPart (and removes xml with blank namespaces) Dim arrElements() As String, iElement As Integer, sFields As String, sXML As String, sNS As String Dim oXMLPart As Office.CustomXMLPart sNS = "http://schema.usaf.gov/commandchange" For Each oXMLPart In ActiveDocument.CustomXMLParts If oXMLPart.NamespaceURI = sNS Or oXMLPart.NamespaceURI = "" Then Debug.Print oXMLPart.XML oXMLPart.Delete End If Next sFields = "chaplin|cot|cotr|guideon|icc|iccfn|iccr|narr|narrr|narrfn|occ|occfn|occr|po|pofn|poduty|por|sq_grp|vol|volr|formation" arrElements = Split(sFields, "|") For iElement = LBound(arrElements) To UBound(arrElements) sXML = sXML & " <" & arrElements(iElement) & " />" & vbCr Next iElement sXML = "<?xml version='1.0' encoding='utf-8'?>" & vbCr & "<Root xmlns='" & sNS & "'>" & vbCr & sXML & "</Root>" Set fnCustomPart = ActiveDocument.CustomXMLParts.Add(sXML) 'Debug.Print AddCustomPart.XML End Function
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#6
|
|||
|
|||
Macro
Thank you. This looks beyond my skill level, but I will give it a go
|
#7
|
||||
|
||||
It is pretty easy really if you use Greg's tool. Certainly easier than using the Content Control Toolkit you have already worked with.
Start by populating the title property of every CC in your document and then use the tool to InstaMap.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#8
|
||||
|
||||
Cross-posted at: adding an item to XML Mapping
For cross-posting etiquette, please read: Excelguru Help Site - A message to forum cross posters
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
.MPP Schema for Parsing | iphoenix | Project | 0 | 08-11-2019 06:56 AM |
adding PDF describing the item listed in a word list | franciselmes | Word | 2 | 10-10-2017 03:00 PM |
Copying data related to one item to worksheet with many instances of the same item | nmp13 | Excel | 3 | 02-06-2016 02:13 AM |
Adding another item to the end of an existing list | cdrdash | Word | 2 | 01-28-2015 09:53 AM |
i have a problem about Wml2XSLT and XML and Schema | happyforever | Office | 0 | 11-02-2005 08:53 PM |