473,395 Members | 1,377 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,395 software developers and data experts.

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>TEST1</CustomerName>
<Gender>M </Gender>
<DateOfBirth>19800101</DateOfBirth>
</CustomerData>
<CustomerData>
<CustomerID>1</CustomerID>
<CustomerName>TEST2</CustomerName>
<Gender />
<DateOfBirth>19000101</DateOfBirth>
</CustomerData>
<CustomerData>
<CustomerID>3</CustomerID>
<CustomerName>TEST3</CustomerName>
<Gender />
<DateOfBirth>19000101</DateOfBirth>
</CustomerData>
<ReturnCode>0</ReturnCode>
<ErrorCode>0</ErrorCode>
<ErrorDescription />
</OutputParams>

How can it be done? Please provide some examples on this.
Thanks in advance.
Cheers,
mae
Nov 18 '05 #1
3 5030
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*@discussions.microsoft.com> wrote in message
news:A0**********************************@microsof t.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>TEST1</CustomerName>
<Gender>M </Gender>
<DateOfBirth>19800101</DateOfBirth>
</CustomerData>
<CustomerData>
<CustomerID>1</CustomerID>
<CustomerName>TEST2</CustomerName>
<Gender />
<DateOfBirth>19000101</DateOfBirth>
</CustomerData>
<CustomerData>
<CustomerID>3</CustomerID>
<CustomerName>TEST3</CustomerName>
<Gender />
<DateOfBirth>19000101</DateOfBirth>
</CustomerData>
<ReturnCode>0</ReturnCode>
<ErrorCode>0</ErrorCode>
<ErrorDescription />
</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*@discussions.microsoft.com> wrote in message
news:A0**********************************@microsof t.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>TEST1</CustomerName>
<Gender>M </Gender>
<DateOfBirth>19800101</DateOfBirth>
</CustomerData>
<CustomerData>
<CustomerID>1</CustomerID>
<CustomerName>TEST2</CustomerName>
<Gender />
<DateOfBirth>19000101</DateOfBirth>
</CustomerData>
<CustomerData>
<CustomerID>3</CustomerID>
<CustomerName>TEST3</CustomerName>
<Gender />
<DateOfBirth>19000101</DateOfBirth>
</CustomerData>
<ReturnCode>0</ReturnCode>
<ErrorCode>0</ErrorCode>
<ErrorDescription />
</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>TEST1</CustomerName>
<Gender>M</Gender>
<DateOfBirth>19800101</DateOfBirth>
</CustomerData>
<CustomerData>
<CustomerID>1</CustomerID>
<CustomerName>TEST2</CustomerName>
<Gender />
<DateOfBirth>19000101</DateOfBirth>
</CustomerData>
<CustomerData>
<CustomerID>3</CustomerID>
<CustomerName>TEST3</CustomerName>
<Gender />
<DateOfBirth>19000101</DateOfBirth>
</CustomerData>
<ReturnCode>0</ReturnCode>
<ErrorCode>0</ErrorCode>
<ErrorDescription />
</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="OutputParams" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="OutputParams">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="CustomerData">
<xs:complexType>
<xs:sequence>
<xs:element name="CustomerID" type="xs:int"></xs:element>
<xs:element name="CustomerName" type="xs:string"></xs:element>
<xs:element name="Gender" type="xs:string"></xs:element>
<xs:element name="DateOfBirth" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
---------------------------------------------------
StepByStep2_9.cs
---------------------------------------------------
using System;
using System.Data;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
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.ComponentModel.Container components = null;

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

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
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 InitializeComponent()
{
this.dgXML = new System.Windows.Forms.DataGrid();
this.btnLoadXML = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.d gXML)).BeginInit();
this.SuspendLayout();
//
// dgXML
//
this.dgXML.DataMember = "";
this.dgXML.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dgXML.Location = new System.Drawing.Point(16, 64);
this.dgXML.Name = "dgXML";
this.dgXML.Size = new System.Drawing.Size(568, 200);
this.dgXML.TabIndex = 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.EventHandler(this.btnLoadXML_Click);
//
// StepByStep2_9
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(600, 285);
this.Controls.Add(this.dgXML);
this.Controls.Add(this.btnLoadXML);
this.Name = "StepByStep2_9";
this.Text = "StepByStep2_9";
this.Load += new System.EventHandler(this.StepByStep2_9_Load);
((System.ComponentModel.ISupportInitialize)(this.d gXML)).EndInit();
this.ResumeLayout(false);

}
#endregion

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

private void btnLoadXML_Click(object sender, System.EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXmlSchema(@"..\..\Customers.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.DataSource = ds;
this.dgXML.DataMember = "CustomerData";
}
}
}

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Mae" <Ma*@discussions.microsoft.com> wrote in message
news:89**********************************@microsof t.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*@discussions.microsoft.com> wrote in message
news:A0**********************************@microsof t.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>TEST1</CustomerName>
<Gender>M </Gender>
<DateOfBirth>19800101</DateOfBirth>
</CustomerData>
<CustomerData>
<CustomerID>1</CustomerID>
<CustomerName>TEST2</CustomerName>
<Gender />
<DateOfBirth>19000101</DateOfBirth>
</CustomerData>
<CustomerData>
<CustomerID>3</CustomerID>
<CustomerName>TEST3</CustomerName>
<Gender />
<DateOfBirth>19000101</DateOfBirth>
</CustomerData>
<ReturnCode>0</ReturnCode>
<ErrorCode>0</ErrorCode>
<ErrorDescription />
</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
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
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
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 :- ...
1
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
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:...
5
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...
4
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,...
1
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>...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
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
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...
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...

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.