troubleshooting Question

C# code does not output the XML format i want.

Avatar of GeneBe
GeneBeFlag for United States of America asked on
XMLC#
10 Comments1 Solution83 ViewsLast Modified:
My C# code does not output the XML format i want.
Here's the code:

[WebMethod(Description = "GetAddressTest")]
[return: XmlRoot(ElementName = "AddressTest")]
public string GetAddressTest(string memberNbr)
{
    XNamespace defaultNamespace = XNamespace.Get("http://tempuri.org/Member.xsd");
    XElement addressInfo = new XElement("AddressDetail");
    IList<string> addressList = new List<string> { "101 state st", "201 exit st", "301 entrance st" };
    var i = 0;
    foreach (string item in addressList)
    {
        i++;
        addressInfo.SetElementValue("Address", item[i]);
    }
    return addressInfo.ToString();
}
here's the output format i want:

<?xml version="1.0" encoding="UTF-8"?>
<MemberSpansTest xmlns="http://www.w3.org/2001/XMLSchema-instance">
</MemberSpansTest>
	<MemberSpansDetail> 
		<Address>101 state st</Address> 
	</MemberSpansDetail>
	<MemberSpansDetail> 
		<Address>201 exit st</Address> 
	</MemberSpansDetail>
	<MemberSpansDetail> 
		<Address>301 entrance st</Address> 
	</MemberSpansDetail>
</MemberSpansTest>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 10 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros