473,770 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Urgent Help Needed Converting from XmlNode to Dataset

Mae
Dear All,

I have a problem here, I'm using C# Webform calling a webservices. The
webservices return me a XMLnode, using this XMLnode I want to convert it to
dataset so I can bind to the datagrid, by extracting the
<CustomerData ></CustomerData> block from the xmlnode.

Below is the sample of xmlnode return from webservices.

<?xml version="1.0" encoding="utf-8"?>
<OutputParams >
<CustomerData >
<CustomerID>1 </CustomerID>
<CustomerName>T EST1</CustomerName>
<Gender>M </Gender>
<DateOfBirth>19 800101</DateOfBirth>
</CustomerData>
<CustomerData >
<CustomerID>1 </CustomerID>
<CustomerName>T EST2</CustomerName>
<Gender />
<DateOfBirth>19 000101</DateOfBirth>
</CustomerData>
<CustomerData >
<CustomerID>3 </CustomerID>
<CustomerName>T EST3</CustomerName>
<Gender />
<DateOfBirth>19 000101</DateOfBirth>
</CustomerData>
<ReturnCode>0 </ReturnCode>
<ErrorCode>0</ErrorCode>
<ErrorDescripti on />
</OutputParams>

How can it be done? Please provide some examples on this.
Thanks in advance.
Cheers,
mae
Nov 18 '05 #1
3 5059
you need something like this

XmlNode xn = new XmlNode();

// the above represents you xml node... replace all instances with your
node.

DataSet dsXML = new DataSet();

XmlDataDocument xdd = new XmlDataDocument (dsXML);

xdd.LoadXml(xn. OuterXml);

// this should populate the dataset

if you have any problems.. message back.. i will try and give you a complete
working example
--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Mae" <Ma*@discussion s.microsoft.com > wrote in message
news:A0******** *************** ***********@mic rosoft.com...
Dear All,

I have a problem here, I'm using C# Webform calling a webservices. The
webservices return me a XMLnode, using this XMLnode I want to convert it to dataset so I can bind to the datagrid, by extracting the
<CustomerData ></CustomerData> block from the xmlnode.

Below is the sample of xmlnode return from webservices.

<?xml version="1.0" encoding="utf-8"?>
<OutputParams >
<CustomerData >
<CustomerID>1 </CustomerID>
<CustomerName>T EST1</CustomerName>
<Gender>M </Gender>
<DateOfBirth>19 800101</DateOfBirth>
</CustomerData>
<CustomerData >
<CustomerID>1 </CustomerID>
<CustomerName>T EST2</CustomerName>
<Gender />
<DateOfBirth>19 000101</DateOfBirth>
</CustomerData>
<CustomerData >
<CustomerID>3 </CustomerID>
<CustomerName>T EST3</CustomerName>
<Gender />
<DateOfBirth>19 000101</DateOfBirth>
</CustomerData>
<ReturnCode>0 </ReturnCode>
<ErrorCode>0</ErrorCode>
<ErrorDescripti on />
</OutputParams>

How can it be done? Please provide some examples on this.
Thanks in advance.
Cheers,
mae

Nov 18 '05 #2
Mae
Hi Hermit,

I'm newbie to XML, I'm not sure how it works.
Can you provide me a complete working examples, that shows how to the
required <CustomerData ></CustomerData> block bind to datagrid ?

Thanks in advance.

Cheers,
Mae

"Hermit Dave" wrote:
you need something like this

XmlNode xn = new XmlNode();

// the above represents you xml node... replace all instances with your
node.

DataSet dsXML = new DataSet();

XmlDataDocument xdd = new XmlDataDocument (dsXML);

xdd.LoadXml(xn. OuterXml);

// this should populate the dataset

if you have any problems.. message back.. i will try and give you a complete
working example
--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Mae" <Ma*@discussion s.microsoft.com > wrote in message
news:A0******** *************** ***********@mic rosoft.com...
Dear All,

I have a problem here, I'm using C# Webform calling a webservices. The
webservices return me a XMLnode, using this XMLnode I want to convert it

to
dataset so I can bind to the datagrid, by extracting the
<CustomerData ></CustomerData> block from the xmlnode.

Below is the sample of xmlnode return from webservices.

<?xml version="1.0" encoding="utf-8"?>
<OutputParams >
<CustomerData >
<CustomerID>1 </CustomerID>
<CustomerName>T EST1</CustomerName>
<Gender>M </Gender>
<DateOfBirth>19 800101</DateOfBirth>
</CustomerData>
<CustomerData >
<CustomerID>1 </CustomerID>
<CustomerName>T EST2</CustomerName>
<Gender />
<DateOfBirth>19 000101</DateOfBirth>
</CustomerData>
<CustomerData >
<CustomerID>3 </CustomerID>
<CustomerName>T EST3</CustomerName>
<Gender />
<DateOfBirth>19 000101</DateOfBirth>
</CustomerData>
<ReturnCode>0 </ReturnCode>
<ErrorCode>0</ErrorCode>
<ErrorDescripti on />
</OutputParams>

How can it be done? Please provide some examples on this.
Thanks in advance.
Cheers,
mae


Nov 18 '05 #3
i created a xmlfile from your node list but as i said you can directly use
the OuterXML
i will copy contents off each file and add those here. Hope this helps

Customers.xml
---------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<OutputParams >
<CustomerData >
<CustomerID>1 </CustomerID>
<CustomerName>T EST1</CustomerName>
<Gender>M</Gender>
<DateOfBirth>19 800101</DateOfBirth>
</CustomerData>
<CustomerData >
<CustomerID>1 </CustomerID>
<CustomerName>T EST2</CustomerName>
<Gender />
<DateOfBirth>19 000101</DateOfBirth>
</CustomerData>
<CustomerData >
<CustomerID>3 </CustomerID>
<CustomerName>T EST3</CustomerName>
<Gender />
<DateOfBirth>19 000101</DateOfBirth>
</CustomerData>
<ReturnCode>0 </ReturnCode>
<ErrorCode>0</ErrorCode>
<ErrorDescripti on />
</OutputParams>
---------------------------------------------------
Customers.xsd (used xsd to load the schema - Cause you do not want the
Return Code ErrorCode & Description in the dataset)
---------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="OutputParam s" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="OutputPar ams">
<xs:complexType >
<xs:choice maxOccurs="unbo unded">
<xs:element name="CustomerD ata">
<xs:complexType >
<xs:sequence>
<xs:element name="CustomerI D" type="xs:int"></xs:element>
<xs:element name="CustomerN ame" type="xs:string "></xs:element>
<xs:element name="Gender" type="xs:string "></xs:element>
<xs:element name="DateOfBir th" type="xs:string "></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
---------------------------------------------------
StepByStep2_9.c s
---------------------------------------------------
using System;
using System.Data;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Xml;

namespace StepByStep
{
/// <summary>
/// Summary description for StepByStep2_9.
/// </summary>
public class StepByStep2_9 : System.Windows. Forms.Form
{
private System.Windows. Forms.DataGrid dgXML;
private System.Windows. Forms.Button btnLoadXML;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public StepByStep2_9()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

//
// TODO: Add any constructor code after InitializeCompo nent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.dgXML = new System.Windows. Forms.DataGrid( );
this.btnLoadXML = new System.Windows. Forms.Button();
((System.Compon entModel.ISuppo rtInitialize)(t his.dgXML)).Beg inInit();
this.SuspendLay out();
//
// dgXML
//
this.dgXML.Data Member = "";
this.dgXML.Head erForeColor = System.Drawing. SystemColors.Co ntrolText;
this.dgXML.Loca tion = new System.Drawing. Point(16, 64);
this.dgXML.Name = "dgXML";
this.dgXML.Size = new System.Drawing. Size(568, 200);
this.dgXML.TabI ndex = 3;
//
// btnLoadXML
//
this.btnLoadXML .Location = new System.Drawing. Point(16, 24);
this.btnLoadXML .Name = "btnLoadXML ";
this.btnLoadXML .TabIndex = 2;
this.btnLoadXML .Text = "Load XML";
this.btnLoadXML .Click += new System.EventHan dler(this.btnLo adXML_Click);
//
// StepByStep2_9
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(600, 285);
this.Controls.A dd(this.dgXML);
this.Controls.A dd(this.btnLoad XML);
this.Name = "StepByStep2_9" ;
this.Text = "StepByStep2_9" ;
this.Load += new System.EventHan dler(this.StepB yStep2_9_Load);
((System.Compon entModel.ISuppo rtInitialize)(t his.dgXML)).End Init();
this.ResumeLayo ut(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new StepByStep2_9() );
}

private void btnLoadXML_Clic k(object sender, System.EventArg s e)
{
DataSet ds = new DataSet();
ds.ReadXmlSchem a(@"..\..\Custo mers.xsd");

// create matching xml data document
XmlDataDocument xdd = new XmlDataDocument (ds);
try
{
xdd.Load(@"..\. .\Customers.xml ");
}
catch(Exception ex)
{
MessageBox.Show (ex.Message, "Error Loading XML");
}
this.dgXML.Data Source = ds;
this.dgXML.Data Member = "CustomerDa ta";
}
}
}

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Mae" <Ma*@discussion s.microsoft.com > wrote in message
news:89******** *************** ***********@mic rosoft.com...
Hi Hermit,

I'm newbie to XML, I'm not sure how it works.
Can you provide me a complete working examples, that shows how to the
required <CustomerData ></CustomerData> block bind to datagrid ?

Thanks in advance.

Cheers,
Mae

"Hermit Dave" wrote:
you need something like this

XmlNode xn = new XmlNode();

// the above represents you xml node... replace all instances with your
node.

DataSet dsXML = new DataSet();

XmlDataDocument xdd = new XmlDataDocument (dsXML);

xdd.LoadXml(xn. OuterXml);

// this should populate the dataset

if you have any problems.. message back.. i will try and give you a complete working example
--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Mae" <Ma*@discussion s.microsoft.com > wrote in message
news:A0******** *************** ***********@mic rosoft.com...
Dear All,

I have a problem here, I'm using C# Webform calling a webservices. The
webservices return me a XMLnode, using this XMLnode I want to convert
it to
dataset so I can bind to the datagrid, by extracting the
<CustomerData ></CustomerData> block from the xmlnode.

Below is the sample of xmlnode return from webservices.

<?xml version="1.0" encoding="utf-8"?>
<OutputParams >
<CustomerData >
<CustomerID>1 </CustomerID>
<CustomerName>T EST1</CustomerName>
<Gender>M </Gender>
<DateOfBirth>19 800101</DateOfBirth>
</CustomerData>
<CustomerData >
<CustomerID>1 </CustomerID>
<CustomerName>T EST2</CustomerName>
<Gender />
<DateOfBirth>19 000101</DateOfBirth>
</CustomerData>
<CustomerData >
<CustomerID>3 </CustomerID>
<CustomerName>T EST3</CustomerName>
<Gender />
<DateOfBirth>19 000101</DateOfBirth>
</CustomerData>
<ReturnCode>0 </ReturnCode>
<ErrorCode>0</ErrorCode>
<ErrorDescripti on />
</OutputParams>

How can it be done? Please provide some examples on this.
Thanks in advance.
Cheers,
mae


Nov 18 '05 #4

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

Similar topics

2
5902
by: tim djossou | last post by:
Hi Is there a simple way to create a dataset from a XmlNode ? or from a string containing the XML? Regards
1
998
by: Michael Persaud | last post by:
Hi, I am trying to retrive data from a datatable. I want to have the information listed out in text so that i can send it via mail Any suggestions appreciated MP
1
3465
by: Mae Lim | last post by:
Dear all, I'm having problem with C# Web Services, in the Web Services it suppose to call another Web Services to return XmlNode to current Web Services. Below is the sample code :- WServices.WServices WSObj = new WServices.WServices(); WSObj.Credentials = System.Net.CredentialCache.DefaultCredentials; XmlNode objNode = WSObj.GetCustomerByID(CustomerID); --> Catch Exception
1
1252
by: Alex | last post by:
I have the follow code: private void crear() { //creating a dataset DataSet myDataset=null; SqlConnection sqlConnection=null; SqlDataAdapter sqlCommand=null; try {
0
2140
by: asgars | last post by:
hi friends, i have a little problem while accessing the attributes returned through xml webservice. i am getting an XMLNode which i need to get into a dataset. Currently i am using this method: 1) Creating a Dataset ds and XMLNode node. 2) Reading from XMLNode into XMLNodeReader, reader. 3) Then getting data into dataset by ds.ReadXML(reader). I am able to fetch all the details.
5
3882
by: GaryDean | last post by:
I have a web service method that returns an XMLDocument. The signature is: public XmlDocument GetPOs() The following client code calls this method but it accepts an XMLNode instead of an XMLDocument and my first question is why does this work? XmlNode neNode; neNode = myHFCService.GetPOs(); DataSet myds = new DataSet();
4
1249
by: slinky | last post by:
I've tried this week everything I can think of to get this code to work , can any kind soul take a look at my code and my what should be a simple task and help me out. I've looked in books, websites, and can't find a solution... thanks! I have an aspx for with a textbox and a button. The goal is to simply have the user type a message, hit the button and it should append to the XML file. I can open the aspx in the browser with no problem,...
1
3318
by: Andrus | last post by:
How to remove whole Xmlnode so that outer tags are also removed ? To reproduce, run the code. Observed result: <Query> <DataSourceName>DS1</DataSourceName> <QueryParameters> </QueryParameters>
1
4149
by: Alexander Vasilevsky | last post by:
Is that valid XmlNode for dataset xml. How to fill in those xml 'of a dataset? There DataSet.ReadXml (XmlReader), but you can initialize XmlReader only URI xml- file, and I have a xml data dataseta in XmlNode ... http://www.alvas.net - Audio tools for C# and VB.Net developers
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8933
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.