C#дXMLµÄ¼òµ¥Àý×Ó
Õâ¸öÀý×ÓÒª°Ñbookstore.xmlÎļþÔö¼ÓÒ»Ìõbook¼Ç¼
1 bookstore.xml
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="love" ISBN="1234123">
<title>who am i </title>
<author>who</author>
<price>999</price>
</book>
</bookstore>
2 bookstore.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace toxml
{
public class ToXml
{
public static void Main(string[] args)
{
//ʵÀý»¯Ò»¸öXmlDocument¶ÔÏó
XmlDocument xmlDoc = new XmlDocument();
//ʵÀý¶ÔÏó¶ÁȡҪдÈëµÄXMLÎļþ
xmlDoc.Load("bookstore.xml");
//²éÕÒ<bookstore>
XmlNode root = xmlDoc.SelectSingleNode("bookstore");
//´´½¨Ò»¸ö<book>½Úµã
XmlElement xe1 = xmlDoc.CreateElement("book");
//ÉèÖøýڵãgenreÊôÐÔ
xe1.SetAttribute("leixing", "music");
//ÉèÖøýڵãISBNÊôÐÔ
xe1.SetAttribute("ISBN", "56756");
 
Ïà¹ØÎĵµ£º
1¡¢mian.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" creationComplete="HTTPSrv.send();" width="242" height="442">
<mx:Script>
<!--[CDATA[
import mx.rpc.events.ResultEv ......
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Xml;
using System.Data;
public class Cls_XML
{
#region ´´½¨xmlÎļþ
/// <summary>
/// ´´½¨xmlÎļþ
/// ......
1.Ìí¼ÓÃüÃû¿Õ¼äÒýÓÃ
using System.Xml;
2.н¨xmlʵÀý
public XmlDocument objXmlDoc = new XmlDocument();
3.¼ÓÔØXmlÎĵµ
string path=Server.Mappath("demo.xml");//µÃµ½ÎĵµÂ·¾¶
objXmlDoc.Load(path);//¼ÓÔØÎĵµ
4.²éÕÒÒª½øÐвÙ×÷µÄ½áµã
objXmlDoc.SelectNodes(xpath);//µÃµ½½áµã¼¯ºÏ
objXmlDoc.SelectSingleN ......
Ò»£ºÉè¼Æģʽ²¿·Ö
״̬ģʽ£¨state£©
״̬ģʽÀàËÆÓÚÒ»ÖÖ¼òµ¥µÄ¹¤×÷Á÷£¬ÓÃÀ´°Ñ´óÁ¿µÄÅжϷÖÖ§½øÐвð·Ö£¬¸øÿһÖÖÅжÏÔö¼ÓÒ»¸ö״̬£¬Èç¹û²»Âú×ã¸ÃÅжϿÉÒÔ½øÐÐ״̬ת»»£¬ÖªµÀÓöµ½Âú×ãÌõ¼þΪֹ
ÕâÑù×öµÄºÃ´¦¾ÍÊÇ£¬µ±ÐèÒªÔö¼ÓÅжϵÄʱºò£¬²»ÐèÒª¸Ä±äÒѾ´æÔڵĴúÂë¡£Ö»ÐèÒªÔö¼ÓÅжϵÄÀ࣬ÔʼÅжÏÀàÖÐÔö¼ÓеÄ״̬ת»»¡£
Ê ......