ASP.Net - Read SQL For xml raw in .Net

摘要:.Net - How should we read SQL For xml raw in .Net

 上篇文章說到,我們用SQL的Xml for raw ,那麼在讀取的時候該如何讀取,上網爬文後自己寫了一個簡單

Function分享給需要的人。

 

In last article. We use SQL Xml for raw. However how should we read it type of value. I take a look in MSND n

write a simple function to share.

 

Target

 

Solution

public String SQLXMLTransfer()

    {       

        //sXML  read from SQL xml for raw,I use a string to try it.

        string sXML = @"<row Target=""My Family"" Do=""Really"" Finally=""Happy"" />";  

        string sTarget, sDo, sFinally;

        string sShow = "<ul>";

        XmlDocument xD = new XmlDocument();

        xD.LoadXml("<html>" + sXML + "</html>");

        XmlNode xNode = xD.DocumentElement.FirstChild;

        int iNodeCount = xD.DocumentElement.ChildNodes.Count;

        for (int i = 0; i < iNodeCount; i++)

        {

            sTarget = xNode.Attributes["Target"].InnerText;

            sDo = xNode.Attributes["Do"].InnerText;

            sFinally = xNode.Attributes["Finally"].InnerText;

            xNode = xNode.NextSibling;    //Next node

            sShow = sShow + "<li>" + sDo + "</li><li>" + sTarget + "</li><li>" + sFinally + "</li>";

        }

        sShow = sShow + "<ul>";

        return sShow;

    }

 

Result

You will see this on your web page.