给一段代码你看看:
System.Xml.XmlDocument parse=new XmlDocument();
try
{
parse.Load(XmlPath);
System.Xml.XmlElement root=parse.DocumentElement;
XmlNode xn=root.SelectSingleNode("//provider");
str="Provider=";
str=str+xn.InnerText;
xn=root.SelectSingleNode("//datasource");
str=str+"; Data Source=";
str=str+xn.InnerText;
XmlNode ini=root.SelectSingleNode("//initial");
XmlNode uid=root.SelectSingleNode("//uid");
XmlNode pwd=root.SelectSingleNode("//pwd");
XmlNode timeout=root.SelectSingleNode("//timeout");
if ((ini!=null)&&(ini.InnerText!="")) str=str+";"+"initial catalog="+ini.InnerText;
str=str+";"+"User ID="+uid.InnerText+" ; Password="+pwd.InnerText;
if ((ini!=null)&&(timeout.InnerText!="")) str=str+"; Connection Timeout="+timeout.InnerText;
}

解决方案 »

  1.   

    xmlTextReader xmlReader=new XmlTextReaer(xml路径);
    while(xmlreaer.reader())
    {
       switch(xmlreader.nodetype)
    {
     case xmlnodeType.Element:
        xmlReader.Name;
        break;
    case xmlNodeType.Text
        xmlredder.value
        break;
    }
    }
      

  2.   

    例子: XML内容 
    <?xml version="1.0" encoding="gb2312"?>
    <Config>
      <Database>
        <Server>192.168.100.1</Server>
        <Database>zhMis</Database>
        <Uid>sa</Uid>
        <Pwd>60FD7DD82EA95B91</Pwd>
      </Database>
    </Config>
    using System.Xml;XmlDocument cmicXmlDoc=new XmlDocument();
    cmicXmlDoc.Load(strFile);
    XmlNode cmicNode;
    cmicNode=cmicXmlDoc.SelectSingleNode(@"Config/Database/Server");
    string tempServer=cmicNode.InnerText;cmicNode=cmicXmlDoc.SelectSingleNode(@"Config/Database/Database");
    tempDatabase=cmicNode.InnerText; cmicNode=cmicXmlDoc.SelectSingleNode(@"Config/Database/Uid");
    tempUid=cmicNode.InnerText; cmicNode=cmicXmlDoc.SelectSingleNode(@"Config/Database/Pwd");
    tempPwd=cmicNode.InnerText;