To all the XML Gurus...
I need a Cascading dropdown list solution for a form that will work both in ip 2007 services and off-line.
For simplicity/testing I use field2 = /my:myFields/my:field1 and field2 = /my:myFields/my:field
I populate both lists from the respective service (this works fine) Then on field1_Changed try to rebuild the field2 list as below:
public void field1_Changed(object sender, XmlEventArgs e)
{
XPathNavigator parent = e.Site.SelectSingleNode("..");
// Remove existing values first
List<XPathNavigator> nodesToDelete = new List<XPathNavigator>();
foreach (XPathNavigator field2SourceNode in parent.Select("my:field2", NamespaceManager))
{
// Cannot just call DeleteSelf on the navigator because it alters the iteration state.
// Instead, collect the navigators for future deletion.
nodesToDelete.Add(field2SourceNode.Clone());
}
// Now remove all the nodes.
foreach (XPathNavigator field2SourceNode in nodesToDelete)
{
field2SourceNode.DeleteSelf();
}
//
// The data is in the datasource
XPathNavigator entryNavigator = this.DataSources["GetUnitList"].CreateNavigator();
// Add the namespaces so we can query the datasource
XmlNamespaceManager umanager = new XmlNamespaceManager(entryNavigator.NameTable);
umanager.AddNamespace("dfs", "http://schemas.microsoft.com/office/infopath/2003/dataFormSolution");
umanager.AddNamespace("tns", "http://tempuri.org/");
umanager.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-01-02T10:15:45");
umanager.AddNamespace("xd", "http://schemas.microsoft.com/office/infopath/2003");
string matchingfield2XPath = String.Format("/dfs:myFields/dfs:dataFields/tns:GetUnitListResponse/tns:GetUnitListResult/Unit/Table/[@UnitType = '{0}']", e.Site.Value);
//// For each matching node, add it to the collection
foreach (XPathNavigator field2Navigator in this.DataSources["GetUnitList"].CreateNavigator().Select(matchingfield2XPath, umanager))
{
using (XmlWriter writer = parent.AppendChild())
{
writer.WriteElementString("field2Source", NamespaceManager.LookupNamespace("my"), field2Navigator.Value);
}
}
}
The value of field1 should filter the entries in field2... I believe the value for matchingfield2XPath is the problem??
matchingfield2XPath = /dfs:myFields/dfs:dataFields/tns:GetUnitListResponse/tns:GetUnitListResult/Unit/Table/[@UnitType = 'a577a221-598e-449c-8f93-cd68ad70a97c']
/////////// RESULTS FROM GetUnitList WEBSERVICE
<?xml version="1.0" encoding="utf-8" ?>
- <DataSet xmlns="http://tempuri.org/">
- <xs:schema id="Unit" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
- <xs:element name="Unit" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
- <xs:complexType>
- <xs:choice minOccurs="0" maxOccurs="unbounded">
- <xs:element name="Table">
- <xs:complexType>
- <xs:sequence>
<xs:element name="RecordID" msdata:DataType="System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" type="xs:string" minOccurs="0" />
<xs:element name="UnitType" msdata:DataType="System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" type="xs:string" minOccurs="0" />
<xs:element name="UnitTypeName" type="xs:string" minOccurs="0" />
<xs:element name="UnitName" type="xs:string" minOccurs="0" />
<xs:element name="Active" type="xs:boolean" minOccurs="0" />
<xs:element name="ISIC" msdata:DataType="System.Guid, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" type="xs:string" minOccurs="0" />
<xs:element name="ISICName" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
- <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
- <Unit xmlns="">
- <Table diffgr:id="Table1" msdata:rowOrder="0">
<RecordID>5d8c579a-0a64-42bc-b7bb-99482ff5fe8f</RecordID>
<UnitType>a577a221-598e-449c-8f93-cd68ad70a97c</UnitType>
<UnitTypeName>USS</UnitTypeName>
<UnitName>ZEPHYR</UnitName>
<Active>true</Active>
<ISIC>2577f9cd-c0d3-4718-9dfd-8d47501225dd</ISIC>
<ISICName>ISIC Test Entry</ISICName>
</Table>
- <Table diffgr:id="Table2" msdata:rowOrder="1">
<RecordID>4e19f8d0-6124-4c33-b089-f0014fbb4a3d</RecordID>
<UnitType>15017374-c205-4d9d-82f8-a8d3727b6185</UnitType>
<UnitTypeName>USNS</UnitTypeName>
<UnitName>1ST LT HARRY L. MARTIN</UnitName>
<Active>true</Active>
</Table>
- <Table diffgr:id="Table3" msdata:rowOrder="2">
<RecordID>39622e87-6086-4d6a-98a6-aae4777d49f9</RecordID>
<UnitType>15017374-c205-4d9d-82f8-a8d3727b6185</UnitType>
<UnitTypeName>USNS</UnitTypeName>
<UnitName>ABLE</UnitName>
<Active>true</Active>
</Table>
...
- <Table diffgr:id="Table816" msdata:rowOrder="815">
<RecordID>42a63396-3eb8-45cb-aa96-a5cf0de812c1</RecordID>
<UnitType>15017374-c205-4d9d-82f8-a8d3727b6185</UnitType>
<UnitTypeName>USNS</UnitTypeName>
<UnitName>YUKON</UnitName>
<Active>true</Active>
</Table>
- <Table diffgr:id="Table818" msdata:rowOrder="817">
<RecordID>40684e1c-b36e-4151-ad9f-d452e44ead51</RecordID>
<UnitType>15017374-c205-4d9d-82f8-a8d3727b6185</UnitType>
<UnitTypeName>USNS</UnitTypeName>
<UnitName>ZEUS</UnitName>
<Active>true</Active>
</Table>
</Unit>
</diffgr:diffgram>
</DataSet>