Asp.Net XML²Ù×÷»ùÀà
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
using System.Text;
using MSXML2;
namespace EC
{
/// <summary>
/// XML ²Ù×÷»ùÀà
/// </summary>
public class XmlObject : IDisposable
{
//ÒÔÏÂΪµ¥Ò»¹¦Äܵľ²Ì¬Àà
#region ¶ÁÈ¡XMLµ½DataSet
/**************************************************
* º¯ÊýÃû³Æ:GetXml(string XmlPath)
* ¹¦ÄÜ˵Ã÷:¶ÁÈ¡XMLµ½DataSet
* ²Î Êý:XmlPath:xmlÎĵµÂ·¾¶
* ʹÓÃʾÁÐ:
* using EC; //ÒýÓÃÃüÃû¿Õ¼ä
* string xmlPath = Server.MapPath("/EBDnsConfig/DnsConfig.xml"); //»ñÈ¡xml·¾¶
* DataSet ds = EC.XmlObject.GetXml(xmlPath); //¶ÁÈ¡xmlµ½DataSetÖÐ
************************************************/
/// <summary>
/// ¹¦ÄÜ:¶ÁÈ¡XMLµ½DataSetÖÐ
/// </summary>
/// <param name="XmlPath">xml·¾¶</param>
/// <returns>DataSet</returns>
public static DataSet GetXml(string XmlPath)
{
DataSet ds = new DataSet();
ds.ReadXml(@XmlPath);
return ds;
}
#endregion
#region ¶ÁÈ¡xmlÎĵµ²¢·µ»ØÒ»¸ö½Úµã
/**************************************************
* º¯ÊýÃû³Æ:ReadXmlReturnNode(string XmlPath,string Node)
* ¹¦ÄÜ˵Ã÷:¶ÁÈ¡xmlÎĵµ²¢·µ»ØÒ»¸ö½Úµã:ÊÊÓÃÓÚÒ»¼¶½Úµã
* ²Î Êý: XmlPath:xmlÎĵµÂ·¾¶;Node ·µ»ØµÄ½ÚµãÃû³Æ
* ÊÊÓ¦ÓÃXml:<?xml version="1.0" encoding="utf-8" ?>
* <root>
* <dns1>ns1.everdns.com</dns1>
* </root>
* ʹÓÃʾÁÐ:
Ïà¹ØÎĵµ£º
ASP.NET»ñÈ¡¿Í»§¶ËIP/Óû§ÃûµÈÐÅÏ¢
1. ÔÚASP.NETÖÐרÓÃÊôÐÔ£º
»ñÈ¡·þÎñÆ÷µçÄÔÃû£ºPage.Server.ManchineName
»ñÈ¡Óû§ÐÅÏ¢£ºPage.User
»ñÈ¡¿Í»§¶ËµçÄÔÃû£ºPage.Request.UserHostName
»ñÈ¡¿Í»§¶ËµçÄÔIP£ºPage.Request.UserHostAddress
2. ÔÚÍøÂç±à³ÌÖеÄͨÓ÷½·¨£º
»ñÈ¡µ±Ç°µçÄÔÃû£ºstatic System. ......
ÔÚ ASP.NET ÍøÒ³µÄĬÈÏÄ£ÐÍÖУ¬Óû§»áÓëÒ³½»»¥£¬µ¥»÷°´Å¥»òÖ´Ðе¼Ö»ط¢µÄһЩÆäËû²Ù×÷¡£´Ëʱ½«ÖØд´½¨Ò³¼°Æä¿Ø¼þ£¬²¢ÔÚ·þÎñÆ÷ÉÏÔËÐÐÒ³´úÂ룬ÇÒа汾µÄÒ³±»³ÊÏÖµ½ä¯ÀÀÆ÷¡£µ«ÊÇ£¬ÔÚÓÐЩÇé¿öÏ£¬ÐèÒª´Ó¿Í»§¶ËÔËÐзþÎñÆ÷´úÂ룬¶ø²»Ö´Ðлط¢¡£Èç¹ûÒ³ÖеĿͻ§¶Ë½Å±¾Î¬»¤Ò»Ð©×´Ì¬ÐÅÏ¢£¨ÀýÈ磬¾Ö²¿±äÁ¿Öµ£©£¬ÄÇô·¢ËÍÒ³ºÍ»ñÈ¡Ò ......
SQl XmlºÍC# XmlÊý¾ÝµÄÒ»µã²Ù×÷×ܽá
ÔÚ´ËÉêÃ÷XmlÊÇInfoSetÊý¾Ý²»ÊÇ×Ö·û´®£¬ËùÒÔÔÚ´ËÇ¿ÁÒ·´¶ÔÓÃstringÆ´½Óxml¡£Êý¾Ý¿â¿ÉÒÔ´æ·ÅxmlÀàÐÍÊý¾Ý£¬ÄÇô¸ÃÊý¾ÝµÄ¾ßÌå²Ù×÷ÓÖÈçºÎÁË¡£
1.Ê×ÏȽ¨Á¢Ò»Õź¬ÓÐxmlÊý¾ÝÀàÐ͵ıí
CREATE TABLE [dbo].[TestXml](
[ID] [bigint] IDENTITY(1,1) NOT NULL,
[Message] [xml] NULL ......
ÒÑÖªÓÐÒ»¸öXMLÎļþ£¨bookstore.xml£©ÈçÏ£º
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
&nb ......