DataSet(DataTable)ÓëXML»¥×ª
using System;
using System.Data;
using System.IO;
using System.Xml;
using System.Text;
// ÏàÓ¦C#´úÂ룺
private string ConvertDataTableToXML(DataTable xmlDS)
{
MemoryStream stream = null;
XmlTextWriter writer = null;
try
{
stream = new MemoryStream();
writer = new XmlTextWriter(stream, Encoding.Default);
xmlDS.WriteXml(writer);
int count = (int)stream.Length;
byte[] arr = new byte[count];
stream.Seek(0, SeekOrigin.Begin);
stream.Read(arr, 0, count);
UTF8Encoding utf = new UTF8Encoding();
return utf.GetString(arr).Trim();
}
catch
{
return String.Empty;
}
finally
{
if (writer != null) writer.Close();
}
}
private DataSet ConvertXMLToDataSet(string xmlData)
{
StringReader stream = null;
XmlTextReader reader = null;
try
{
DataSet xmlDS = new DataSet();
stream = new StringReader(xmlData);
reader = new XmlTextReader(stream);
xmlDS.ReadXml(reader);
return xmlDS;
}
catch (Exception ex)
{
string strTest = ex.Message;
return null;
}
finally
{
if (reader != null)
reader.Close();
}
}
Ïà¹ØÎĵµ£º
ÕâÊÇÒ»¸öÓÃc#¿ØÖÆÌ¨³ÌÐòÏ£¬ ÓÃXmlDocument ½øÐÐXML²Ù×÷µÄµÄÀý×Ó£¬°üº¬Á˲éѯ¡¢Ôö¼Ó¡¢Ð޸ġ¢É¾³ý¡¢±£´æµÄ»ù±¾²Ù×÷¡£½ÏÍêÕûµÄÃèÊöÁËÒ»¸öXMLµÄÕû¸ö²Ù×÷Á÷³Ì¡£ÊʺϸÕÈëÃÅ.net XML²Ù×÷µÄÅóÓѲο¼ºÍѧϰ¡£
¼ÙÉèÓÐXMLÎļþ£ºbooks.xml
Xml´úÂ룺
<?xml version="1.0" encoding="UTF-8"?>
<books>
< ......
sd.xmlÎļþ:
<?xml version="1.0" encoding="gb2312"?>
<!--ÕâÊÇÒ»¸öxmlÎļþ-->
<xml1>
<item name="1">µÚÒ»¸öitem</item>
<item name="2">
<item name="1">Õâ¸ö½áµã(1) ......
Eclipse IBM¿ª·¢³öµÄ¹¤¾ß
step over Ìøµ½µ±Ç°³ÌÐòµÄÏÂÒ»ÐÐ(Ìø¹ý)
step into Ìø½øÈ¥ (ÌøÈë)
step return Ìø³öÀ´ (Ìø³ö)
XML
<a classname="cn.itcast.Person"></a>
<?xml version="1.0"?> ¿Õ¸ñ±ØÐëΪӢÎÄ
×Ö·û±àÂë
<?xml version="1.0" encoding="UTF-8"?>
CDATA -->Character data &nb ......
1£®Ê²Ã´ÊÇXML£¿
XML ¿ª·¢ÕßÃÇ»á¸æËßÄ㣬ÊÂʵÉÏXML²¢²»ÊÇÒ»ÖÖÓïÑÔ£¬¶øÊÇÒ»ÖÖÓÃÀ´¶¨ÒåÆäËüÓïÑÔµÄϵͳ¡£¿ÉÄÜÄãÒѾÌý¹ý£¬»òÐíÉõÖÁ×Ô¼º³¢ÊÔ¹ýһЩÕâÑùµÄÓïÑÔ??±ÈÈç΢ÈíÎªÍÆ£¨push£©¼¼ÊõËùÍÆ³öµÄƵµÀ¶¨Òå¸ñʽ£¨Channel Definition Format£©¡£
W3CÊÇ»¥Á¬ÍøÉÏһЩ¹«Óñê×¼µÄ¿ª·¢Õߣ¬ËûÍÆ³öÁËһϵÁкÍXMLÏà¹ØµÄ±ê× ......
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
xmlѧϰ£ºhttp://www.w3school.com.cn/x.asp ......