Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > .NET Framework

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-20-2008, 06:25 PM
ryan baldwin
 
Posts: n/a
Selecting ComboBox Item throws odd exception.

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'
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_QueryT ree()
at System.Xml.XPath.XPathNavigator.Evaluate(XPathExpr ession expr,
XPathNodeIterator context)
at System.Xml.XPath.XPathNavigator.Evaluate(XPathExpr ession expr)
at System.Xml.XPath.XPathNavigator.Select(XPathExpres sion 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" 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>
Reply With Quote
  #2 (permalink)  
Old 06-20-2008, 06:27 PM
ryan baldwin
 
Posts: n/a
Re: Selecting ComboBox Item throws odd exception.

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/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'
> 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_QueryT ree()
> at System.Xml.XPath.XPathNavigator.Evaluate(XPathExpr ession expr,
> XPathNodeIterator context)
> at System.Xml.XPath.XPathNavigator.Evaluate(XPathExpr ession expr)
> at System.Xml.XPath.XPathNavigator.Select(XPathExpres sion 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" 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>

Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > .NET Framework


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:42 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Buy Anything On eBay | Dominios | Credit Card Consolidation | Refinance | Online Advertising



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114