![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | XML Problem as XMLDatasource from windowsapp to asp.net Sorry for the crosspost, but I really am stumped here. (vs2008pro) The problem is using an XML file as a Datasource in asp.net that was created in a vb.net winforms app. Any explination would be much appreciated. I will try to explain the best way I can with the following example: Step1... Create a vb.net windowsform application and manually add a dataset. Create 1 table in the dataset (this dataset and table are not connected to a physical file). I created a table called Colors and added the following columns. ID-key Color-String ImageUrl-String Put a datagridview on the windows form and a button. Bind the datagridview to dataset1 and the bindingsource to the colors table. Put a commandbutton on the form, Add this code DataSet1.AcceptChanges() DataSet1.WriteXml("C:\Temp\myxmlfile.xml") DataSet1.WriteXmlSchema("C:\Temp\myxmlfile.xsd") Now, run the app and add data to the datagrid, and push the command button. Now you have an xml file created directly from the dataset with some data. I went and took the xml file and changed it around a bit and saved it with a different name: myxmlfile_canBind.xml ===here is the xmlfile changed. <?xml version="1.0" encoding="utf-8" ?> <DataSet1> <Colors> <AColor Id="1" Color="Black" ImageUrl="somewhere" /> <AColor Id="2" Color="Red" ImageUrl="somewhereelse" /> </Colors> </DataSet1> ==== Here is a snippet of the original <?xml version="1.0" standalone="yes"?> <DataSet1 xmlns="http://tempuri.org/DataSet1.xsd"> <Colors> <ID>1</ID> <Color>Black</Color> <ImageUrl>somewhere</ImageUrl> </Colors> <Colors> <ID>2</ID> <Color>Red</Color> <ImageUrl>SomewhereElse</ImageUrl> </Colors> </DataSet1> === ***Take note how the two xmls look different. (the one created by vb.net writexml and the one created manually) Step2: Now create a brand new asp.net project, Copy all the xml files created in to the App_Data folder. Add a dropdown on the aspx page, and an xmldatasource. The XMLDatasource1 has the properties set as follows: DataFile: ~/App_Data/myxmlfile_canBind.xml XPath: DataSet1/Colors/AColor Bind the dropdown to the xmlDatasource1 - notice how you can pick an ID for the value and the color for the display. -It works... Now try and bind to the second xml file ( that was actually created through vb ) by writing an xml with the same step2. Dont forget to pick a different Xpath. I cannot tell you what it is cause I cannot get this part working. -You cannot... Funny how you cannot bind to a valid xmldatasource that was actually created with the writeXML Cheers' Miro |
My System Specs![]() |
| | #2 (permalink) |
| | Re: XML Problem as XMLDatasource from windowsapp to asp.net Miro wrote: Quote: > Now try and bind to the second xml file ( that was actually created > through vb ) by writing an xml with the same step2. > Dont forget to pick a different Xpath. I cannot tell you what it is > cause I cannot get this part working. you can bind to. So you either need to ensure that your data table columns are output as attributes or you need to apply an XSLT stylesheet to transform elements you want to bind to to attributes. If you want to ensure that columns are output as attributes then set e.g. foreach (DataColumn col in yourDataTable.Columns) { col.ColumnMapping = MappingType.Attribute; } -- Martin Honnen --- MVP XML http://msmvps.com/blogs/martin_honnen/ |
My System Specs![]() |
| | #3 (permalink) |
| | Re: XML Problem as XMLDatasource from windowsapp to asp.net Thank you martin for that explination. I couldn't understand why my version of the xml file would not work. Cheers' Miro "Martin Honnen" <mahotrash@newsgroup> wrote in message news:O2Wmaf$VKHA.3720@newsgroup Quote: > Miro wrote: > Quote: >> Now try and bind to the second xml file ( that was actually created >> through vb ) by writing an xml with the same step2. >> Dont forget to pick a different Xpath. I cannot tell you what it is >> cause I cannot get this part working. > The XmlDataSource exposes XML attributes of XML elements as properties you > can bind to. So you either need to ensure that your data table columns are > output as attributes or you need to apply an XSLT stylesheet to transform > elements you want to bind to to attributes. > If you want to ensure that columns are output as attributes then set e.g. > > foreach (DataColumn col in yourDataTable.Columns) > { > col.ColumnMapping = MappingType.Attribute; > } > > -- > > Martin Honnen --- MVP XML > http://msmvps.com/blogs/martin_honnen/ |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Re: Windows Mail Attachement Problem and Adobe Player Problem with IE8 | Vista mail | |||
| Generic McAfee Problem Message in Vista Problem Reports | Vista performance & maintenance | |||
| Repeater and XmlDataSource | Vista installation & setup | |||