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:
<xhtml:p>This text is
<xhtml:b>bold</xhtml:b> and this text is
<xhtml:u>underlined</xhtml:u>!
</xhtml:p>
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:
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="MixedContent">
<xsd:complexType mixed="true">
<xsd:sequence>
<xsd:element name="Element1" type="xsd:string" />
<xsd:element name="Element2" type="xsd:string" />
<xsd:element name="Element3" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Create an InfoPath form that uses the schema for a data source
- Start InfoPath. On the File menu, click
Design a Form.
- In the Design a Form task pane, click New From Data
Source.
The Data Source Setup Wizard appears. - Click Next to use XML Schema or
XML data file for the data source type.
- Click Browse. In the Open
dialog box, select MixedContent.xsd, and then click
Open. Click Finish to complete the
wizard.
- In the Data Source task pane, move the
MixedContent group to your form. Select Section with
Controls.
- Save your form as
MixedContent.xsn.
Test the form
- On the File menu, click Fill Out a
Form. In the Fill Out a Form task pane, click
MixedContent.
- Type AAA in the Element1 text field,
type BBB in the Element2 text field, and then type
CCC in the Element3 text field.
- Save the form data as Form1.xml, and
then close the form.
- Open Form1.xml in an XML editor or in a text editor. The
contents are similar to the following code sample:
<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.1"
productVersion="11.0.5531" PIVersion="1.0.0.0" href="file:///C:\mixedcontent.xsn"
language="de" ?><?mso-application progid="InfoPath.Document"?><MixedContent>
<Element1>AAA</Element1>
<Element2>BBB</Element2>
<Element3>CCC</Element3>
</MixedContent>
- Add mixed text to Form1.xml as described in the following
code sample, and then save your changes:
<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.1"
productVersion="11.0.5531" PIVersion="1.0.0.0" href="file:///C:\mixedcontent.xsn"
language="de" ?><?mso-application progid="InfoPath.Document"?><MixedContent>
One<Element1>AAA</Element1>
<Element2>BBB</Element2>Two
Three<Element3>CCC</Element3>Four
</MixedContent>
- 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. - 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.
- 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="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.1"
productVersion="11.0.5531" PIVersion="1.0.0.0" href="file:///C:\mixedcontent.xsn"
language="de" ?><?mso-application progid="InfoPath.Document"?><MixedContent>
One<Element1>111</Element1>
<Element2>222</Element2>Two
Three <Element3>333</Element3>Four
</MixedContent>