日期:2014-05-19  浏览次数:20640 次

求一XML读法
<?xml   version= "1.0 "   encoding= "utf-8 "   ?>
<root>

    <message   id= "1 ">
        <title> title1 </title>
        <body> body1 </body>
    </message>

    <message   id= "2 ">
        <title> title2 </title>
        <body> body2 </body>
    </message>

</root>

如何读取不同MessageID的title以及body   ?

------解决方案--------------------
#region GetXml try to do .....
public ArrayList GetXml(string nodes, string strAttribute, string name)
{
ArrayList strResult = new ArrayList();
int i = 0;
XmlDocument doc = new XmlDocument();
doc.Load(this.filePath);
XmlNodeList list = doc.SelectNodes(nodes);
foreach(XmlNode l in list)
{
XmlElement xe = (XmlElement)l;
XmlNodeList list1 = xe.ChildNodes;
foreach(XmlNode l1 in list1)
{
if(xe.HasAttribute(name))
{
XmlElement xe1 = (XmlElement)l1;
if(xe1.Name == name) strResult.Add(xe1.InnerText);
}
}
i++;
}
return strResult;
}
#endregion
------解决方案--------------------
DataSet ds = new DataSet();
ds.ReadXml(this.Server.MapPath( "XMLFile1.xml "));


this.DataGrid1.DataSource = ds.Tables[ "message "].DefaultView;
this.DataGrid1.DataBind();
------解决方案--------------------
xmlNode CurrentNode=Root.SelectNodes( "message[@ID= ' "+数值+ " '] ")
------解决方案--------------------
XmlDocument xDoc = new XmlDocument();
xDoc.Load(Server.MapPath( "Xml.xml "));

XmlNodeList xnl = xDoc.SelectNodes( "//message[@id= '1 '] ");//选id=1的节点
foreach(XmlNode xn in xnl)
{
Response.Write(xn.ChildNode.Itme(0).InnerText+ "; "+xn.ChildNode.Item(1).InnerText);
}