SQL中的XML字段

I have a method which serializes an object, into a SQL Server XML field. I see the XML in SQL server in Managmenet Studio, and now I need to display that in a HTML page.

I use an AJax function calling into a WebMethod, which calls a stored procedure as follows:

using (conn){
    using (SqlCommand cmd = new SqlCommand()){

        conn.Open();

        cmd.CommandText = "GetMessage_Sel";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@messageId", SqlDbType.VarChar, 50).Value = str;
        cmd.Connection = conn;

        try{
            rdr = cmd.ExecuteReader();

            if (rdr.HasRows){

                while (rdr.Read()){
                    returnValue1 = rdr.GetString(0);
                    returnValue2 = rdr.GetString(1);
                }      
            }

            else{
                Console.WriteLine("No rows found.");
            }  
            rdr.Close();
        }

        catch (Exception err){
            // handle the error
            //messageInsert = false;
        }

        finally{ 
            conn.Close(); 
        }
    }
}

return new string[] {returnValue1,returnValue2};

the ajax is therefore set up as follows:

$('.view-details').click(function (e) {
    e.preventDefault();

    $('#ticket-id').text("Ticket id: " + $(this).closest('tr').children().eq(1).html());

    $.ajax({
        type: "POST",

        url: "Default.aspx/PopulatePopUp",

        cache: false,
        data: "{'arg':'" + $(this).closest('tr').children().eq(1).html() + "'}",
        contentType: "application/json; charset=utf-8",

        dataType: "json",

        success: function (msg)
        {
            $("#CompleteMessage").text(msg.d[0]);
            $("#lblaka").text(msg.d[1]);
        }

    });
}

so #lblaka displays the entire XML message, but i need to break this down into a more readable manner. So eithe in my WebMethod or the Ajax function, how do i iterate through the rdr.GetString(1), so something like this

foreach (var item in rdr.GetString(1))  {
    string 1 = xml node value 1 ..... etc
}

EDIT:

Here is an example of the XML being stored.

<Person xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <AKA>
        <string>Name 1</string>
        <string>Name 2</string>
    </AKA>
    <Countries>
        <string>USA</string>
        <string>UK</string>
    </Countries>
    <Names>
        <string>Name 1</string>
        <string>Name 2</string>
    </Names>
    <Gender>Male</Gender>
</Person>

If its pure XLM in your SQL string you could load the string into and XDocument like so and query using linq to get your list to loop over.

XDocument xDoc = XDocument.Parse(rdr.GetString(1));
var query = xDoc.Descendants("AKA").Elements("string").ToList();

//If you want to add them to an Array
string[] array = new string[query.Count() -1];
int i = 0
// this will add the values Name 1 and Name 2 to an array
foreach (var element in query)
{
     array[i] = element.Value;
     i++;
}

Here is how you could do it with jQuery:

declare this function:

function GetNestedElements(aThis, name) {
 $(aThis).find(name).each(function(index){            
        $("#lblaka").append('<span>'+ name +' : ');
        $(this).find('string').each(function(index){            
             $("#lblaka").append($(this));
            });
        $("#lblaka").append('</span><br/>');
    });    
}

Use this in your success call:

var xml = $.parseXML(msg),
$xml = $( xml );
$xml.find('Person').each(function(index){             
    GetNestedElements(this, 'AKA');
    GetNestedElements(this, 'Countries');
    GetNestedElements(this, 'Names');

    var gender = $(this).find('Gender').text();                 
            $("#lblaka").append('<span>Gender : ' + gender + '</span><br/>');

        });

Please see this jsFiddle for a working version (select 'Show Person' to view it):

http://jsfiddle.net/MZ5Xs/2/