XML Ôö¡¢É¾¡¢¸Ä¡¢Çóƽ¾ùÊý
string file = "c:\\work.xml";
private void btnCearte_Click(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
XmlDeclaration dl = doc.CreateXmlDeclaration("1.0", "Unicode", null);
doc.AppendChild(dl);
XmlElement @class = doc.CreateElement("class");
doc.AppendChild(@class);
doc.Save(file);
}
private void btnInsert_Click(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
doc.Load(file);
XmlElement student = doc.CreateElement("student");
student.SetAttribute("age", "20");
XmlElement name = doc.CreateElement("name");
name.InnerText = "ͯСϼ";
XmlElement sex = doc.CreateElement("sex");
sex.InnerText = "famale";
student.AppendChild(name);
student.AppendChil
Ïà¹ØÎĵµ£º
Õª×Ô--http://www.moandroid.com/?p=821
Android¶ÁдXML£¨ÖУ©——SAX
By: º£ÊÐò×Â¥ | In: Android¿ª·¢
22 ¾Å 2009
ÔÚAndroid¶ÁдXML£¨ÉÏ£©——package˵Ã÷ÖУ¬Ïêϸ½éÉÜÁËʹÓà DOM·½·¨¶ÁÈ¡XMLÎĵµ£¬ÓÉÓÚʹÓÃDOM·½·¨ÐèÒª½«Õû¸öXMLÎĵµ¼ÓÔØÄÚ´æÖУ¬¶Ôϵͳ×ÊÔ´Õ¼ÓñȽ϶࣬Õâ¶ÔÄÚ´æ±È½Ï½ôÕŵ ......
½âÎöxmlÎĵµµÄÀà¿âÓкܶàÖÖ£¬±È½Ï³£ÓõľÍÊÇSimpleXML£¬DOM Document£¬XMLReader£¬»ùÓÚSAXµÄxml_parseº¯Êý¡£
¸ù¾ÝxmlÎĵµ½á¹¹£¬ÒÔ¼°ÐèÇóµÄ²»Í¬£¬ÒªÑ¡ÔñºÃ¶ÔÓ¦µÄÀà¿â¡£
½âÎöСµÄÎĵµµÄ»°£¬Ê¹ÓÃSimpleXML±È½ÏºÏÊÊ£¬¼òµ¥µÄ¼¸¸öº¯Êý¾Í¿ÉÒԸ㶨¡£
Èç¹ûÎĵµ·Ç³£¾Þ´ó£¬×îºÃÊÇXMLReader´ò¿ª£¬Öмäת»»³ÉDOMÀ´½âÎö£¬¸Ð¾õDOMÓëXPat ......
ÒÑÖªÓÐÒ»¸öXMLÎļþ£¨bookstore.xml£©ÈçÏ£º
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price> ......
¶ÔXmlµÄ½Úµã½øÐмòµ¥²éѯµÄʱºò£¬³£ÓõĿÉÒÔʹÓÃÈçÏ·½·¨£º
(1) XmlNode node = doc.selectSingleNode("//AllNode/Node[@ID = ’aaa’]");
ÔÚÕû¸öXmlÖвéÕÒAllNode½ÚµãϵĽڵãÃûΪNodeµÄ½Úµã£¬¸Ã×Ó½ÚµãµÄIDÊôÐÔֵΪaaa
(2)XmlNode node = doc.selectSingleNode("//AllNode /*[@ID = ’aaa& ......