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();
}
}
Ïà¹ØÎĵµ£º
ÒÔǰÔÚ²©¿ÍÉÏ·¢¹ý£¬¾ÈËÌáÐÑDataSetÒÑ×Ô´ø¶ÁдXMLµÄ¹¦ÄÜ£¬ÓÚÊDZãɾÁË£¬
²»¹ýÔÚʵ¼ùÖиоõ·â×°Ò»²ãºó£¬Ê¹ÓÃÆðÀ´»¹ÊÇÂù·½±ãµÄ¡£¹ÊÔÙ´ÎÖØ·¢¡£
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.IO;
using System.Xml;
namespace XmlDesign
{
class XmlDatasetC ......
///ͨ¹ý´«ÈëµÄÌØ¶¨XML×Ö·û´®£¬Í¨¹ý ReadXmlº¯Êý¶ÁÈ¡µ½DataSetÖС£
protected static DataSet GetDataSetByXml(string xmlData)
{
try
{
&nbs ......
¿ª·¢Öо³£Óöµ½ÒªºÍ¸÷ÖÖ¸÷ÑùµÄ XML ´ò½»µÀ£¬±à¼ XML Îļþʱ×îÍ·Í´µÄ±ãÊÇÒª¼ÇסÐí¶à XML ÔªËØÃû³Æ¡¢ÊôÐÔÃû³Æ¡£
ÐÒÔ˵ÄÊÇ£¬Vistual Studio µÄ XML ÖÇÄÜÌáʾ¹¦ÄÜ¿ÉÒÔ´ó´óµØ¼õÇáÕâһʹ¿à¡£Ö»Ðèͨ¹ýÌí¼Ó×Ô¶¨ÒåµÄ XSD ÎļþʹµÃÔڱ༠XML Îļþʱ»ñµÃV ......
XML DOM
XML DOM (XML Document Object Model) ¶¨ÒåÒ»Ì×·ÃÎʺͲÙ×÷ XML ÎĵµµÄ±ê×¼·½·¨¡£
DOM °Ñ XML Îĵµ×÷ΪÊ÷½á¹¹À´²é¿´¡£Äܹ»Í¨¹ý DOM Ê÷À´·ÃÎÊËùÓÐÔªËØ¡£¿ÉÒÔÐ޸Ļòɾ³ýËüÃǵÄÄÚÈÝ£¬²¢´´½¨ÐµÄÔªËØ¡£ÔªËØ£¬ËüÃǵÄÎı¾£¬ÒÔ¼°ËüÃǵÄÊôÐÔ£¬¶¼±»ÈÏΪÊǽڵ㡣
ÔÚÏÂÃæµÄÀý×ÓÖУ¬ÎÒÃÇʹÓà DOM ÒýÓÃ´Ó <to> ÔªËØÖлñÈ ......
½ñÌìÊÇÉϿεĵÚÒ»Ì죬ûÏëµ½µÚÒ»Ìì¾Í½²ÁËÄÇô¶àµÄ¶«Î÷£¬¿´ÁË¿´ÀÏʦµÄPPT£¬·¢ÏÖ¶«Î÷ËäÈ»¶à£¬µ«ÊǶ¼²»ÄÑÀí½â£¬»¹ÊDZȽÏÈÝÒ׵ġ£¹þ¹þ£¬µÃÒæÓÚÔÚ´«ÖÇ»ù´¡°àµÄ´¸Á¶£¬Ó¢Ã÷µÄ¾ö¶¨¾ÍÊÇ´ÓͷѧÆð¡£
¸Õ¹ýÍê´º½ÚÀÏ·½µÄ»°»¹ÊÇ˵µÄ²»ÊǺÜÁ÷Àû°¡£¨Òª¼ÓÇ¿ÆÕͨ»°Á·Ï°à¸ ......