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 DOM
XML DOM (XML Document Object Model) ¶¨ÒåÒ»Ì×·ÃÎʺͲÙ×÷ XML ÎĵµµÄ±ê×¼·½·¨¡£
DOM °Ñ XML Îĵµ×÷ΪÊ÷½á¹¹À´²é¿´¡£Äܹ»Í¨¹ý DOM Ê÷À´·ÃÎÊËùÓÐÔªËØ¡£¿ÉÒÔÐ޸Ļòɾ³ýËüÃǵÄÄÚÈÝ£¬²¢´´½¨ÐµÄÔªËØ¡£ÔªËØ£¬ËüÃǵÄÎı¾£¬ÒÔ¼°ËüÃǵÄÊôÐÔ£¬¶¼±»ÈÏΪÊǽڵ㡣
ÔÚÏÂÃæµÄÀý×ÓÖУ¬ÎÒÃÇʹÓà DOM ÒýÓÃ´Ó <to> ÔªËØÖлñÈ ......
sd.xmlÎļþ:
<?xml version="1.0" encoding="gb2312"?>
<!--ÕâÊÇÒ»¸öxmlÎļþ-->
<xml1>
<item name="1">µÚÒ»¸öitem</item>
<item name="2">
<item name="1">Õâ¸ö½áµã(1) ......
1.ÔÚJSPÖÐÉú³É¶¯Ì¬XML
¿ÉÒÔʹÓÃJSPÉú³ÉXML,ʹÓÃCSS»òÕßXSLת»»ºÍÏÔʾXML;
Ö»ÒªÔÚ¾²Ì¬µÄXMLÎĵµÄ£°åÖмÓÈëJava´úÂëºÍJSP±ê¼Ç£¬XML¾Í¿ÉÒÔÓо²±ä¶¯£¬²úÉú¶¯Ì¬µÄÄÚÈÝ£¬Éú³ÉXMLÎĵµµÄ·½·¨ºÜ¼òµ¥£¬Ö»ÐèÒªÔÚÎļþÖÐʹÓÃÖ¸Áîcontenttype,Èç<%@ page contenttype="text/xml"%>£»
ÔÚXMLÎĵµÖÐͬÑù¿ÉÒÔʹ ......