473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How to set DataSource in XML file

I have a listbox and I want to set the DataSource property to a specific
location of an XML file. Can someone tell me how? I want the DataMember
property to refer to the <ChildTestsection to list all the tests under that
section.

I want to refer either to the <ChildTestunder <TestDefinitionsor the
<ChildTestunder <TestRuns>.
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<CITests>
<TestDefinitions>
<TestGroupName TestName="Application">
<ChildTest>Run Registry Entry</ChildTest>
<ChildTest>Spawn Process</ChildTest>
</TestGroupName>
<TestRuns>
<TestGroupName TestName="Run1.tr">
<ChildTest>Suite1.ts</ChildTest>
<ChildTest>Suite2.ts</ChildTest>
</TestGroupName>
<TestGroupName TestName="Run2.tr">
<ChildTest>Suite2.ts</ChildTest>
</TestGroupName>
</TestRuns>
<TestGroupName TestName="BIOS">
<ChildTest>System Power</ChildTest>
</TestGroupName>
<TestGroupName TestName="Operating System">
<ChildTest>Registry</ChildTest>
</TestGroupName>
<TestGroupName TestName="Storage">
<ChildTest>File Operations</ChildTest>
<ChildTest>File Properties</ChildTest>
</TestGroupName>
<TestGroupName TestName="System">
<ChildTest>Event Logs</ChildTest>
<ChildTest>OCA MRK Files</ChildTest>
<ChildTest>PnP Driver Version Check</ChildTest>
<ChildTest>System Properties Panel</ChildTest>
<ChildTest>WMI</ChildTest>
</TestGroupName>
</TestDefinitions>
</CITests>
--
-----------
Thanks,
Steve
Oct 23 '06 #1
5 3342
Hi Steve,

The XmlDocument itself cannot be bound to a ListBox as data source
directly, because it doesn't implement an IList interface. In this case,
you can try to load everything into a DataSet and use the DataSet as
ListBox.DataSource.

Here is an example. It works fine on my machine.

DataSet ds = new DataSet();
ds.ReadXml("..\\..\\XMLFile1.xml");

this.listBox1.DataSource = ds;
this.listBox1.DisplayMember = "ChildTest.ChildTest_Text";

If anything is unclear, please feel free to let me know.

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Oct 24 '06 #2
This does indeed pull up my list now, but it pulls up all <ChildTestsin the
xml file. How do I filter it to pull up only the section that I desire?
--
-----------
Thanks,
Steve
"Kevin Yu [MSFT]" wrote:
Hi Steve,

The XmlDocument itself cannot be bound to a ListBox as data source
directly, because it doesn't implement an IList interface. In this case,
you can try to load everything into a DataSet and use the DataSet as
ListBox.DataSource.

Here is an example. It works fine on my machine.

DataSet ds = new DataSet();
ds.ReadXml("..\\..\\XMLFile1.xml");

this.listBox1.DataSource = ds;
this.listBox1.DisplayMember = "ChildTest.ChildTest_Text";

If anything is unclear, please feel free to let me know.

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Oct 24 '06 #3
Hi Steve,

If this the data in xml needs to be filtered, we cannot put it directly
into DataSet for data binding.

In this case, I suggest you try to use XSLT to transform the xml file,
filter out all the data that is not needed. Or you can load the xml file
into an XmlDocument and remove all the nodes except those <ChildTest>
elements under <TestDefinitionsor the <ChildTestunder <TestRuns>. Then
load the transformed xml into a DataSet and do the data binding.

This seems to be the only way, since we cannot bind to an xml file directly.

Please try this and let me know the results. Thank you!

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Oct 25 '06 #4
Thanks for the response. I read what you stated earlier and it got me to
thinking about serializing Data structures. I created a class that mirrored
the XML data and "deserialized" the XML data into my class. I then used the
class as my DataSource. I was able to move forward quickly after doing that.

Thank you again for triggering some thoughts on this end. :)
--
-----------
Thanks,
Steve
"Kevin Yu [MSFT]" wrote:
Hi Steve,

If this the data in xml needs to be filtered, we cannot put it directly
into DataSet for data binding.

In this case, I suggest you try to use XSLT to transform the xml file,
filter out all the data that is not needed. Or you can load the xml file
into an XmlDocument and remove all the nodes except those <ChildTest>
elements under <TestDefinitionsor the <ChildTestunder <TestRuns>. Then
load the transformed xml into a DataSet and do the data binding.

This seems to be the only way, since we cannot bind to an xml file directly.

Please try this and let me know the results. Thank you!

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Oct 25 '06 #5
Nice to know that you have a solution. Glad to help. :-)

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Oct 26 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: no-spam | last post by:
Hello group, I have some questions concerning configuring and using a JNDI DataSource with PostgreSQL and Apache Tomcat. Currently, I belive I have successfully configured a "basic" DataSource....
0
by: szabelin | last post by:
Hello - I need to populate myDataGrid.DataSource with the contents of a node of an XmlDocument. So everything I've seen so far has been: writing xml conents to a stream (physical file), and then...
5
by: Sky | last post by:
What makes something a valid DataSource? What methods/iterators/etc? Why do I ask? I do understand that a DataSet is based on an XML structure...but it's too table structured for what I am...
4
by: Jerry Camel | last post by:
On the WebLogic side of our development team, we use JNDI and access datasources that are defined outside the actual application. This is an advantage in several ways... Not the least is becasue...
0
by: ¿ Mahesh Kumar | last post by:
I have created a XML file as datasource which i 'm binding to a grid view control. During runtime I'm capturing items in XML file and displaying in a GRID VIEW control. but i want to remove or...
4
by: JeffP | last post by:
datagrid1 has a single column contact I'm getting an invalid datasource at... Me.DataGrid1.DataSource = cmd I don't want to use the methods here, I usually use SQLHelper psuedo code: dim ds...
2
by: nospam | last post by:
I have code that is working in one place but not another. In one spot, you click a button to open an XML file and have it read into a dataset. I then set the datasource of my datagrid to the...
3
by: balaki | last post by:
Hi, I am working on a Installer Project, which requires to deploy SQL Server 2005 Reports (.rdl files) and Datasource (.rds file). The datasource is common for all reports. The report files are...
0
by: morathm | last post by:
I have a windows client database management application written in C# that connects to remote web services to do all the heavy work. The thin-client app uses strong typed datasets, all maintained at...
1
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi misters, I used the Data Sources window to drop a custom object onto the designer surface. It created a BindingSource and BindingNavigator as a result. When I open the Properties window...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.