´¦ÀíXMLƬ¶Î
±êÇ©£ºÊý¾Ý·ÃÎÊ ADO.NET
´¦ÀíXMLƬ¶Î ´¦ÀíÆ¬¶Îʱ£¬Ö»ÊǰÑXElement£¨¶ø²»ÊÇXDocument£©µ±×÷¶¥¼¶XML¶ÔÏó¡£
Ƭ¶ÎµÄΨһÏÞÖÆÊÇ£¬²»ÄÜÌí¼Ó±È½Ï½ÚµãÀàÐÍ£¬ÀýÈ磺XComment£¬XDeclaration£¬XProcessingInstruction(ÓÃÓÚXML´¦ÀíÖ¸Áî)¡£
Àý£º XElement xcust = new XElement( new XElement(......)..........);
×¢Ò⣺ÕâÁ½¸öÀ඼ʵÏÖÁËLoad()ºÍSave()·½·¨£¬XElemnt ºÍ XDocument¼Ì³Ð×ÔLINQ to XMLÀàµÄXContainer£» ÔÚXDocumentÉÏÖ´ÐеĴó¶àÊý²Ù×÷£¬ÔÚXElementÉÏÒ²¿ÉÒÔÖ´ÐС£
Ïà¹ØÎĵµ£º
IsolatedStorageFile£º°üº¬ÎļþºÍÊý¾ÝµÄ¶ÀÁ¢´æ´¢Çø
datasetÊý¾Ý´æ´¢µ½±¾µØxmlÎĵµ£¬´úÂë´¦ÀíÈçÏÂ
public static void WriteDataToXML(DataSet dataset, string dataname)
{
try
{
IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForAssembly(); / ......
Definition comparer class,
class ItemComparer : IEqualityComparer<XElement>
{
public bool Equals(XElement x, XElement y)
{
return x.Attribute("Name").Value == x.Attribute("Name").Value;
}
public int GetHashCode(XElement obj)
......
<?
XML DOM¶ÁÈ¡½ÚµãÐÅÏ¢Óöµ½ÎÊÌâ×ܽ᣺
1:NodeList: ʹÓýڵãµÄchildNodesÊôÐÔ»òÕßdocument¶ÔÏóµÄgetElementsByTagName()·½·¨£¬¾Í»á·µ»ØÒ»¸ö°üº¬½ÚµãÁбíµÄNodeList
2: ÔÚ XML DOM ÖУ¬½ÚµãµÄ¹ØÏµ±»¶¨ÒåΪ½ÚµãµÄÊôÐÔ£º
· parentNode
· childNodes
· ......
import java.io.File;
import java.io.FileNotFoundException;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class ResolveXmlFile {
public void resolverXml() throws DocumentException, FileNotFoundExcept ......
×î³£¼ûµÄXMLÊý¾ÝÀàÐÍÓУºElement, Attribute£¬Comment, Text.
Element, Ö¸ÐÎÈç<Name>Tom<Name>µÄ½Úµã¡£Ëü¿ÉÒÔ°üÀ¨£ºElement, Text, Comment, ProcessingInstruction, CDATA, and EntityReference.
Attribute, Ö¸ÔÚ<Employee >ÖеĴ ......