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