Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-19-2019, 06:14 PM
skylinekiller skylinekiller is offline adding an item to XML Mapping schema Windows 10 adding an item to XML Mapping schema Office 2016
Novice
adding an item to XML Mapping schema
 
Join Date: Nov 2019
Posts: 5
skylinekiller is on a distinguished road
Default 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.
Attached Images
File Type: jpg XML Mapping.jpg (177.2 KB, 27 views)
Attached Files
File Type: docx Script for Forum.docx (165.3 KB, 8 views)
Reply With Quote
  #2  
Old 11-19-2019, 07:43 PM
Guessed's Avatar
Guessed Guessed is offline adding an item to XML Mapping schema Windows 10 adding an item to XML Mapping schema Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #3  
Old 11-19-2019, 09:00 PM
skylinekiller skylinekiller is offline adding an item to XML Mapping schema Windows 10 adding an item to XML Mapping schema Office 2016
Novice
adding an item to XML Mapping schema
 
Join Date: Nov 2019
Posts: 5
skylinekiller is on a distinguished road
Default

Guessed,
Thank you for the response. What do you mean by
Quote:
add a namespace to the xml file
Lastly, how would I create the macro to do that and how would it work? Would I be able to use it for other documents or does it have to made for each document?
Reply With Quote
  #4  
Old 11-19-2019, 09:35 PM
Guessed's Avatar
Guessed Guessed is offline adding an item to XML Mapping schema Windows 10 adding an item to XML Mapping schema Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #5  
Old 11-19-2019, 09:59 PM
Guessed's Avatar
Guessed Guessed is offline adding an item to XML Mapping schema Windows 10 adding an item to XML Mapping schema Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #6  
Old 11-21-2019, 01:32 AM
skylinekiller skylinekiller is offline adding an item to XML Mapping schema Windows 10 adding an item to XML Mapping schema Office 2016
Novice
adding an item to XML Mapping schema
 
Join Date: Nov 2019
Posts: 5
skylinekiller is on a distinguished road
Default Macro

Thank you. This looks beyond my skill level, but I will give it a go
Reply With Quote
  #7  
Old 11-21-2019, 02:56 PM
Guessed's Avatar
Guessed Guessed is offline adding an item to XML Mapping schema Windows 10 adding an item to XML Mapping schema Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
  #8  
Old 11-21-2019, 08:13 PM
macropod's Avatar
macropod macropod is offline adding an item to XML Mapping schema Windows 7 64bit adding an item to XML Mapping schema Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply

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
adding an item to XML Mapping schema 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

Other Forums: Access Forums

All times are GMT -7. The time now is 09:45 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft