日期:2014-05-18  浏览次数:20906 次

在C#中如何解析一个XML文档,把其中的数据存入相关的数据库表中
请问主要用到什么技术?能给详例更好?

------解决方案--------------------
XmlDocument mXml=new XmlDocument();
mXml.Load( "C:\\test1.xml ");
string XmlString=mXml.OuterXml;
string[] mStrs
=System.Text.RegularExpressions.Regex.Split(XmlString, "version ");
//= XmlString.Split( "version ".);//new char[]{ 'v ', 'e ', 'r ', 's ', 'i ', 'o ', 'n '}
foreach(string Str in mStrs)
{
int a=Str.IndexOf( "=\ " ");
if(a==-1 )
{
continue;
}
int b=Str.IndexOf( "\ " ",a+2);
if( b==-1)
{
continue;
}
MessageBox.Show( Str.Substring(a+2,b-2));
}

------解决方案--------------------
<%@ Page Language= "C# " %>
<%@ Import Namespace= "System.Xml " %>
<script runat= "server ">

protected void Page_Load( object sender, EventArgs e )
{
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath( "x.xml "));
GetNode(doc.DocumentElement);

}

void GetNode(XmlNode m)
{
Response.Write( " <hr> " + m.Name);
for(int j = 0;j <m.Attributes.Count;j++)
{
Response.Write( " <li> " + m.Attributes[j].Name + " = " + m.Attributes[j].Value);
}
if(m.ChildNodes.Count > 0)
{
for(int i = 0;i <m.ChildNodes.Count;i++)
{
GetNode(m.ChildNodes[i]);
}
}
}

</script>

以上代码转net_lover(【孟子E章】)