Microsoft KB Archive/826999

= How to handle mixed content elements in XML documents in InfoPath 2007 and in InfoPath 2003 =

Article ID: 826999

Article Last Modified on 11/9/2006

-

APPLIES TO


 * Microsoft Office InfoPath 2007
 * Microsoft Office InfoPath 2003, Service Pack 1 (SP1)
 * Microsoft Office InfoPath 2003

-





SUMMARY
Mixed content is an option in an XSD schema that indicates that the COMPLEXTYPE element can contain text nodes that are mixed in with other elements. A typical example of mixed content is XHTML XML: This text is  bold and this text is   underlined!  Microsoft Office InfoPath 2007 and Microsoft Office InfoPath 2003 load a schema with mixed content without error, but InfoPath does not support binding to mixed content elements. If you use a schema that contains mixed content elements for the data source of your form, InfoPath does not bind to the text nodes in your mixed content element. However, InfoPath honors, validates, and accepts mixed XML, and then preserves the text nodes in the containing element.

This article describes how InfoPath handles a schema with mixed content for a form data source.

Create a schema for mixed content
Use an XML editor or a text editor such as Notepad to create a schema that is named MixedContent.xsd with the following elements:         </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>

Create an InfoPath form that uses the schema for a data source

 * 1) Start InfoPath. On the File menu, click Design a Form.
 * 2) In the Design a Form task pane, click New From Data Source.

The Data Source Setup Wizard appears.
 * 1) Click Next to use XML Schema or XML data file for the data source type.
 * 2) Click Browse. In the Open dialog box, select MixedContent.xsd, and then click Open. Click Finish to complete the wizard.
 * 3) In the Data Source task pane, move the MixedContent group to your form. Select Section with Controls.
 * 4) Save your form as MixedContent.xsn.

Test the form
<ol> <li>On the File menu, click Fill Out a Form. In the Fill Out a Form task pane, click MixedContent.</li> <li>Type AAA in the Element1 text field, type BBB in the Element2 text field, and then type CCC in the Element3 text field.</li> <li>Save the form data as Form1.xml, and then close the form.</li> <li> Open Form1.xml in an XML editor or in a text editor. The contents are similar to the following code sample: <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?><?mso-infoPathSolution solutionVersion=&quot;1.0.0.1&quot; productVersion=&quot;11.0.5531&quot; PIVersion=&quot;1.0.0.0&quot; href=&quot;file:///C:\mixedcontent.xsn&quot; language=&quot;de&quot; ?><?mso-application progid=&quot;InfoPath.Document&quot;?><MixedContent> <Element1>AAA</Element1> <Element2>BBB</Element2> <Element3>CCC</Element3> </MixedContent> </li> <li> Add mixed text to Form1.xml as described in the following code sample, and then save your changes: <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?><?mso-infoPathSolution solutionVersion=&quot;1.0.0.1&quot; productVersion=&quot;11.0.5531&quot; PIVersion=&quot;1.0.0.0&quot; href=&quot;file:///C:\mixedcontent.xsn&quot; language=&quot;de&quot; ?><?mso-application progid=&quot;InfoPath.Document&quot;?><MixedContent> One<Element1>AAA</Element1> <Element2>BBB</Element2>Two Three<Element3>CCC</Element3>Four </MixedContent> </li> <li>In the Fill Out a Form task pane, click Open a Form On My Computer, select Form1.xml, and then click Open.

Notice that the mixed text (such as One and Two) does not appear on the form.</li> <li>Replace the string AAA, the string BBB , and the string CCC with 111 , with 222 , and with 333 respectively in the text fields, and then save your changes to Form1.xml.</li> <li> Open Form1.xml in an XML editor or in a text editor.

Notice in the following code sample that the fields that you last entered have changed while the text nodes have been preserved even though the text nodes did not appear in the form: <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?><?mso-infoPathSolution solutionVersion=&quot;1.0.0.1&quot; productVersion=&quot;11.0.5531&quot; PIVersion=&quot;1.0.0.0&quot; href=&quot;file:///C:\mixedcontent.xsn&quot; language=&quot;de&quot; ?><?mso-application progid=&quot;InfoPath.Document&quot;?><MixedContent> One<Element1>111</Element1> <Element2>222</Element2>Two Three  <Element3>333</Element3>Four </MixedContent> </li></ol>

Additional query words: IP2007

Keywords: kbhowto kbxml KB826999

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.