xmlÔö£¬É¾£¬¸Ä£¬²é
XMLÊÇÒ»ÏîÈÈÃŵļ¼Êõ¡£ËüÖ®ËùÒÔÄܹ»ÒýÆðÈËÃǵÄÐËȤ£¬Ò»¸öÖ÷ÒªµÄÔÒòÔÚÓÚËüÊ®·ÖµÄ¼òµ¥£¬ÈËÃÇ¿ÉÒÔºÜÈÝÒ×µØÀí½âºÍʹÓÃËü¡£Ã¿Ò»¸ö³ÌÐòÔ±¶¼ÄÜÇáÒ׵ؿ´¶®Ò»¸öXMLÎļþ£¬Àí½âËü°üº¬µÄÄÚÈÝ¡£
.NETÖаüº¬Á˺ܶàÖ§³ÖXMLµÄÀ࣬ÕâЩÀàʹµÃ³ÌÐòԱʹÓÃXML±à³Ì¾ÍÈçͬÀí½âXMLÎļþÒ»Ñù¼òµ¥¡£ÔÚÕâƪÎÄÕÂÖУ¬ÎÒ½«¸ø³öÕâÑùµÄÒ»¸öÀàµÄʹÓÃʾÀý£¬Õâ¸öÀà¾ÍÊÇXmlTextWriterÀà¡£
XmlTextWriterÀàÔÊÐíÄ㽫XMLдµ½Ò»¸öÎļþÖÐÈ¥¡£Õâ¸öÀà°üº¬Á˺ܶ෽·¨ºÍÊôÐÔ£¬Ê¹ÓÃÕâЩÊôÐԺͷ½·¨¿ÉÒÔʹÄã¸üÈÝÒ׵ش¦ÀíXML¡£ÎªÁËʹÓÃÕâ¸öÀ࣬Äã±ØÐëÊ×ÏÈ´´½¨Ò»¸öеÄXmlTextWriter¶ÔÏó£¬È»ºóÄã¿ÉÒÔ½«XMLƬ¶Ï¼ÓÈëµ½Õâ¸ö¶ÔÏóÖС£Õâ¸öÀàÖаüº¬Á˲»Éٵķ½·¨ÓÃÓÚ½«¸÷ÖÖÀàÐ͵ÄXMLÔªËØÌí¼Óµ½XMLÎļþÖУ¬Ï±í¸ø³öÁËÕâЩ·½·¨µÄÃû×ÖºÍÃèÊöÇé¿ö£º
·½·¨
ÃèÊö
WriteStartDocument
Êéд°æ±¾Îª“1.0”µÄ XML ÉùÃ÷
WriteEndDocument
¹Ø±ÕÈκδò¿ªµÄÔªËØ»òÊôÐÔ
Close
¹Ø±ÕÁ÷
WriteDocType
д³ö¾ßÓÐÖ¸¶¨Ãû³ÆºÍ¿ÉÑ¡ÊôÐ﵀ DOCTYPE ÉùÃ÷
WriteStartElement
д³öÖ¸¶¨µÄ¿ªÊ¼±ê¼Ç
WriteEndElement
¹Ø±ÕÒ»¸öÔªËØ
WriteFullEndElement
¹Ø±ÕÒ»¸öÔªËØ£¬²¢ÇÒ×ÜÊÇдÈëÍêÕûµÄ½áÊø±ê¼Ç
WriteElementString
д³ö°üº¬×Ö·û´®ÖµµÄÔªËØ
WriteStartAttribute
ÊéдÊôÐÔµÄÆðʼÄÚÈÝ
WriteEndAttribute
¹Ø±ÕÉÏÒ»¸ö WriteStartAttribute µ÷ÓÃ
WriteRaw
ÊÖ¶¯ÊéдÔʼ±ê¼Ç
WriteString
Êéдһ¸ö×Ö·û´®
WriteAttributeString
³ö¾ßÓÐÖ¸¶¨ÖµµÄÊôÐÔ
WriteCData
д³ö°üº¬Ö¸¶¨Îı¾µÄ <![CDATA[...]]> ¿é
WriteComment
д³ö°üº¬Ö¸¶¨Îı¾µÄ×¢ÊÍ <!--...-->
WriteWhiteSpace
д³ö¸ø¶¨µÄ¿Õ°×
WriteProcessingInstruction
д³öÔÚÃû³ÆºÍÎı¾Ö®¼ä´øÓпոñµÄ´¦ÀíÖ¸ÁÈçÏÂËùʾ£º<?name text?>
Èç¹ûÄã¶ÔÓÚXMLÊ®·ÖÊìϤ£¬ÄÇôÄãÒ»¶¨ÄܺܺõÄÀí½âÉÏÃæµÄÕâЩ·½·¨¡£ÏÂÃæÎÒÃǽ«¸ø³öÒ»¸öÀý×Ó£¬ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃǽ«ÏÈ´´½¨Ò»¸öÎĵµ£¬Ìí¼ÓһЩԪËØ£¬È»ºó¹Ø±ÕÕâ¸öÎĵµ¡£Ìí¼ÓÁËÔªËغóÄ㻹¿ÉÒÔÌí¼Ó×ÓÔªËØ£¬ÊôÐÔºÍÆäËûÄÚÈÝ¡£ÏÂÃæµÄ´úÂë¾ÍÊÇÕâÑùµÄÒ»¸öÀý×Ó£¬Ëü´´½¨ÁËÒ»¸öÎļþÃûΪtitleµÄXMLÎļþ¡£
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
XmlTextWriter writer = new XmlTextWriter("titles.xml", null);
//дÈë¸ùÔªËØ
writer.WriteStartElement("ite
Ïà¹ØÎĵµ£º
¶ÔÓÚСÐÍÊý¾Ý´æ´¢ºÜ·½±ã¡£
µ«¶àÁ˾ÍÒªÓöµ½IOÆ¿¾±¡£
ÁíÍ⣬XML¸ñʽ±È½ÏͨÓá£
Ò»°ãÀ´Ëµ£¬¸´ÔÓÐ͵ÄÊý¾Ý´æ´¢»¹ÊÇÓÃÊý¾Ý¿âºÃЩ¡£´¦Àí·½±ã¡£¶øÇÒЧÂʸߡ£
ͨÓÃÐÔÇ¿£¬¿ÉÒÔÔÚÈκÎƽ̨ÉÏʹÓá£Ð¡Ð͵ÄÊý¾Ý¶¼¿ÉÒÔʹÓÃXML¡£
ȱµã¾ÍÊÇÓÐÒ»¸ö»º´æµÄÎÊÌâ
1£©XML¿ÉÒÔÓÃÓÚ±¾µØ¼ÆËãµÄÊý¾Ý¡£´«µÝµ½×ÀÃæµÄÊý¾Ý¿ÉÒÔ½øÐб¾µØ¼ÆËã¡£XM ......
×÷Õß: J. Andrew Schafer
ÕâƪÎÄÕ¼ÙÉèÄã¶Ô XML, XSLT, ºÍ C# ÊìϤ
ÏÂÔØÕâƪÎÄÕµÄÔ´´úÂë: XMLC.exe (76KB)
ÒëÕß˵Ã÷£ºÕâƪÎÄÕÂÊǺÜÔçÒÔÇ°¾Í·¢±íÁË£¬ËüÌṩµÄÔ´´úÂëÊÇ»ùÓÚ VS.net ²âÊ԰棨RTM ºÍ Beta 2£©µÄ¡£
ÕªÒª
C# ÔÊÐí¿ª·¢ÈËÔ±ÔÚÔ´´úÂëÖвåÈëXML×¢ÊÍ£¬ÕâÔÚ¶àÈËÐ×÷¿ª·¢µÄʱºòÏÔµÃÌرðÓÐÓᣠ......
package demo.oath ;
import org.jdom.* ;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class AccountHelper
{
......
Á½ÖÖ·½·¨£º
ÆäÒ»£¬Ê¹Óà SelectNodes µÄ·½·¨£»ÒÔÏÂÀý×ÓΪʹÓô˷½·¨µÄ´¦Àí¡£
Æä¶þ£¬Ê¹Óà XQuery µÄ·½·¨¡£
''' <summary>
''' ´Ó XML ÎļþÖÐÈ¡µÃ¶ÔÓ¦ID µÄÓïÑÔÖµ
''' </summary>
''' <param name="textID">ÊäÈëµÄID< ......
XML DOM
¡¡¡¡XML DOM ¶¨ÒåÁË·ÃÎʺʹ¦Àí XML ÎĵµµÄ±ê×¼·½·¨¡£
¡¡¡¡XML DOM ÊÇ XML Document Object Model µÄËõд£¬¼´ XML Îĵµ¶ÔÏóÄ£ÐÍ¡£
¡¡¡¡Ò»¡¢DOM ¼ò½é
¡¡¡¡Ê²Ã´ÊÇ DOM£¿
¡¡¡¡DOM ÊÇ W3C£¨ÍòάÍøÁªÃË£© µÄÍƼö±ê×¼¡£
¡¡¡¡DOM ¶¨ÒåÁË·ÃÎÊÖîÈç XML ºÍ XHTML ÎĵµµÄ±ê×¼¡£
¡¡¡¡“W3C Îĵµ¶ÔÏóÄ£ÐÍ£¨DOM£©ÊÇÒ»¸ ......