0

I have a Word document with one mergeField who has name "NBJ"
MergeField

I open document.xml and I found

<w:instrText xml:space="preserve"> MERGEFIELD NB</w:instrText>

The document works fine, but I don't understand why I haven't the same merge field name ?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Joc02
  • 345
  • 8
  • 18

1 Answers1

1

Field coding can be split into more than one element, so if you have another look at your document's XML my guess is that you will find another such element whose text content starts with "J".

In general, when you are dealing with XML encoding in Word, you need to be aware that Word frequently splits texts into several pieces. It certainly isn't always obvious why, but two common reasons are:

  • There is different formatting for different parts of the text. You wouldn't normally need that or get that in the name of a merge field, but for example, the first "run" of a field code may be formatted because someone needs to use the *Charformat field switch to apply that format to the entire field result
  • Change tracking has recorded that you have changed/added/deleted one part of the text.
  • It is correct, I find another element with "J". But I parse "manually" the document.xml for find all "MERGEFIELD". What is the best way for create the MERGEFIEL list ? Or how I can consolidate the 2 parts of my MERGEFIELD ? – Joc02 May 03 '16 at 13:40
  • Well, it's not trivial (e.g. the instrText elements are not child elements of a single "field" element. Word also allows field nesting). I would have to work this out from scratch myself, so at this point I think you should (a) research it a bit more, have a look at the XML and what you could do with XPath, for example, then if you still can't work it out, post your effort and see if anyone can help... –  May 03 '16 at 13:52
  • @Joc02 I would suggest you to create a logic around occurrences of "" and "". You would search for instrText elements inside a "begin"-"end" range, also you should take into account the occurrences of another "begin" inside the "begin" (the child field elements inside the parent field's instruction inlines. – Mario Z May 04 '16 at 07:57
  • @Joc02 having a look at Eric White's material (e.g. here: http://ericwhite.com/blog/introduction-to-wordprocessingml-series/ ) could be a useful place to start. –  May 04 '16 at 08:51