private void Write()
{
XmlDocument doc = new XmlDocument();
doc.AppendChild(doc.CreateXmlDeclaration("1.0", "UTF-8", null));
XmlElement root = doc.CreateElement("config");
for (int i = 0; i < 2; i++)
{
XmlElement two = doc.CreateElement("twonode");
two.InnerText = i.ToString();
two.SetAttribute("TYPE","xiaoshuo");
for (int j = 0; j < 2; j++)
{
XmlElement day = doc.CreateElement("day");
day.InnerText = i.ToString();
day.SetAttribute("TYPE", "xiaoshuo");
two.AppendChild(day);
}
root.AppendChild(two);
}
doc.Save("");
}
private void read()
{
XmlDocument doc = new XmlDocument();
doc.Load("er.xml");
XmlNode rootnode = doc.SelectSingleNode("dd");
XmlNodeList twoList = rootnode.SelectNodes("twonode");
foreach (XmlNode two in twoList)
{
XmlNodeList startList = two.SelectNodes("daystart");
foreach (XmlNode day in startList)
{
string content = day.InnerText;
// XmlElement eleday = day as XmlElement;可以省去,简化
string type = (day as XmlElement).GetAttribute("Type");
}
}