R
ryan baldwin
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/XMLSchema"
Prefix="xs" />
<XmlNamespaceMapping Uri="http://www.mssample.com" 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'
BindingExpressionath=/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.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/Definitions.xsd"
xmlns:mstns="http://tempuri.org/Definitions.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ui="http://www.mssample.com"<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" uiption="/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"
uiptions="/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"
uiptions="/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" uiption="/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"
uiptions="/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"
uiptions="/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"
uiptions="/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"
uiptions="/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>
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/XMLSchema"
Prefix="xs" />
<XmlNamespaceMapping Uri="http://www.mssample.com" 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'
BindingExpressionath=/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.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/Definitions.xsd"
xmlns:mstns="http://tempuri.org/Definitions.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ui="http://www.mssample.com"<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" uiption="/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"
uiptions="/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"
uiptions="/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" uiption="/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"
uiptions="/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"
uiptions="/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"
uiptions="/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"
uiptions="/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>