Form designer: How to bind XML data to the drop-down list tool

To use the XmlDataSource data binding feature in the drop-down list tool, you have to define the public URI path of the XML file in the URL field, and ensure that the XML is structured so that the properties of each element are expressed as attributes.

Here’s an example of XML file content compatible with the drop-down list databind:

http://localhost/wfgen/samples/xmldatasource.xml

<?xml version="1.0" encoding="utf-8" ?>
<NewDataSet>
    <Table1 name="John Doe"/>
    <Table1 name="Bill Smith"/>
    <Table1 name="Jane Brown"/>
</NewDataSet>

In many cases, XML files that you work with are structured differently. For example, values are often created as elements with inner text.

http://localhost/wfgen/samples/users.xml

<?xml version="1.0" encoding="utf-8" ?>
<NewDataSet>
    <Table1>
        <name>John Doe</name>
    </Table1>
    <Table1>
        <name>Bill Smith</name>
    </Table1>
    <Table1>
        <name>Jane Doe</name>
    </Table1>
</NewDataSet>

In this case you can provide an XSLT transformation file that can dynamically reformat the XML file so that it is compatible with the XmlDataSource format.

First, create an XSLT file named users.xsl and host it on the same URI as the XML file (for example, http://localhost/wfgen/samples/users.xsl):

<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <xsl:for-each select="NewDataSet">
            <xsl:element name="NewDataSet">
                <xsl:for-each select="Table1">
                    <xsl:element name="Table1">
                        <xsl:attribute name="name">
                            <xsl:value-of select="name"/>
                        </xsl:attribute>
                    </xsl:element>
                </xsl:for-each>
            </xsl:element>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

Then, set its public URI path in the XSL transform file field in your drop-down list’s databind settings.

Download the sample pack

For more information, see http://msdn.microsoft.com/en-us/library/13ftcwy9(v=VS.80).aspx.