²éѯXMLÎĵµ
±êÇ©£ºÊý¾Ý·ÃÎÊ ADO.NET
²éѯXMLÎĵµ LINQ to XMLÀàÌṩÊôÐԺͷ½·¨£¬·µ»Ø¿É²éѯµÄÀàµÄ¶ÔÏ󼯺ϡ£
½«XML¶ÔÏó×÷ΪLINQ²éѯ¶ÔÏó£º
.......
XDocument customers = XDocument.Load(xmlFileName);
var queryResult = from c in customers.Elements() select c.Name;
ʹÓòéѯ³ÉÔ±
1£©Element()£º·µ»ØÎĵµ »ò Ƭ¶ÎÖеĵÚÒ»¸öÔªËØ¡£ÎĵµµÄ»°¾Í·µ»Ø¸ùÔªËØ£» 2£©Descendants()£º·µ»ØÎĵµ »ò Ƭ¶ÎÖеÄËùÓÐ×ÓÔªËØ£¨ËùÓм¶±ð£©£» Àý£ºqueryResults = from c in customers.Descendants() select c.Name; foreach (var item in queryResults.Distinct()) //ɸѡ³ö²»Í¬µÄÔªËØ
Descendants(string)ÖØÔØ£º queryResults = from c in customers.Desendants("customer") select c; //²éѯָ¶¨Ãû³ÆµÄ×ÓÔªËØ£¬·µ»ØËùÓÐcustomerÔªËØ¡£
3£©Ancestors()£º·µ»Ø±ÈÔ´ÔªËØ¼¶±ð¸ßµÄÒ»×éÔªËØ£»
4£©Attribute()£º·µ»Øµ±Ç°Ñ¡ÖÐÔªËØµÄËùÓÐÊôÐÔ£»
Àý£ºqueryResults = from c in customers.Descendants("customer").Attributes() select c; //·µ»ØcustomersÖÐËùÓÐcustomerÔªËØµÄÊôÐÔÖµ
Ïà¹ØÎĵµ£º
public int createXMLFile(String filename) {
int returnValue = 0;
Document document = DocumentHelper.createDocument(); //Éú³ÉDocument£¬ÓÃÓÚ¹ÜÀíXMLÎĵµ
Element booksElement = document.addElement("books"); //Ìí¼Ó ......
XMLÎļþʵÀý£º
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource auth="Container" maxActive="20" name="sss" password="123"
type="javax.sql.DataSource" />
<Resource auth="Container" ......
ʹÓÃjavascript´´½¨Microsoft XML DOM,¾Í¿ÉÒÔÍê³ÉÕâÒ»¹¤×÷.
// ×°ÈëÊý¾Ý.
var source = new ActiveXObject("Microsoft.XMLDOM");
source.async = false
source.load("history.xml");
// ×°ÈëÑùʽ±í.
var stylesheet = new ActiveXObject("Microsoft.XMLDOM");
stylesheet.async = false
stylesheet.load( ......
×î³£¼ûµÄXMLÊý¾ÝÀàÐÍÓУºElement, Attribute£¬Comment, Text.
Element, Ö¸ÐÎÈç<Name>Tom<Name>µÄ½Úµã¡£Ëü¿ÉÒÔ°üÀ¨£ºElement, Text, Comment, ProcessingInstruction, CDATA, and EntityReference.
Attribute, Ö¸ÔÚ<Employee >ÖеĴ ......