Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

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:
<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

  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.
  3. Click Next to use XML Schema or XML data file for the data source type.
  4. Click Browse. In the Open dialog box, select MixedContent.xsd, and then click Open. Click Finish to complete the wizard.
  5. In the Data Source task pane, move the MixedContent group to your form. Select Section with Controls.
  6. Save your form as MixedContent.xsn.

Test the form

  1. On the File menu, click Fill Out a Form. In the Fill Out a Form task pane, click MixedContent.
  2. Type AAA in the Element1 text field, type BBB in the Element2 text field, and then type CCC in the Element3 text field.
  3. Save the form data as Form1.xml, and then close the form.
  4. 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>
  5. 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>
  6. 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.
  7. 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.
  8. 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>

↑ Back to the top


Keywords: KB826999, kbxml, kbhowto

↑ Back to the top

Article Info
Article ID : 826999
Revision : 4
Created on : 11/9/2006
Published on : 11/9/2006
Exists online : False
Views : 325