Xml°ïÖúÎļþ
using System.Xml;
//³õʼ»¯Ò»¸öxmlʵÀý
XmlDocument xml=new XmlDocument();
//µ¼ÈëÖ¸¶¨xmlÎļþ
xml.Load(path);
xml.Load(HttpContext.Current.Server.MapPath("~/file/bookstore.xml"));
//Ö¸¶¨Ò»¸ö½Úµã
XmlNode root=xml.SelectSingleNode("/root");
//»ñÈ¡½ÚµãÏÂËùÓÐÖ±½Ó×Ó½Úµã
XmlNodeList childlist=root.ChildNodes;
//ÅжϸýڵãÏÂÊÇ·ñÓÐ×Ó½Úµã
root.HasChildNodes;
//»ñȡͬÃûͬ¼¶½Úµã¼¯ºÏ
XmlNodeList nodelist=xml.SelectNodes("/Root/News");
//Éú³ÉÒ»¸öнڵã
XmlElement node=xml.CreateElement("News");
//½«½Úµã¼Óµ½Ö¸¶¨½ÚµãÏ£¬×÷ΪÆä×Ó½Úµã
root.AppendChild(node);
//½«½Úµã¼Óµ½Ö¸¶¨½ÚµãÏÂij¸ö×Ó½ÚµãÇ°
root.InsertBefore(node,root.ChildeNodes[i]);
//Ϊָ¶¨½ÚµãµÄн¨ÊôÐÔ²¢¸³Öµ
node.SetAttribute("id","11111");
//Ϊָ¶¨½ÚµãÌí¼Ó×Ó½Úµã
root.AppendChild(node);
//»ñÈ¡Ö¸¶¨½ÚµãµÄÖ¸¶¨ÊôÐÔÖµ
string id=node.Attributes["id"].Value;
//»ñÈ¡Ö¸¶¨½ÚµãÖеÄÎı¾
string content=node.InnerText;
//±£´æXMLÎļþ
string path=Server.MapPath("~/file/bookstore.xml");
xml.Save(path);
//or use :xml.Save(HttpContext.Current.Server.MapPath("~/file/bookstore.xml"));
¶þ¡¢¾ßÌåʵÀý
ÔÚC#.netÖÐÈçºÎ²Ù×÷XML
ÐèÒªÌí¼ÓµÄÃüÃû¿Õ¼ä£º
using System.Xml;
¶¨Ò弸¸ö¹«¹²¶ÔÏó£º
XmlDocument xmldoc ;
XmlNode xmlnode ;
XmlElement xmlelem ;
1£¬´´½¨µ½·þÎñÆ÷ͬÃûĿ¼ÏµÄxmlÎļþ£º
·½·¨Ò»£º
xmldoc = new XmlDocument ( ) ;
//¼ÓÈëXMLµÄÉùÃ÷¶ÎÂä,<?xml version="1.0" encoding="gb2312"?>
XmlDeclaration xmldecl;
xmldecl = xmldoc.CreateXmlDeclaration("1.0","gb2312",null);
xmldoc.AppendChild ( xmldecl);
//¼ÓÈëÒ»¸ö¸ùÔªËØ
xmlelem = xmldoc.CreateElement ( "" , "Employees" , "" ) ;
xmldoc.AppendChild ( xmlelem ) ;
//¼ÓÈëÁíÍâÒ»¸öÔªËØ
for(int i=1;i<3;i++)
{
XmlNode root=xmldoc.SelectSingleNode("Employees");//²éÕÒ<Employees>
XmlElement xe1=xmldoc.CreateElement("Node");//´´½¨Ò»¸ö<Node>½Úµã
xe1.SetAttribute("genre","ÀîÔÞºì");//ÉèÖøýڵãgenreÊôÐÔ
xe1.SetAttribute("ISBN","2-3631-4");//ÉèÖøýڵãISBNÊôÐÔ
XmlElement xesub1=xmldoc.CreateElement("title");
xesub1.InnerText="CS´ÓÈëÃŵ½¾«Í¨";//ÉèÖÃÎı¾½Úµ
Ïà¹ØÎĵµ£º
Ò»¡¢Îĵµ¶ÔÏóÄ£ÐÍ£¨DOM£©
¡¡¡¡DOMÊÇDocument Object Model£¨Îĵµ¶ÔÏóÄ£ÐÍ£©µÄ¼ò³Æ£¬ÊǶÔXMLÎĵµ½øÐÐÓ¦Óÿª·¢¡¢±à³ÌµÄÓ¦ÓóÌÐò½Ó¿Ú£¨API£©¡£×÷ΪW3C¹«²¼µÄÒ»ÖÖ¿çƽ̨¡¢ÓëÓïÑÔÎ޹صĽӿڹ淶£¬DOMÌṩÁËÔÚ²»Í¬»·¾³ºÍÓ¦ÓÃÖеıê×¼³ÌÐò½Ó¿Ú£¬¿ÉÒÔÓÃÈκÎÓïÑÔʵÏÖ¡£
¡¡¡¡DOM²ÉÓöÔÏóÄ£ÐͺÍһϵÁеĽӿÚÀ´ÃèÊöXMLÎĵµµÄÄÚÈݺͽ ......
´úÂëÈçÏÂ:
DECLARE
@TempTable table(UserID int , UserName nvarchar(50));
insert into
@TempTable (UserID,UserName) values (1,'a')
insert into @TempTable
(UserID,UserName) values (2,'b')
select UserID,UserName
from @TempTable FOR XML PATH
ÔËÐÐÕâ¶Î½Å±¾£¬½«Éú³ÉÈçϽá¹û£º
¸´ÖÆ´úÂë
......
ÊÇ·ñÑá¾ëÁËÓÃxmlÎļþÀ´×öMagentoµÄÒ³Ãæ²¼¾Ö£¬ÊǵĻ°À´ÊÔÊÔÏÂÃæÕâÖÖ·½Ê½£¬°Ñ²¼¾Ö´úÂëдµ½controller ÀïÃæ
public function mycoolAction()
{
/* ... Some code ...*/
$update = $this->getLayout()->getUpdate();
/* ... Some code ...*/
$this->addActionLayoutHandles();
/* ... Some code ...*/
......
Ç°ÃæÎÄÕÂÖÐÌáµ½ xml½ÚµãµÄɾ³ý
“ɾ³ý <book genre="fantasy" ISBN="2-3631-4">½ÚµãµÄgenreÊôÐÔ£¬É¾³ý <book genre="updateÌÕά¼Ñ" ISBN="2-3631-4">½Úµã¡£”
´úÂ룺
XmlNodeList xnl=xmlDoc.SelectSingleNode("bookstore").ChildNodes;
foreach(XmlNode&nbs ......
Loading XML data using ActionScript 3.0
By Blue_Chi | Flash CS3 | ActionScript 3.0 | Beginner
Using XML is one of the best ways for structuring external content in a logical format that is easy to understand, process, and update. This tutorial will teach you the basics on how to load and process X ......