Visual Studio Developer Center > Visual Studio Forums > Visual Studio Tools for Office > Word 2007 Binding content control to an XML list
Ask a questionAsk a question
 

AnswerWord 2007 Binding content control to an XML list

  • Monday, October 26, 2009 10:29 PMmark010101 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hi,
    i have an xml that contains elements that looks like this:
    <Authors>
         <Author>
                <Id>1
                <Name>Joe Smith</Name>
          </Author>
         <Author>
                <Id>2
                <Name>Tom Smith</Name>
          </Author>
         <Author>
                <Id>3
                <Name>Mark Smith</Name>
          </Author>
    </Author>
    I would like to bind this to two controls that display Id and Name.  The problem is, how do i handle XML nodes that may contain 1 to N amount of elements?  In .NET we could use something like a Repeater control.  Is it possible to do something similar in word where it would display all child Author nodes?

    thanks

Answers

  • Tuesday, October 27, 2009 1:38 PMCindy MeisterMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Mark

    First, I hope you aren't trying to use exactly the XML you show, as it's not valid. You have no end element for the Id: </Id>

    But in answer to your question, no, Word has no real support for 1:n relationships. It's lacking in mail merge, it's lacking in data-binding and in XML and content controls. Anything you want along these lines has to be created in your code.

    So you would have to create a content control for each Id and Name element. (I'm not sure how much sense it would make to also generate "parent" content controls at the Author level, as you won't be able to link that to anything.)
    Cindy Meister, VSTO/Word MVP

All Replies

  • Tuesday, October 27, 2009 1:38 PMCindy MeisterMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Mark

    First, I hope you aren't trying to use exactly the XML you show, as it's not valid. You have no end element for the Id: </Id>

    But in answer to your question, no, Word has no real support for 1:n relationships. It's lacking in mail merge, it's lacking in data-binding and in XML and content controls. Anything you want along these lines has to be created in your code.

    So you would have to create a content control for each Id and Name element. (I'm not sure how much sense it would make to also generate "parent" content controls at the Author level, as you won't be able to link that to anything.)
    Cindy Meister, VSTO/Word MVP
  • Friday, November 06, 2009 5:39 PMmark010101 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks much.