Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

c#xmlµÄÔöɾ¸Ä²é


ÒÑÖªÓÐÒ»¸ö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>  
      </book>  
  </bookstore>  
     
  1¡¢Íù<bookstore>½ÚµãÖвåÈëÒ»¸ö<book>½Úµã£º  
        XmlDocument   xmlDoc=new   XmlDocument();  
        xmlDoc.Load("bookstore.xml");  
        XmlNode   root=xmlDoc.SelectSingleNode("bookstore");//²éÕÒ<bookstore>  
        XmlElement   xe1=xmlDoc.CreateElement("book");//´´½¨Ò»¸ö<book>½Úµã  
        xe1.SetAttribute("genre","ÀîÔÞºì");//ÉèÖøýڵãgenreÊôÐÔ  
        xe1.SetAttribute("ISBN","2-3631-4");//ÉèÖøýڵãISBNÊôÐÔ  
     
        XmlElement   xesub1=xmlDoc.CreateElement("title");  
        xesub1.InnerText="CS´ÓÈëÃŵ½¾«Í¨";//ÉèÖÃÎı¾½Úµã  
        xe1.AppendChild(xesub1);//Ìí¼Óµ½<book>½ÚµãÖÐ  
        XmlElement   xesub2=xmlDoc.CreateElement("author");  
        xesub2.InnerText="ºò½Ý";  
        xe1.AppendChild(xesub2);  
        XmlElement   xesub3=xmlDoc.CreateElement("price");  
        xesub3.InnerText="58.3";  
        xe1.AppendChild(xesub


Ïà¹ØÎĵµ£º

StringºÍXmlÖ®¼äµÄת»»¡¢StringתInputStream

ͨ³£ÔÚ²Ù×÷xmlµÄʱºò£¬¶¼ÊÇͨ¹ýinputstream£¨ºÜ¶àÇé¿öÏÂÊÇFileInputStream£©À´¶ÁÈëxml²¢×ªÎªdomµÄ£¬ºÜ¶àÈË»áÓöµ½ÕâÖÖÇé¿öÊý¾Ý²»ÊÇ´ÓÎļþ¶ÁÈëµÄ¶øÊÇ´ÓStringÖÐÈ¡µÃµÄ
ÓÚÊÇ»áʹÓÃ
InputStream in = new ByteArrayInputStream (str.getBytes());À´È¡µÃinputstream £¬µ«ÊÇÕâÖÖInputStreamÖÐÊý¾Ý±»×ª³ÉÁËbyteÊý×飬ËùÒÔתdom ......

´¦ÀíXMLµÄз½Ê½——LINQ to XML

ºÎνLINQ? LINQ¼´.NET ÓïÑÔ¼¯³É²éѯ(.NET Language-Integrated Query (LINQ) Framework),Ϊ.NET¼Ü¹¹ÖеÄÖØÒª×é³É²¿·Ö¡£LINQϵÁм¼ÊõÌṩÁËÕë¶Ô¶ÔÏó(LINQ)¡¢¹ØϵÊý¾Ý¿â(LINQ to SQL)ºÍXML(LINQ to XML)µÄÒ»ÖÂÐÔ²éѯÌåÑé¡£ ʲôÊÇLINQ to XML? LINQ to XML ʹÓÃ×îеÄ.NET FrameworkÓïÑÔ¹¦ÄÜ£¬Ï൱ÓÚ¸üкÍÖØÐÂÉè¼ÆµÄÎĵµ¶ ......

ʵÀýÆÊÎöxmlÓ¦Óã¨1£©

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
 //µ¼ÈëʹÓÃxmlÓ¦ÓÃËùÐèµ ......

XML ¼Ü¹¹½éÉÜ

XML ¼Ü¹¹½éÉÜ:
XML ¼Ü¹¹ÊÇÓÃÓÚ¶¨ÒåºÍÑéÖ¤ XML Êý¾ÝµÄÄÚÈݺͽṹµÄÎĵµ£¬¾ÍÏñÊý¾Ý¿â¼Ü¹¹¶¨ÒåºÍÑéÖ¤×é³ÉÊý¾Ý¿âµÄ±í¡¢ÁкÍÊý¾ÝÀàÐÍÒ»Ñù¡£
XML ¼Ü¹¹Í¨¹ý XML ¼Ü¹¹¶¨Òå (XSD) ÓïÑÔ¶¨ÒåºÍÃèÊöijЩ XML Êý¾ÝÀàÐÍ¡£XML ¼Ü¹¹ÔªËØ£¨ÔªËØ¡¢ÊôÐÔ¡¢ÀàÐͺÍ×飩ÓÃÓÚ¶¨ÒåijЩ XML Êý¾ÝÀàÐ͵ÄÓÐЧ½á¹¹¡¢ÓÐЧÊý¾ÝÄÚÈݺ͹Øϵ¡£XML ¼Ü¹¹»¹¿ÉΪ ......

Xml¶Áд

<?xml version="1.0" encoding="utf-8"?> 
<userdata createuser="false">
  <dataconnection>
    <server>xml test</server>
    <uid>sa</uid>
    <pwd>sa</pwd>
  </dataconnection> ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ