C#读取XML

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace TEST{
    class UI
    {
        private XmlDocument doc = new XmlDocument();

        public UI(String sXML)
        {
            loadXML(sXML);
        }

        public void loadXML(String sXML)
        {
            doc.LoadXml(sXML);
        }

 

//vRow表示第几行

// vFld表示那个元素
        public String getDsValue(int vRow, String vFld)
        {
            XmlNode oRoot = doc.SelectSingleNode("ROWS");

            String vValue = "NO-VALUE";
            if (oRoot.SelectNodes("ROW").Count > 0)
            {
                XmlNode oRow = oRoot.SelectNodes("ROW").Item(vRow);
                XmlNode vCol = oRow.SelectSingleNode(vFld.ToUpper());
                if (vCol != null)
                {
                    vValue = vCol.Value;
                    vValue = vCol.InnerText;
                }
            }

            return vValue;
        }
        public int getDsRowCount()
        {
            int rowCount = 0;

            XmlNode oRoot = doc.SelectSingleNode("ROWS");

            rowCount = oRoot.SelectNodes("ROW").Count;

            return rowCount;
        }
    }
}

你可能感兴趣的:(读取xml)