WPF xml

I'm using WPF with net 3.5 to load the ItemsSource of a combo box from an 
xml file.

The xml is setup like this:

<profiles>
    <profile>
        <profilename>First profile</profilename>
        ...
    </profile>
    ... other profile nodes
</profiles>

In the Windows.Resources node of the xaml I have:

    <XmlDataProvider x:Key="xmldata" Source="c:/temp/xmlData.xml" 
XPath="profiles/profile" />

and in the combobox I have:

    <ComboBox Margin="5" Name="cbProfiles" Width="240" IsEditable="True"
                  ToolTip="Select database profile" 
VerticalContentAlignment="Center"
                      ItemsSource="{Binding Source={StaticResource xmldata}, 
XPath=profilename }" SelectedIndex="0" />

But this only retreives the first profile-profilename for the combobox list. 
If I change the XPath of the combobox to //profilename, then I get them all.

What am I not understanding about how this works since I think the XPath of 
the XmlDataProvider should be providing a list of <profiles/profile> nodes 
and then the XPath of the combobox should give me all the <profilename> 
nodes.

Regards,

Rick 

0
Rick2256 (24)
10/9/2008 11:39:09 AM
dotnet.xml 7266 articles. 0 followers. Follow

1 Replies
1098 Views

Similar Articles

[PageSpeed] 54

Rick wrote:
> I'm using WPF with net 3.5 to load the ItemsSource of a combo box from 
> an xml file.
> 
> The xml is setup like this:
> 
> <profiles>
>    <profile>
>        <profilename>First profile</profilename>
>        ...
>    </profile>
>    ... other profile nodes
> </profiles>
> 
> In the Windows.Resources node of the xaml I have:
> 
>    <XmlDataProvider x:Key="xmldata" Source="c:/temp/xmlData.xml" 
> XPath="profiles/profile" />
> 
> and in the combobox I have:
> 
>    <ComboBox Margin="5" Name="cbProfiles" Width="240" IsEditable="True"
>                  ToolTip="Select database profile" 
> VerticalContentAlignment="Center"
>                      ItemsSource="{Binding Source={StaticResource 
> xmldata}, XPath=profilename }" SelectedIndex="0" />
> 
> But this only retreives the first profile-profilename for the combobox 
> list. If I change the XPath of the combobox to //profilename, then I get 
> them all.
> 
> What am I not understanding about how this works since I think the XPath 
> of the XmlDataProvider should be providing a list of <profiles/profile> 
> nodes and then the XPath of the combobox should give me all the 
> <profilename> nodes.

I think you want

   <XmlDataProvider x:Key="xmldata" Source="c:/temp/xmlData.xml" 
XPath="profiles" />

and

<ComboBox Margin="5" Name="cbProfiles" Width="240" IsEditable="True"
                  ToolTip="Select database profile" 
VerticalContentAlignment="Center"
                      ItemsSource="{Binding Source={StaticResource 
xmldata}, XPath=profile/profilename }" SelectedIndex="0" />

As far as I understand it, the XPath on the XmlDataProvider selects a 
single node as the context node, then a relative XPath on the 
ItemsSource of the ComboBox selects a list of nodes relative to that 
content node.


If you use an absolute XPath like //profilename then you are basically 
ignoring the XPath set on the XmlDataProvider.


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1777)
10/9/2008 12:38:44 PM
Reply:

Similar Artilces:

Converting a string date field/node in an XML document to Date type in a dataset
I am having problems with Date Strings when using VS.net method of converting an XML document to a dataset. I need the the date nodes to be of date type. As I am loading the Dataset to a datagrid, and I using the sort facility to sort by date. Currently the dates are being treated as strings. ree32@hotmail.com (ree32) wrote in message news:<7606ccc8.0409192108.3cbebe24@posting.google.com>... > I am having problems with Date Strings when using VS.net method of > converting an XML document to a dataset. > > I need the the date nodes to be of date type. As I am loading the ...

Urgent problem with System.Xml.Schema.XmlSchema
A set of xsd files has been working fine for us at this site, but now it gives *intermittent* errors for someone at a different cite (who is consuming the code we are producing). Most of the time it works fine. Occasionally it gives an error in the schema compiler: "System.Xml.Schema.XmlSchemaException: Wildcard '##other' allows element 'Page', and causes the content model to become ambiguous. A content model must be formed such that during validation of an element information item sequence, the particle contained directly, indirectly or implicitly therein with which t...

WPF and XBAP
I red http://msdn.microsoft.com/en-us/library/aa970060.aspx to learn WPF. I have some questions below. 1) Can I create a new project using WPF application template instead of WPF Browser Application (once done, convert to XBAP)? 2) If I have to use WPF Browser Application template, can I use all winform controls? 3) If I have to use WPF Browser Application template, can I use ASP.NET controls? -- Message posted via DotNetMonster.com http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net/201001/1 "aspfun via DotNetMonster.com" <u53138@uwe> wrote in news:a...

iniciar xml..
amigos pueden ayudarme donde conseguir lo basico de xml y como empezar a usarlo con ASP y asp.net, solamente se qeu xml funciona como una tabla..pero quisiera saber mas.. gracias.. -- Gerardo Alfredo F. Pa�l Analista de Sistemas gerardo f. paul wrote: > amigos pueden ayudarme donde conseguir lo basico de xml y como empezar a > usarlo con ASP y asp.net, solamente se qeu xml funciona como una tabla..pero > quisiera saber mas.. Start here - "Employing XML in the .NET Framework", http://msdn.microsoft.com/library/en-us/cpguide/html/cpconemployingxmlinnetframework.asp --...

String representation of XML from System.Xml.XmlTextWriter
Is there anyway to get the XML string representation from the XmlTextWriter object? I created a function to create an XML using this object, but I need to send back an XML as the return value of this function. But I am not sure how to do this. Sub getXML() Dim objXMLWriter As New System.Xml.XmlTextWriter(w, Text.Encoding.UTF8) objXMLWriter.WriteStartDocument() objXMLWriter.WriteStartElement("firstElement") objXMLWriter.WriteStartElement("SecondElement") objXMLWriter.WriteElementString("ThirdELement", "Just text&qu...

WPF Textbox won't wrap
As in the subject. I create a simple textbox and set the TextWrapping="Wrap". No wouldn't one expect wrapping for the text? Goggling does not bring much help and as an aside the searching for WPF and textbox is getting much more difficult because websites now want to have as many keywords as possible so every search for "textbox wpf wrap" brings windows controls pages. Nope. Why is everything in WPF so difficult? The number of lines of code I have written to make controls act similarly to windows controls is ridiculous. Thanks LS On 2010-0...

xml Templates
Does anyone where i can find or download more reciept templates?.. or maybe a prgram that nmakes it easy to design a template. thanks Pete There are some additional template available on the Reports Library section of Customer Source. I'm not aware of any receipt generator type programs, but XMLSpy from Altova is a terrific XML Editor. -- -- Glenn Adams Tiber Creek Consulting http://www.tibercreek.com glenn@tibercreek.com ---------------------------------------------- Please DO NOT respond to me directly but post all responses here in the newsgroup so that all can share the informa...

saving as xml
Hi, The following url give you an XML output http://webservices.titantvguide.titantv.com/contentblocks.asmx/TonightOn?registrationKey=g8byqgPai3PYi1i7VOfEcKDfKOeYwmYM is there a way to save this as an xml file on to the server? Thanks in Advance. Regards Manoj Manoj Paramu Das wrote: > is there a way to save this as an xml file on to the server? What's the difference between saving XML file and HTML file? Just create WebRequest, get response stream and save it. -- Oleg Tkachenko XML Insider http://www.tkachenko.com/blog ...

xml to serialize a dataset
I created a dataset using the DataSet Designer - http://aspnet.4guysfromrolla.com/articles/020806-1.aspx My objective was to serialize the generated dataset. protected void Page_Load(object sender, EventArgs e) { SalesOrderHeaderTableAdapter Adapter = new SalesOrderHeaderTableAdapter(); AdventureWorks.SalesOrderHeaderDataTable Orders = Adapter.GetDataBy(new DateTime(2004, 7, 1)); this.GridView1.DataSource = Orders; this.GridView1.DataBind(); /////////////////////////////////////////////////////////////////////////////// ...

need help with XML parser
I can parse a simple XML file (the hard way) but do not know how to parse the XML file (DTD and sample XML below) using System.XML. YOur help is greatly appreciated. Bill <!-- DTN REFINED FUELS XML FUEL PRICE FORMAT 2--> <!ELEMENT PRICES (TransmissionHeader, FuelPriceData+)> <!ELEMENT AdjustedPrice (#PCDATA)> <!ELEMENT BrandedCode (#PCDATA)> <!ELEMENT City (#PCDATA)> <!ELEMENT Change (#PCDATA)> <!ELEMENT EffectiveDate (#PCDATA)> <!ELEMENT EffectiveTime (#PCDATA)> <!ELEMENT FuelPriceData (SupplierName, Terminal, Product)> <!ELEMENT I...

insert WPF user control in ppt slide
Any way to insert WPF user control in ppt slide? Thanks, Vatia ...

Win Forms, WPF and Silverlight (?)
Hello. Amateur hour Webbiz here. :-) I'm in the middle of learning C# coming from VB6. Yes, it's a jump but a guy's got to move into the 21st Century eventually. Besides, in my past life (1980's) I was pretty familiar with C and C++ so learning the language part has been a breeze. However, .NET is a whole new world for me. Man, a lot has happened since the ole API days! While learning C# coding I'm getting familiar with my Visual Studio 2010 Pro IDE. Lots of strange files list that you have to get used to. Meanwhile, I've got a book open for WPF and ...

WPF DataBinding
I'm developing a fairly simple WPF solution. It's basically just a treeview on the left side, and a listview on the other. Very similar to Windows explorer in looking at the file system, but not with the file system. 8-) Anyway, here's my problem: My WPF listview has 5 columns. Each column has a name, and each column was databound using a simple custom expression. e.g.: <ListView.View> <GridView> <GridViewColumn Header="Column1" DisplayMemberBinding="{Binding A}"/> <GridViewColumn Header="Column2" Disp...

Signed-signed xml-doc and xsd
Hi, I�m a bit of a newbie when it comes to xml but here goes: I am using the SignedXml-class to construct a signed xmldoc which in turn contains 1 or more signed xml-doc which creates the following structure (edited of course): <Signature xmlns:xd="Whatever"> <Object Id="A uri"> <Signature> <Object Id="Another uri">My data</Object> </Signature> </Object> </Signature> My problem occurrs when try to use xsd.exe to create a schema for this. I get the fol...

XML
I am ripping my hair out over this. I need to find a simple way of loading xml documents into a VS2005 mfc app. I want to be able to add nodes to a document or create a new one, as well as display it. I have checked out xerces and a package my oracle as well as about 6 (no kidding) differnt packages available. I also am having trouble with finding a way to use msxml - am I stupid or are the docs slanted twoards .net and VB? Any of the files I've downloaded won;t compile. Am I missing an sdk, I thought it came with VS2005, am I wrong? Please help me on this. TIA b "sa...

xml within xml?
Hi all, I wish to embed an xml document within an element of another xml document. If I enclose the child xml within a CDATA section will the DOM not parse the child xml? What is the best way to do this? Additionally what should the parent element be defined as in the xsd? I noticed xs:anytype throws an error when validating the final xml doc. TIA, RP RP wrote: > Hi all, I wish to embed an xml document within an element of another xml > document. If I enclose the child xml within a CDATA section will the DOM not > parse the child xml? What is the best way to do this? Additionally...

XML Question
Hi, Using Excel 2003 Pro. I've figured out how to pull an XML file from a remote web server into Excel and map the 2 fields I'm interested in (ProductID and ProductName) to cells, so the data looks like this ProductName ProductID Product 1 1234 Product 2 5678 etc...... However I want to reformat the results so I end up with this "Product 1" ** 0.05 ** http://www.website.com/1234.aspx "Product 2" ** 0.05 ** http://www.website.com/5678.aspx etc..... I need quotes around the product name, the 2 stars in co...

Newbie in XML with C# question
Hello, I am learning how to using XML documents to store data. I get this error: Access to the path "c:\inetpub\wwwroot\Info.xml" is denied. I have tried with the full path of the file, with / infront of the file. How do I get the data in too the xml document Here is the code below: using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Xml; using System.Xml.XPath; ...

DataView from XML
I have an XML doc that has an element called date. This has a date in the following format "1/6/2004". I am using a filter sting such as "date > myDate" myDate is in the same format and is a date datatype. Everything worked fine until the new year, now i am having a problem if I put in a date from last year. It will not get any rows from '04. I also use a schema that has the following: "<xs:element name="date" type="xs:date"/>" Does anyone have any idea how to solve this problem? Thanks, Andy Andy wrote: > I have an XML ...

Adding an additional XML node
The below is the article I read today having the same question I want to raise here has no answer yet, so I copy and paste it again with hoping somebody can help out! I have seen samples of custom XML nodes in the eConnect help file eConnect8.0.chm. Has anyone seen code samples that show how to get the node into the struct. If you type 'eConnect business logic, extending' in the index textbox in the chm file you will get a page titled 'Extendign Business Logic'. If you click the link 'XML document' you will be presented with a page containing the following XML. &l...

Is it possible to define a schema that a xml tag can contains xml or text?
so xml could look like <field>test</field> or <field><test>this is a test</test></field> thanks! davidw wrote: > so xml could look like > > <field>test</field> > > or > > <field><test>this is a test</test></field> Example for mixed contents that allows both your above examples: <xs:element name="field" maxOccurs="unbounded"> <xs:complexType mixed="true"> <xs:sequence> <xs:element name="test&q...

FOR XML Explicit, XMLDATA not giving relationship information in XDR for nested XML
This is a problem that has been nagging me for a while, and I cannot figure out how to best solve the problem: I have a stored procedure that returns multi-level "nested" XML and inline XDR. My goal is to have a .NET application read the XML into a DataSet using the inline schema, and the relations automatically created according to the nesting of the elements. My query in the stored procedure looks similar to this: SELECT 1 AS TAG, NULL AS PARENT, c.name [Customer!1!Name] NULL [Details!2!Address] FROM Customer c UNION ALL SELECT 2 AS TAG, 1 AS PARENT, NULL, c.address FROM Custom...

XML support
XML sorry accidentally posted unfinished message "MSNews2" <null2@null.com> wrote in message news:OqNqb#0yGHA.4116@TK2MSFTNGP02.phx.gbl... > XML > > ...

XML Deserialization
Hello Guys, I have tried to use the xsd.exe tool to generate a class for the following Oracle-generated xml sample but always fail to get it right when I try to change oracle xml elements names to the class's names, specifically I'm not sure how to do it for the ROWSET and ROW part of it. Being very new to the serialization/deserialization business I'm sure this is very easy to implement for someone with a bit of more knowledge of it, can some help me please. I have created 2 classes for for Department and Employee: [XmlRoot("ROWSET")] class Dep...

Databindings and XML
Dear Group I wonder if I do something wrong and whether this is possible at all. Any hint is greatly appreciated. I have a XML file bound to a Treeview. The treenodes Text/Value properties bind and populate fine if I set them to an attribute of the XML tag. What I would like to do however is setting my nodes text and value property to text that is between the XML tags. Example: <products> <article value="1" text="Washing Powder"> <description text="Super Whitewash"> Super Whitewash is ideal and a 'must hav...