LINQ to XML ѧϰ±Ê¼Ç
LINQ to XML ¿ÉÒÔ¿´×÷ÊÇÒ»¸ö “better DOM” ±à³ÌÄ£ÐÍ£¬¿ÉÒÔºÍ System.Xml.dll ³ÌÐò¼¯Öеĺܶà³ÉÔ±½»»¥¡£
Ò»¡¢ÃüÃû¿Õ¼ä
System.Xml.Linq.dll ³ÌÐò¼¯¶¨ÒåÁËÈý¸öÃüÃû¿Õ¼ä£ºSystem.Xml.Linq, System.Xml.Schema ºÍ System.Xml.XPath
×îºËÐĵÄÊÇ System.Xml.Linq£¬ ¶¨ÒåÁ˶ÔÓ¦ XML Îĵµ¸ö·½ÃæµÄºÜ¶àÀàÐÍ
Member of System.Xml.Linq
Meaning in Life
XAttribute
Represents an XML attribute on a given XML element
XComment
Represents an XML comment
XDeclaration
Represents the opening declaration of an XML document
XDocument
Represents the entirety of an XML document
XElement
Represents a given element within an XML document
XName/XNamespace
Provide a very simple manner to define and reference XML namespaces
¶þ¡¢±à³Ì·½Ê½´´½¨XMLÎĵµ
ÒÔÇ°µÄ .NET XML±à³ÌÄ£ÐÍÐèҪʹÓúܶàÈß³¤µÄ DOM API£¬¶ø LINQ to XML ÔòÍêÈ«¿ÉÒÔÓÃÓë DOM Î޹صķ½Ê½Óë XML Îĵµ½»»¥¡£ÕâÑù²»µ«´ó´ó¼õÉÙÁË´úÂëÐУ¬¶øÇÒÕâÖÖ±à³ÌÄ£ÐÍ¿ÉÒÔÖ±½ÓÓ³Éäµ½¸ñʽÁ¼ºÃµÄXMLÎĵµ½á¹¹¡£
static void CreateFunctionalXmlElement()
{
// A "functional" approach to build an
// XML element in memory.
XElement inventory =
new XElement("Inventory",
new XElement("Car", new XAttribute("ID", "1"),
new XElement("Color", "Green"),
new XElement("Make", "BMW"),
new XElement("PetName", "Stan")
)
);
// Call ToString() on our XElement.
Console.WriteLine(inventory);
}
ÔÚÄÚ´æÖд´½¨XMLÎĵµ
static void CreateFunctionalXmlDoc()
{
XDocument inventoryDoc =
new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
&n
Ïà¹ØÎĵµ£º
Ð÷ÂÛ
LibxmlÊÇÒ»¸öÓÐÃâ·ÑÐí¿ÉµÄÓÃÓÚ´¦ÀíXML¡¢¿ÉÒÔÇáËÉ¿çÔ½¶à¸öƽ̨µÄCÓïÑÔ¿â¡£LibxmlʵÏÖÁ˶Á¡¢´´½¨¼°²Ù×ÝXMLÊý¾Ý¹¦ÄÜ¡£
Õâ¸öÖ¸ÄÏ»ùÓÚÒ»¸ö¼òµ¥µÄXMLÓ¦Óá£
Êý¾ÝÀàÐÍ
Libxml ¶¨ÒåÁËÐí¶àÊý¾ÝÀàÐÍ£¬ËüÒþ²ØÁËÔÓÂÒµÄÀ´Ô´ÒÔÖÂÄã²»±Ø´¦ÀíËü³ý·ÇÄãÓÐÌض¨µÄÐèÒª¡£xmlChar Ìæ´úchar,ʹÓÃUTF-8±àÂëµÄÒ»×Ö½Ú×Ö·û´®¡£Èç¹ûÄãµÄÊ ......
ÕâÊǹØÓÚAsp.Net/XMLÉîÈë±à³ÌµÄ¼¼ÊõÊ飬×÷Õß¾«ÐÄÉè¼ÆÁË66¸öʵÀýÏêϸ½éÉÜÁË.Net FrameworkÒÔ¼°XML¼¼ÊõÔÚ.Net FrameworkµÄ±à³Ì·½·¨ºÍ¼¼ÇÉ¡£È«ÊéÓÉ12Õ¹¹³É£¬ÄÚÈÝ°üÀ¨.Netƽ̨µÄ½¨Á¢¡¢Asp.NetµÄWeb Forms¡¢¿Ø¼þ¡¢Êý¾Ý·ÃÎÊ¡¢Web Service¡¢Asp.NetµÄÉèÖú͸ú×Ù¡¢Asp.NetµÄ°²È« ......
ת×Ô£ºhttp://www.w3school.com.cn/xml/xml_syntax.asp
XML µÄÓï·¨¹æÔòºÜ¼òµ¥£¬ÇÒºÜÓÐÂß¼¡£ÕâЩ¹æÔòºÜÈÝÒ×ѧϰ£¬Ò²ºÜÈÝÒ×ʹÓá£
ËùÓÐ XML ÔªËض¼ÐëÓйرձêÇ©
ÔÚ HTML£¬¾³£»á¿´µ½Ã»ÓйرձêÇ©µÄÔªËØ£º
<p>This is a paragraph
<p>This is another paragraph
ÔÚ XML ÖУ¬Ê¡ÂԹرձêÇ©ÊÇ·Ç·¨µÄ¡£ËùÓÐÔª ......
ת×Ô£ºhttp://www.w3school.com.cn/xml/xml_dtd.asp
ÓµÓÐÕýÈ·Óï·¨µÄ XML ±»³ÆΪ“ÐÎʽÁ¼ºÃ”µÄ XML¡£
ͨ¹ýij¸ö DTD ½øÐÐÁËÑéÖ¤µÄ XML ÊÇ“ºÏ·¨”µÄ XML¡£
ÐÎʽÁ¼ºÃµÄ XML Îĵµ
Ò»¸ö"ÐÎʽÁ¼ºÃ"µÄ XML ÎĵµÓµÓÐÕýÈ·µÄÓï·¨¡£
Ò»¸ö"ÐÎʽÁ¼ºÃ"µÄ XML Îĵµ»á×ñÊØÇ°¼¸Õ½éÉܹýµÄ XML Óï·¨¹æÔò£º
XML 뀵 ......
Parsing XML from the Net - Using the SAXParser
http://www.anddev.org/parsing_xml_from_the_net_-_using_the_saxparser-t353.html
What you learn:
You will learn how to properly parse XML
(here: from the net
) using a SAXParser
.
What it will look like:
Description:
0.)
In this tutorial we ......