1

I am using Visual Studio 2013 Ultimate with SQL Server 2008 R2 version.

I have created my web service from which I return the custom XML in StringBuilder data to my desktop application (C#).

So my question is how to store that XML and how to read it?

Demo of my custom xml data:

<TableName>students
<row>
<StudentId><![CDATA[1]]></StudentId>
<StudentName><![CDATA[abc]]></StudentName>
<Password><![CDATA[password]]></Password>
</row>
</TableName>

This is just one example of data, there are multiple data coming like this format.

Please someone help me how to store and read this XML!

3 rules
  • 1,359
  • 3
  • 26
  • 54
  • How do you want to store the data? In a database, as a file? – Dan O'Leary Feb 25 '16 at 12:12
  • see this link for reading xml data : http://stackoverflow.com/questions/364253/how-to-deserialize-xml-document. On a side note, is that `password` hashed? Are you just transferring it in plaintext? – Vishnu Prasad V Feb 25 '16 at 12:14
  • @DanO'Leary I don't want to store xml in database I simply want to store it in one variable or any xml reader from which I can read in C#. – 3 rules Feb 25 '16 at 12:22
  • Ok, could you share how you are calling your web service from the desktop application? – Dan O'Leary Feb 25 '16 at 12:26
  • @DanO'Leary Just simply call the function by adding web service's reference in my desktop application and call by creating object of ServiceClient. i.e. WebServiceApp.Service1Client client = new WebServiceApp.Service1Client(); and call the function client.functionname(); – 3 rules Feb 25 '16 at 12:48

1 Answers1

0

Try with this -

public class TableName
{
    public Students students { get; set; }
}

[XmlRoot(ElementName = "students")]
public class Students
{
    [XmlElement(ElementName = "row")]
    public List<Row> Rows { get; set; }
}

public class Row
{
    public string StudentId { get; set; }
    public string StudentName { get; set; }
    public string Password { get; set; }
}

var ser = new XmlSerializer(typeof(TableName));
var def = new XmlSerializerNamespaces();
def.Add("", "");
var obj = ser.Deserialize("xmlPath");
Amit Kumar Ghosh
  • 3,618
  • 1
  • 20
  • 24
  • Thanks for your response your solution is good but the demo is just for showing that how my data are coming there is a bunch of data coming like this and many more row values are coming. So for each table, row I can't create class and create get set value so I need different solution. – 3 rules Feb 25 '16 at 12:17