none
WordProcessingML - Unique Paragraph Identifier RRS feed

  • Question

  • I'm reviewing the documentatio for OpenXml WordProcessing.  I'd like to be able to make a template with paragraphs identified by unique IDs that I give them.  However, looking over the ECMA-376, Part 1 (2nd Edition) at the Attributes defined for the Paragraph and Run elements, I notice that the only Attributes defined at the root level for these elements are not guaranteed to be unique.

    For instance, the Attributes "w:rsidR", "w:rsidRPr", "w:rsidRDefault", and "w:rsidP" all have the caveat that -

    "All rsid* attributes throughout this document with the same value, if present, shall
    indicate that those regions were modified during the same editing session (time between
    subsequent save actions)."

    So, my question is - how can I create a template where the Paragraphs and/or Runs have unique IDs so that they can be targeted by code, etc.?

    Thanks.

    Wednesday, April 6, 2011 2:46 AM

Answers

All replies

  • Hello sdfsda,
     
    Thank you for your question.

    I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.
     
    Thank you for your understanding and support. Have a nice day.


    Bessie Zhao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, April 7, 2011 3:50 AM
  • As far as I know there is no attribute of either a paragraph or a run that would make it unique - and certainly none that is available through the UI or the object model. The way to name items in a document is with Bookmarks.
     

    Enjoy,
    Tony
    www.WordArticles.com
    Thursday, April 7, 2011 2:07 PM
  • Hello sdfsda,

    When building a template if you contemplate empty paragraphs use bookmarks, of use content controls, one at the head of each empty paragraph or use a list for existing but miniscle but not empty paragraphs. The best way to see this in a test is to create a Word 2007 or 2010 document with multiple sample paragraphs (push the enter key then start with the command '=rand(6,1)' (without the quotes), press enter.

    For indexing, Select the entire document and make a numbered list.


    For content controls at the beginning of each paragraph insert a RichText Content Control (that is found on the developer tab). In the first Content enter "Section 1, Paragraph 1" (without the quotes). Progress down the document changing the content of each control to show the progressive numbering, so that the next Content Control will contain "Section 1, Paraghraph 2" , etc.

    Save each document in a unique folder. Change its name by renaming it by adding .zip to the end of the name. MyTest.docx will be MyTest.docx.zip.

    Extract the contents and look in the Word folder for the document.xml file.  Open that in an xml editor and see the schema references and the runs. 

    In the ContentControl test you'll see important xml also in the numbering folder.

    In the numbered list example you'll also find significant xml in the Styles.xms file.

    With the same approach you can also see the results of using bookmarks.

     

     


    Chris Jensen
    Senior Technical Support Lead

    Thursday, April 7, 2011 4:17 PM
    Moderator
  • Okay, I understand how to do all this, however when looking at the XML (document.xml, etc.) this seems very clunky.  I have built "templates" before using straight text values as place-holders etc, but I really don't like doing this.  Using the Bookmarks, etc. just adds an additional layer of elements to navigate.

    What I was hoping for was something like Fields, something where I can create my own Text Fields, with the brackets around them like in a Mail Merge template, etc. ([FirstName], etc.).  But it seems unless you are inserting DB fields you are limited to the OOB fields in the the Quick Parts -> Fields dialog box.

    I think the OpenXml specification should cover the ability to make genuine Templates that normal users can make via the standard Ribbon options, kind of like using a database to reference fields, etc. - they should be able to make their own custom, uniquely ID'd, blocks for targeting during a dynamic document creation, etc.  Then, using the unique IDs and a simple x-ref. of what to place in them, all of which can be made by a user, the developer wouldn't even have to look at the XML to find out what to update and what with.  Otherwise, it's left to developers to make a template, examine the XML closely, and then make very unportable, custom classes for each document "template".

    I'm finding as I get more into this that it is a lot more work than I expected to make a genuine template.  It seems the potential is there (again, you can do so with a database, etc.), but not as dynamic as it should be.

    Any other ideas?


    Thursday, April 7, 2011 7:55 PM
  •   Hello sdfsda

    The feature that is added to Word 2007 and Word 2010 is the Content Control.
    The following 3 links to msdn discuss the feature, and two have references to the Open Document XML SDK where you can see programmatic approaches to including Content Controls in your document.

    Please see:
    Using Open Document XML WordprocessingML documents as Data Sources;
    http://msdn.microsoft.com/en-us/library/ff433640(office.14).aspx

    Word Content Controls Resource Center
    http://msdn.microsoft.com/en-us/library/gg278014.aspx

    Building Word 2007 Document Templates Using Content Controls
    http://msdn.microsoft.com/en-us/library/bb264571.aspx


    Chris Jensen
    Senior Technical Support Lead

     

    • Marked as answer by sdfsda Saturday, April 9, 2011 4:24 PM
    Friday, April 8, 2011 3:01 PM
    Moderator
  • Well, it doesn't really work in my case.  I'll just put in my own target text areas, etc.  But I guess this is as good as it gets for now.
    Friday, April 8, 2011 4:32 PM