none
How to put XML-Code into Rich Text Content Control via Custom XML Part RRS feed

  • Frage

  • According to https://msdn.microsoft.com/en-us/library/office/jj889465.aspx it should be possible to bound custom xml data to a rich text control (Word 2013 or higher): "... Within the custom XML part, the custom XML is stored as flat Open XML markup converted into a string (by using standard XML encoding), so that it can be stored as a text node in the custom XML part..."

    But can anyone please give me a working example.
    I tried the following string as content of a bounded XML element:

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
      <w:wordDocument xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
        <w:body>
          <w:p>
            <w:r>
              <w:t>More testing</w:t>
            </w:r>
            <w:r>
              <w:rPr><w:i/></w:rPr>
              <w:t>with</w:t>
            </w:r>
            <w:r>
              <w:rPr><w:b/></w:rPr>
              <w:t>Bold text</w:t>
            </w:r>
            <w:r>
              <w:t>in Content Control</w:t>
            </w:r>
          </w:p>
        </w:body>
      </w:wordDocument>

    Of course, I encoded the < and > characters as "&lt;" and "&gt;", respectively. But when I open the word document with this custom xml part, Word application crashes. The reason for this seems to be the xlmns attribute. Regardless of what I specify for this attribute, Word crashes. If I omit the xlmns attribute, the string is not interpreted as OpenXML Markup, but is displayed as it is. I tried other strings with pkg:package elements, but they also lead to crashing Word.

    All I need is a working example for displaying formatted text within a rich text content control bound to XML data.


    • Bearbeitet ghuebner Freitag, 16. September 2016 08:30
    Freitag, 16. September 2016 08:22

Antworten

  • In the meantime, I found a working example, here

    https://dev.office.com/docs/add-ins/word/create-better-add-ins-for-word-with-office-open-xml

    <pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage">
      <pkg:part pkg:name="/_rels/.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml" pkg:padding="512">
        <pkg:xmlData>
          <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
            <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
          </Relationships>
        </pkg:xmlData>
      </pkg:part>
      <pkg:part pkg:name="/word/document.xml" pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml">
        <pkg:xmlData>
          <w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" >
            <w:body>
              <w:p>
                <w:r>
                  <w:t>More testing</w:t>
                </w:r>
                <w:r>
                  <w:rPr><w:i/></w:rPr>
                  <w:t>with</w:t>
                </w:r>
                <w:r>
                  <w:rPr><w:b/></w:rPr>
                  <w:t>Bold text</w:t>
                </w:r>
                <w:r>
                  <w:t>in Content Control</w:t>
                </w:r>
              </w:p>
            </w:body>
          </w:document>
        </pkg:xmlData>
      </pkg:part>
    </pkg:package>

    This seems to be the minimal string possible. If document styles are used, further package parts may have to be included.

    The output is, as expected, formatted text within an xml bounded rich text content control:
    Formatted Text in a bounded Rich Text Content Control


    Visit my blog at https://massivedynamicsblog.wordpress.com/





    • Als Antwort markiert ghuebner Freitag, 16. September 2016 09:56
    • Bearbeitet ghuebner Freitag, 16. September 2016 10:05
    Freitag, 16. September 2016 09:49