Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to see below format as output of my webservice but it is return empty, would you mind help me to how figure it out?

I am using asp.net2

I would like to receive out put like below:

<LIST OF CUSTOMER>
<CustomerData>
    <V_CUST_CODE value="c1"/>
    <V_CUST_NAME value="Customer 1"/>
</CustomerData>
<CustomerData>
    <V_CUST_CODE value="c2"/>
    <V_CUST_NAME value="Customer 2"/>
</CustomerData>
<CustomerData>
    <V_CUST_CODE value="c2"/>
    <V_CUST_NAME value="Customer 2"/>
</CustomerData>
<LIST OF CUSTOMER/>

my current out put:

<?xml version="1.0" encoding="utf-8" ?> 
  <ArrayOfCustomerData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://123.23.45.34/sms/" /> 

my webservice

[WebMethod]
    public List<CustomerData> getFMSCustomerName()
    {
        string[] cols = {"V_CUST_CODE", "V_CUST_NAME"};

        ArrayList CustomerList = (ArrayList)db.Select(cols, "table1", "", "order by V_CUST_NAME");

        List<CustomerData> cd = new List<CustomerData>();
        foreach(DataRow dr in CustomerList)
            cd.Add(new CustomerData(dr["V_CUST_CODE"].ToString(), dr["V_CUST_NAME"].ToString()));

        return cd;
    }


public class CustomerData
{
    private string _V_CUST_CODE;
    private string _V_CUST_NAME;

    public String V_CUST_CODE
    {
        get
        {
            return this._V_CUST_CODE;
        }
        set
        {
            this._V_CUST_CODE = value;
        }
    }
    public String V_CUST_NAME
    {
        get
        {
            return this._V_CUST_NAME;
        }
        set
        {
            this._V_CUST_NAME = value;
        }
    }


    public CustomerData(String V_CUST_CODE, String V_CUST_NAME)
    {
        this.V_CUST_CODE = V_CUST_CODE;
        this.V_CUST_NAME = V_CUST_NAME;

    }

    public CustomerData() { }
}
share|improve this question

1 Answer 1

I solve my problem by using below code:

public String getFMSCustomerName()
    {
        string[] cols = {"V_CUST_CODE", "V_CUST_NAME"};

        ArrayList CustomerList = (ArrayList)db.Select(cols, "table1", " V_STATUS = 'A'", "order by V_CUST_NAME");

        //List<CustomerData> cd = new List<CustomerData>();
        XmlDocument doc = new XmlDocument();

        XmlNode CustomersNode = doc.CreateElement("Customers");
        doc.AppendChild(CustomersNode);

        foreach (DataRow dr in CustomerList)
        {
            //  cd.Add(new CustomerData(dr["V_CUST_CODE"].ToString(), dr["V_CUST_NAME"].ToString()));
            XmlNode customerNode = doc.CreateElement("Customer");

            XmlNode V_CUST_CODENode = doc.CreateElement("V_CUST_CODE");
            V_CUST_CODENode.AppendChild(doc.CreateTextNode(dr["V_CUST_CODE"].ToString()));
            customerNode.AppendChild(V_CUST_CODENode);
            XmlNode V_CUST_NAMENode = doc.CreateElement("V_CUST_NAME");
            V_CUST_NAMENode.AppendChild(doc.CreateTextNode(dr["V_CUST_NAME"].ToString()));
            customerNode.AppendChild(V_CUST_NAMENode);
            CustomersNode.AppendChild(customerNode);
        }

        return doc.OuterXml;
    }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.