Linq xml Ê÷¼ÓÔØ×ܽá(1)
¾³£»áÓõ½xmlÎļþ£¬ÄÚÈݼÓÔØ£¬ Èç¹ûʹÓÃlinq xmlÊ÷¼ÓÔØ£¬ÐèҪͨ¹ýXElementÀ࣬һÖÖ·½Ê½ÊÇÒÔ×Ö·û´®µÄÐÎʽ¼ÓÔØ£¬ÁíÍâÒ»ÖÖ·½Ê½ÊÇÒÔÎļþÐÎʽ¼ÓÔØ¡£ 1.ÒÔ×Ö·û´®ÐÎʽ¼ÓÔØ¡£ ÔÚXElementÀàÖУ¬Í¨¹ý¾²Ì¬µÄParse()·½·¨£¬½«XMLÊ÷ÒÔ×Ö·û´®µÄÐÎʽ¼ÓÔص½ÄÚ´æÖУ¬¸ø³öÁËÒ»¸öʵÏÖ´úÂ룺 XElement element =XElement.Parse(xml); xmlÊÇËù°üº¬µÄXMLÊ÷ÄÚÈÝ¡£¿ÉÒÔʵÏÖ½«¸ÃLINQ XMLÊ÷¼ÓÔص½ÄÚ´æÖС£ 2.ÒÔÎļþÐÎʽ¼ÓÔØ¡£ XElement elementfromFile = XElement.Load("myxml.xml"); XELementÀàÖеľ²Ì¬Load()·½·¨£¬ÊµÏÖ½«¸Ãlinq xmlÊ÷¼ÓÔص½ÄÚ´æÖС£
Ïà¹ØÎĵµ£º
/// <summary>
/// DataTable-------------------->XML --String
/// </summary>
public static String ToXmlString(DataTable dt)
{
StringWriter tr = new StringWriter();
try
{
dt.WriteXml(tr); ......
ÏÖÔÚÎÒÃÇÔÝÇÒʹÓÓ¼Çʱ¾”À´´´½¨ÎÒÃǵÄXMLÎļþ°É¡£ÏÈ¿´Ò»¸öXMLÎļþ£º
¡¡¡¡Àý1
¡¡¡¡¡´?xml version="1.0" encoding="gb2312" ?¡µ
¡¡¡¡¡´²Î¿¼×ÊÁÏ¡µ
¡¡¡¡ ¡´Êé¼®¡µ
¡¡¡¡ ¡´Ãû³Æ¡µXMLÈëÞ«½â¡´/Ãû³Æ¡µ
¡¡¡¡ ¡´×÷Õß¡µÕÅÈý¡´/×÷Õß¡ ......
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 >ÖеĴ ......
ÔÚweb.config×ö參數設¶¨時Óöµ½ÌØÊâ×ÖÔª value="http://www.yahoo.com.tw/default.aspx?sid=111111111&uid=test"
&uid這µØ·½會³ö錯...換³É&uid ¾ÍOKÁË~~
幾個
對ÕÕÈçÏÂ:
< Сì¶
<
> ´óì¶
>
&
& ......