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

´úÂëÐÞ¸ÄXML±êÇ©

Ò»¡¢ÎÊÌâÃèÊö£º
Ò»¸öXMLÎĵµ£¬ÃûΪOriginXml.xml£¬Ê¾ÀýÊý¾ÝÈçÏ£º
 <?xml version="1.0" encoding="utf-8"?>
<Class>
<student id="2001001">
<name>ÕÅÈý</name>
<age>18</age>
<scores>
<ÓïÎÄ>79</ÓïÎÄ>
<Êýѧ>90</Êýѧ>
</scores>
</student>
<student id="2001002">
<name>ÀîËÄ</name>
<age>20</age>
<scores>
<ÓïÎÄ>88</ÓïÎÄ>
<Êýѧ>64</Êýѧ>
</scores>
</student>
</Class>
  
 
ÏÖÐèÒªÔÚÁ½¸öÎĵµ¼äת»»£¬ÐèÒª½«±êÇ©studentÐÞ¸ÄΪ<pStudent>,ÆäÓà×ÓÔªËر£³Ö²»±ä£¬Ð޸ĵÄÎĵµ´æÈëModifyXML.xmlÖС£
 
¶þ¡¢ÎÊÌâ·ÖÎö
    Ð޸ıêÇ©Ãû³Æ£¬ÊµÖÊÉÏÊǶÔÔªËØÖØÃüÃû¡£ÔªËØÔÚDTD»òXML SchemaÖж¨Ò壬Òò´ËÐÞ¸ÄÔªËØÃû³Æ±ØÐëÐÞ¸ÄDTD»òXML Schema£¬·ñÔòÐ޸ĺóµÄÎĵµ²»ÊÇ“Êý¾ÝÓÐЧ”µÄ¡£Èç¹ûûÓÐDTD»òXML SchemaµÄÇé¿öÏ£¬ÔòÒª¼òµ¥Ò»Ð©¡£¿ÉÒÔÖ±½ÓÐ޸ĻòÔÚDOMÄ£ÐÍÖÐÐ޸ġ£
    Ö±½ÓÐ޸ľÍÊǽ«XMLÎĵµÊÓΪÆÕͨµÄÎı¾Á÷£¬¶ÁÈëºóÖ±½Ó½øÐÐ×Ö·û´®Ìæ»»²Ù×÷¡£µ«ÊÇ£¬Èç¹ûÄÚǶDTD»òXML Schema¶¨Ò壬Ôò²»¿ÉÖ±½ÓÌæ»»¡£Ìæ»»¹ý³ÌÖУ¬Èç¹ûÔªËؾßÓÐÏÞ¶¨Ãû³Æ£¬Ôò×îºÃʹÓÃÕýÔò±í´ïʽ²éÕÒ¡¢Ìæ»»¡£
    DOMÄ£ÐÍÐÞ¸ÄÊÇͨ¹ý¶ÁÈëXMLÎĵµºó£¬¸ù¾ÝÒªÇó½âÎö²¢Öع¹½Úµã¡£Ïà¶ÔÓÚSAXÀ´Ëµ£¬DOMÊǿɱ༭µÄ£¬µ«²¢²»Òâζ׎ڵãÃû³Æ¿É¸ü¸Ä¡£Ò»µ©´´½¨½Úµãºó£¬Ãû³Æ¼´²»¿ÉÐ޸ġ£ËùÒÔÖ»ÄÜ´´½¨Ð½ڵ㣬½«Ô­Óнڵ㸴ÖƹýÈ¥²¢×÷±ØÒªµÄÐ޸ģ¬×îºóÌæ»»½Úµã¡£
Èý¡¢½â¾öÎÊÌâ
    ÒÔÏÂÃèÊöÁ˼ٶ¨Ã»ÓÐDTDºÍXML SchemaµÄÇé¿öÏ£¬ÐÞ¸ÄÔªËرêÇ©µÄÁ½ÖÖ·½·¨ 
£¨Ò»£©Ö±½ÓÐÞ¸Ä
´úÂëÈçÏ£º
StreamReader sr = new StreamReader("OriginXml.xml");
string str = sr.ReadToEnd();
sr.Close();
str=str.Replace("student", "pStudent");
//Èç¹ûÓÐÏÞ¶¨Ãû³Æ£¬×îºÃÓÃÕýÔò±í´ïʽ²éѯ¡¢Ìæ»»
StreamWriter sw = new StreamWriter("ModifyXml.xml");
sw.Write(str);
sw.Flush(); sw.Close();


£¨¶þ£©Ê¹ÓÃDOMÄ£ÐÍÐÞ¸Ä
XmlDocument doc = new XmlDocument();
doc.Load("OriginXml.xml");
XmlElement oldEleme


Ïà¹ØÎĵµ£º

J2MEÖÐKXMLÓëNanoXML½âÎöXML×ܽá

ÔÚJ2MEÌåϵÖУ¬¶ÔxmlµÄ½âÎöÓбȽÏÓÐÃûµÄµÚÈý·½½âÎöAPI£¬·Ö±ðΪKXMLºÍNanoXML£¬ËûÃǶ¼ÌṩÁ˶ԽâÎöxmlµÄÖ§³Ö¡£KXMLÔÚ½âÎöXML¹ý³ÌÖлá¶ÔÎļþÄÚÈÝÒ»²ãÒ»²ã½øÐнâÎö£¬Òò´Ë³ÉΪÔöÁ¿Ê½½âÎöÆ÷£¬±È½ÏÊʺϴóÎļþµÄ½âÎö¡£¶øNanoXMLÊÇÒ»´ÎÐÔ½âÎöÆ÷£¬ÔÚÒ»´Îʱ¼äÀï¾Í°ÑÕû¸öxmlÎĵµ½âÎöÍ꣬Òò´Ë²»ÊʺϴóÎļþµÄ½âÎö£¬»áÔì³ÉÄÚ´æ²»×ãµÄÏÖÏó¡ ......

C#.Net²Ù×÷XMLÎļþµÄÊý¾Ý

XMLÎļþ×÷ΪÊý¾ÝÊý¾Ý´æ´¢½éÖʵÄÒ»ÖÖ£¬ºÃ´¦ÔÚÓÚ£ºÈκεÄϵͳ¾ù¿ÉÒÔ½âÎöËü¡£
XMLÈ«³Æ£ºExtensible Markup Language£¨À©Õ¹±ê¼ÇÓïÑÔ£©Ê¹ÓÃÎĵµÀàÐͶ¨Ò壨DTD£©»òÕßģʽ£¨Schema£©À´ÃèÊöÊý¾ÝµÄ¡£¿É¹©ÈËÔĶÁ£¬¶øÇÒ»¹»ùÓÚÒ»ÖÖ¹«¹²µÄ¿ª·¢±ê×¼¡£
×î½üÓÉÓÚ¿ª·¢µÄÐèÒª£¬Ò²ÊÇÑо¿ÒÔÏÂXMLµÄ²Ù×÷£¬±¾ÆªÈÕÖ¾Ö÷Òª×ܽáC#.NETÖÐÊÇÈçºÎ²Ù×÷XM ......

ÔÚVisual C#ÖÐʹÓÃXMLÖ¸ÄÏÖ®¶ÁÈ¡XML

ÎÒÃǽñÌìÀ´½²Ò»Ï¸ÃÌåϵ½á¹¹ÖеÄXmlTextReaderÀ࣬¸ÃÀàÌṩ¶ÔXmlÎļþ½øÐжÁÈ¡µÄ¹¦ÄÜ£¬Ëü¿ÉÒÔÑéÖ¤ÎĵµÊÇ·ñ¸ñʽÁ¼ºÃ£¬Èç¹û²»ÊǸñʽÁ¼ºÃµÄXmlÎĵµ£¬¸ÃÀàÔÚ¶ÁÈ¡¹ý³ÌÖн«»áÅ׳öXmlExceptionÒì³££¬¿ÉʹÓøÃÀàÌṩµÄһЩ·½·¨¶ÔÎĵµ½Úµã½øÐжÁÈ¡£¬É¸Ñ¡µÈ²Ù×÷ÒÔ¼°µÃµ½½ÚµãµÄÃû³ÆºÍÖµ£¬ÇëÀμǣºXmlTextReaderÊÇ»ùÓÚÁ÷Ä£Ð͵ÄʵÏÖ£¬´ò¸ö ......

ÓÃjdom¶ÔxmlÎļþµÄ¶ÁÈ¡

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.xpath.XPath;
public class XMLReader {
 priv ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ