[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

Selecting ComboBox Item throws odd exception.

ryan baldwin

6/20/2008 5:25:00 PM

I'm creating a sample project to help solve another problem (oh how this
rabbit hole is getting deep!) and I'm having the following problem.

Given the following XmlDataProvider:

<Window.Resources>
<XmlNamespaceMappingCollection x:Key="namespaceMappings">
<XmlNamespaceMapping Uri="http://www.w3.org/2001/XMLSc...
Prefix="xs" />
<XmlNamespaceMapping Uri="http://www.mssample... Prefix="ui" />
</XmlNamespaceMappingCollection>

<XmlDataProvider x:Key="TaxonomyDataProvider" Source="Definitions.xsd"
XmlNamespaceManager="{StaticResource
namespaceMappings}"
XPath="/xs:schema/xs:complexType" />
</Window.Resources>

I'm trying to bind a ComboBox to the above XmlDataProvider with the
following:

<ComboBox Grid.Row="0" x:Name="cboAssetGroups" MinWidth="75"
IsSynchronizedWithCurrentItem="True" SelectedIndex="-1"
ItemsSource="{Binding Source={StaticResource
TaxonomyDataProvider}}"
DisplayMemberPath="@ui:label"
SelectedValuePath="@name">

Everything works fine - I can see the list of combobox items and they
are indeed being mapped to the @name attribute. However, when I select
a value from the combobox, the selected item is blank, and the output
produces the following error:

System.Windows.Data Error: 40 : XML binding failed. Cannot obtain result
node collection because of bad source node or bad Path.;
SourceNode='xs:complexType'; Path='@ui:label'
BindingExpression:Path=/InnerText; DataItem='XmlElement'
(HashCode=64083652); target element is 'ComboBox'
(Name='cboAssetGroups'); target property is 'NoTarget' (type 'Object')
XPathException:'System.Xml.XPath.XPathException: Namespace Manager or
XsltContext needed. This query has a prefix, variable, or user-defined
function.
at MS.Internal.Xml.XPath.CompiledXpathExpr.get_QueryTree()
at System.Xml.XPath.XPathNavigator.Evaluate(XPathExpression expr,
XPathNodeIterator context)
at System.Xml.XPath.XPathNavigator.Evaluate(XPathExpression expr)
at System.Xml.XPath.XPathNavigator.Select(XPathExpression expr)
at System.Xml.XPath.XPathNavigator.Select(String xpath)
at System.Xml.XmlNode.SelectNodes(String xpath)
at MS.Internal.Data.XmlBindingWorker.SelectNodes()'

Why? I already have an XmlNamespaceMapping for the @ui namespace... I
don't understand why I can see the items but selecting them throws an error.

Here is the xml sourcefile in question (it's an xsd):
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Definitions"
targetNamespace="http://tempuri.org/Definitions...
elementFormDefault="qualified"
xmlns="http://tempuri.org/Definitions...
xmlns:mstns="http://tempuri.org/Definitions...
xmlns:xs="http://www.w3.org/2001/XMLSc...
xmlns:ui="http://www.mssample...
>
<xs:complexType name="Cat" ui:label="Cat">
<xs:sequence>
<xs:element maxOccurs="1" minOccurs="0" name="Name"
type="xs:string" ui:label="Name" ui:maxLength="30" />
<xs:element maxOccurs="1" minOccurs="0" name="Colour"
type="xs:string" ui:allowCustom="true" ui:label="Colour"
ui:maxLength="20" ui:option="/choices/attribute[@key='Colour']/option" />
<xs:element maxOccurs="1" minOccurs="0" name="Length"
ui:label="Length">
<xs:complexType>
<xs:attribute name="value" type="xs:decimal" use="required" />
<xs:attribute name="unit" type="xs:string"
ui:allowCustom="true"
ui:options="/choices/attribute[@key='Length']/option" />
</xs:complexType>
</xs:element>
<xs:element maxOccurs="1" minOccurs="0" name="Weight"
ui:label="Weight">
<xs:complexType>
<xs:attribute name="value" type="xs:decimal" use="required" />
<xs:attribute name="unit" type="xs:string"
ui:allowCustom="true"
ui:options="/choices/attribute[@key='Length']/option" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Dog" ui:label="Cat">
<xs:sequence>
<xs:element maxOccurs="1" minOccurs="0" name="Name"
type="xs:string" ui:label="Name" ui:maxLength="30" />
<xs:element maxOccurs="1" minOccurs="0" name="Colour"
type="xs:string" ui:allowCustom="true" ui:label="Colour"
ui:maxLength="20" ui:option="/choices/attribute[@key='Colour']/option" />
<xs:element maxOccurs="1" minOccurs="0" name="Length"
ui:label="Length">
<xs:complexType>
<xs:attribute name="value" type="xs:decimal" use="required" />
<xs:attribute name="unit" type="xs:string"
ui:allowCustom="true"
ui:options="/choices/attribute[@key='Length']/option" />
</xs:complexType>
</xs:element>
<xs:element maxOccurs="1" minOccurs="0" name="Weight"
ui:label="Weight">
<xs:complexType>
<xs:attribute name="value" type="xs:decimal" use="required" />
<xs:attribute name="unit" type="xs:string"
ui:allowCustom="true"
ui:options="/choices/attribute[@key='Weight']/option" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Programmer" ui:label="Programmer">
<xs:sequence>
<xs:element maxOccurs="1" minOccurs="0" name="Name"
type="xs:string" ui:label="Name" ui:maxLength="30" />
<xs:element maxOccurs="1" minOccurs="0" name="Height"
ui:label="Height">
<xs:complexType>
<xs:attribute name="value" type="xs:decimal" use="required" />
<xs:attribute name="unit" type="xs:string"
ui:allowCustom="true"
ui:options="/choices/attribute[@key='Height']/option" />
</xs:complexType>
</xs:element>
<xs:element maxOccurs="1" minOccurs="0" name="Weight"
ui:label="Weight">
<xs:complexType>
<xs:attribute name="value" type="xs:decimal" use="required" />
<xs:attribute name="unit" type="xs:string"
ui:allowCustom="true"
ui:options="/choices/attribute[@key='Weight']/option" />
</xs:complexType>
</xs:element>
<xs:element maxOccurs="1" minOccurs="0" name="IsBald"
ui:label="Is Bald" type="xs:boolean" />
</xs:sequence>
</xs:complexType>
</xs:schema>
1 Answer

ryan baldwin

6/20/2008 5:28:00 PM

0

Apologies - I should have posted this in the DataBinding forum.

ryan baldwin wrote:
> I'm creating a sample project to help solve another problem (oh how this
> rabbit hole is getting deep!) and I'm having the following problem.
>
> Given the following XmlDataProvider:
>
> <Window.Resources>
> <XmlNamespaceMappingCollection x:Key="namespaceMappings">
> <XmlNamespaceMapping Uri="http://www.w3.org/2001/XMLSc...
> Prefix="xs" />
> <XmlNamespaceMapping Uri="http://www.mssample... Prefix="ui" />
> </XmlNamespaceMappingCollection>
>
> <XmlDataProvider x:Key="TaxonomyDataProvider" Source="Definitions.xsd"
> XmlNamespaceManager="{StaticResource
> namespaceMappings}"
> XPath="/xs:schema/xs:complexType" />
> </Window.Resources>
>
> I'm trying to bind a ComboBox to the above XmlDataProvider with the
> following:
>
> <ComboBox Grid.Row="0" x:Name="cboAssetGroups" MinWidth="75"
> IsSynchronizedWithCurrentItem="True" SelectedIndex="-1"
> ItemsSource="{Binding Source={StaticResource
> TaxonomyDataProvider}}"
> DisplayMemberPath="@ui:label"
> SelectedValuePath="@name">
>
> Everything works fine - I can see the list of combobox items and they
> are indeed being mapped to the @name attribute. However, when I select
> a value from the combobox, the selected item is blank, and the output
> produces the following error:
>
> System.Windows.Data Error: 40 : XML binding failed. Cannot obtain result
> node collection because of bad source node or bad Path.;
> SourceNode='xs:complexType'; Path='@ui:label'
> BindingExpression:Path=/InnerText; DataItem='XmlElement'
> (HashCode=64083652); target element is 'ComboBox'
> (Name='cboAssetGroups'); target property is 'NoTarget' (type 'Object')
> XPathException:'System.Xml.XPath.XPathException: Namespace Manager or
> XsltContext needed. This query has a prefix, variable, or user-defined
> function.
> at MS.Internal.Xml.XPath.CompiledXpathExpr.get_QueryTree()
> at System.Xml.XPath.XPathNavigator.Evaluate(XPathExpression expr,
> XPathNodeIterator context)
> at System.Xml.XPath.XPathNavigator.Evaluate(XPathExpression expr)
> at System.Xml.XPath.XPathNavigator.Select(XPathExpression expr)
> at System.Xml.XPath.XPathNavigator.Select(String xpath)
> at System.Xml.XmlNode.SelectNodes(String xpath)
> at MS.Internal.Data.XmlBindingWorker.SelectNodes()'
>
> Why? I already have an XmlNamespaceMapping for the @ui namespace... I
> don't understand why I can see the items but selecting them throws an
> error.
>
> Here is the xml sourcefile in question (it's an xsd):
> <?xml version="1.0" encoding="utf-8"?>
> <xs:schema id="Definitions"
> targetNamespace="http://tempuri.org/Definitions...
> elementFormDefault="qualified"
> xmlns="http://tempuri.org/Definitions...
> xmlns:mstns="http://tempuri.org/Definitions...
> xmlns:xs="http://www.w3.org/2001/XMLSc...
> xmlns:ui="http://www.mssample...
> >
> <xs:complexType name="Cat" ui:label="Cat">
> <xs:sequence>
> <xs:element maxOccurs="1" minOccurs="0" name="Name"
> type="xs:string" ui:label="Name" ui:maxLength="30" />
> <xs:element maxOccurs="1" minOccurs="0" name="Colour"
> type="xs:string" ui:allowCustom="true" ui:label="Colour"
> ui:maxLength="20" ui:option="/choices/attribute[@key='Colour']/option" />
> <xs:element maxOccurs="1" minOccurs="0" name="Length"
> ui:label="Length">
> <xs:complexType>
> <xs:attribute name="value" type="xs:decimal" use="required" />
> <xs:attribute name="unit" type="xs:string"
> ui:allowCustom="true"
> ui:options="/choices/attribute[@key='Length']/option" />
> </xs:complexType>
> </xs:element>
> <xs:element maxOccurs="1" minOccurs="0" name="Weight"
> ui:label="Weight">
> <xs:complexType>
> <xs:attribute name="value" type="xs:decimal" use="required" />
> <xs:attribute name="unit" type="xs:string"
> ui:allowCustom="true"
> ui:options="/choices/attribute[@key='Length']/option" />
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> <xs:complexType name="Dog" ui:label="Cat">
> <xs:sequence>
> <xs:element maxOccurs="1" minOccurs="0" name="Name"
> type="xs:string" ui:label="Name" ui:maxLength="30" />
> <xs:element maxOccurs="1" minOccurs="0" name="Colour"
> type="xs:string" ui:allowCustom="true" ui:label="Colour"
> ui:maxLength="20" ui:option="/choices/attribute[@key='Colour']/option" />
> <xs:element maxOccurs="1" minOccurs="0" name="Length"
> ui:label="Length">
> <xs:complexType>
> <xs:attribute name="value" type="xs:decimal" use="required" />
> <xs:attribute name="unit" type="xs:string"
> ui:allowCustom="true"
> ui:options="/choices/attribute[@key='Length']/option" />
> </xs:complexType>
> </xs:element>
> <xs:element maxOccurs="1" minOccurs="0" name="Weight"
> ui:label="Weight">
> <xs:complexType>
> <xs:attribute name="value" type="xs:decimal" use="required" />
> <xs:attribute name="unit" type="xs:string"
> ui:allowCustom="true"
> ui:options="/choices/attribute[@key='Weight']/option" />
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> <xs:complexType name="Programmer" ui:label="Programmer">
> <xs:sequence>
> <xs:element maxOccurs="1" minOccurs="0" name="Name"
> type="xs:string" ui:label="Name" ui:maxLength="30" />
> <xs:element maxOccurs="1" minOccurs="0" name="Height"
> ui:label="Height">
> <xs:complexType>
> <xs:attribute name="value" type="xs:decimal" use="required" />
> <xs:attribute name="unit" type="xs:string"
> ui:allowCustom="true"
> ui:options="/choices/attribute[@key='Height']/option" />
> </xs:complexType>
> </xs:element>
> <xs:element maxOccurs="1" minOccurs="0" name="Weight"
> ui:label="Weight">
> <xs:complexType>
> <xs:attribute name="value" type="xs:decimal" use="required" />
> <xs:attribute name="unit" type="xs:string"
> ui:allowCustom="true"
> ui:options="/choices/attribute[@key='Weight']/option" />
> </xs:complexType>
> </xs:element>
> <xs:element maxOccurs="1" minOccurs="0" name="IsBald" ui:label="Is
> Bald" type="xs:boolean" />
> </xs:sequence>
> </xs:complexType>
> </xs:schema>