1、包含xml命名空间。
2、写xml函数实例:
private void addItemToXmlMylib()
{
String strXml = downLoading_.kuMid_.strAppPath_ + "//data//mylib//mylib.xml";
XmlDocument doc = new XmlDocument();
if (!File.Exists(strXml))
{
XmlNode root = doc.CreateElement("alllist");
doc.AppendChild(root);
doc.Save(strXml);
}
doc.Load(strXml);
XmlNode element = doc.FirstChild;
XmlNode node = doc.CreateElement("item");
element.AppendChild(node);
//caption
XmlNode nodeCaption = doc.CreateElement("caption");
nodeCaption.InnerText = strCaption_;
node.AppendChild(nodeCaption);
//from
XmlNode nodeFrom = doc.CreateElement("from");
nodeFrom.InnerText = "ku6.com";
node.AppendChild(nodeFrom);
//duration
XmlNode nodeDuration = doc.CreateElement("duration");
nodeDuration.InnerText = "0";
node.AppendChild(nodeDuration);
//menu
XmlNode nodeMenu = doc.CreateElement("menu");
nodeMenu.InnerText = "";
node.AppendChild(nodeMenu);
//moviefile
XmlNode nodeMovie = doc.CreateElement("moviefile");
nodeMovie.InnerText = strFileName_;
node.AppendChild(nodeMovie);
//image
XmlNode nodeImage = doc.CreateElement("image");
nodeImage.InnerText = strPic_;
node.AppendChild(nodeImage);
//read
XmlNode nodeRead = doc.CreateElement("read");
nodeRead.InnerText = "1";
node.AppendChild(nodeRead);
doc.Save(strXml);
}
};