none
Binding content control to elements with mixed content RRS feed

  • Question

  • Hello all,

    Is is possible to map plain text content controls to text nodes inside elements in the Custom XML part?

    Example:

    <paragraph>This is text node 1 <bold>some text</bold>and this is text node 2</paragraph><br/>
    

    I tried to give an XPath like:  'paragraph/text()[1]'  and 'paragraph/text()[2]', to map content controls to the text nodes, but it does not work. I don't get any error message, the binding is just not done. I tried the content control toolkit, but it shows only elements and no text nodes within it.

    Thanks for any information,

    Greets,

    Tuesday, August 30, 2011 7:08 AM

Answers

  • Hi Sam

    Thanks for spelling it out :-) I'm afraid my head is a bit "crammed" this morning... <sigh>

    I've never seen it spelled out explicitly in the documentation, but given other restrictions of CustomXMLParts (no binding to rich text, no support of optional parameters in a schema) I'm more than 99% certain that binding to mixed elements isn't supported.

    I think you'd have to break this down to multiple paragraph elements that can contain "text run" elements such as bold, italic, etc.

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <document>
    <paragraph>The quick brown fox </paragraph>
     <bold>jumped</bold>
    <paragraph>over the fence</paragraph>
    </document>

    So the mapping would be more like document/paragraph[1], document/paragraph[1]/bold, document/paragraph[2]


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by samwillie Tuesday, August 30, 2011 9:02 AM
    Tuesday, August 30, 2011 8:53 AM
    Moderator

All replies

  • Hi Sam

    I'm not certain I'm understanding completely what you have in mind, but if I do, then the answer is no.

    As far as I know, an element can't have more than one text node?


    Cindy Meister, VSTO/Word MVP
    Tuesday, August 30, 2011 7:43 AM
    Moderator
  • Hi Cindy,

    Thanks for your time. Probably, it will be easier for you to provide an answer if I explain the context. I am trying to bind elements with mixed content like in the example below.

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <document>
    <paragraph>The quick brown fox <bold>jumped</bold>over the fence</paragraph>
    </document>
    
    

    I have the following content controls for the above xml in the document (they are created programmatically upon import of this XML file into the document):

    1. Rich text CC for <document>
    2. Rich text CC for <paragraph>
    3. Plaintext CC for text node 1 'The quick brown fox'
    4. Plaintext CC for <bold>
    5. Plaintext CC for text node 2 'over the fence'.

    The CC bindings are as follows:

    3. Plaintext CC for text node 1 'The quick brown fox' -> document/paragraph/text()[1] -> This does not bind! no errors, just don't see the result.

    4. Plaintext CC Binding for <bold> -> document/paragraph/bold -> This binds properly! can see the result - 'jumped'.

    5 Plaintext CC Binding for text node 2 'over the fence' -> document/paragraph/text()[2] -> This does not bind! no errors, just don't see the result.

    Is there another way to bind these kind of <paragraph> elements with mixed content - both text and elements in order?

    Thanks in advance,

    Greets

    Tuesday, August 30, 2011 8:17 AM
  • Hi Sam

    Thanks for spelling it out :-) I'm afraid my head is a bit "crammed" this morning... <sigh>

    I've never seen it spelled out explicitly in the documentation, but given other restrictions of CustomXMLParts (no binding to rich text, no support of optional parameters in a schema) I'm more than 99% certain that binding to mixed elements isn't supported.

    I think you'd have to break this down to multiple paragraph elements that can contain "text run" elements such as bold, italic, etc.

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <document>
    <paragraph>The quick brown fox </paragraph>
     <bold>jumped</bold>
    <paragraph>over the fence</paragraph>
    </document>

    So the mapping would be more like document/paragraph[1], document/paragraph[1]/bold, document/paragraph[2]


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by samwillie Tuesday, August 30, 2011 9:02 AM
    Tuesday, August 30, 2011 8:53 AM
    Moderator
  • Hi Cindy,

    Thank you so much!

    Greets,

    Tuesday, August 30, 2011 9:03 AM