C#操作xml哪种方式性能比较高

hozry 2010-08-19 11:41:53
如javascript 、linq to xml、xmldocument等
...全文
400 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
symbol_bc 2010-08-19
  • 打赏
  • 举报
回复
我觉得js和c#差不多吧
cwaspnet 2010-08-19
  • 打赏
  • 举报
回复
xmldocument
  • 打赏
  • 举报
回复

/// <summary>
/// 读取Xml字符串返回DataSet
/// </summary>
/// <param name="StringXml">字符串</param>
/// <returns>DataSet</returns>
public DataSet GetDataSet(string StringXml)
{
StringReader stringReader = null;
XmlTextReader xmlTextReader = null;
DataSet rDataSet = new DataSet();
try
{
stringReader = new StringReader(StringXml);
xmlTextReader = new XmlTextReader(stringReader);
rDataSet.ReadXml(xmlTextReader);
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (xmlTextReader != null)
{

xmlTextReader.Close();
stringReader.Close();
stringReader.Dispose();
}
}
return rDataSet;
}


别太注重效率、有时候要看方便不
xupeihuagudulei 2010-08-19
  • 打赏
  • 举报
回复
看样子大家都是自己写的呀
我都是直接在属性前加上xmlattribute特性。
呵呵。
  • 打赏
  • 举报
回复

/// <summary>
/// 读取Xml字符串返回DataSet
/// </summary>
/// <param name="StringXml">字符串</param>
/// <returns>DataSet</returns>
public DataSet GetDataSet(string StringXml)
{
StringReader stringReader = null;
XmlTextReader xmlTextReader = null;
DataSet rDataSet = new DataSet();
try
{
stringReader = new StringReader(StringXml);
xmlTextReader = new XmlTextReader(stringReader);
rDataSet.ReadXml(xmlTextReader);
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (xmlTextReader != null)
{

xmlTextReader.Close();
stringReader.Close();
stringReader.Dispose();
}
}
return rDataSet;
}


别太注重效率、有时候要看方便不
  • 打赏
  • 举报
回复

/// <summary>
/// 读取Xml字符串返回DataSet
/// </summary>
/// <param name="StringXml">字符串</param>
/// <returns>DataSet</returns>
public DataSet GetDataSet(string StringXml)
{
StringReader stringReader = null;
XmlTextReader xmlTextReader = null;
DataSet rDataSet = new DataSet();
try
{
stringReader = new StringReader(StringXml);
xmlTextReader = new XmlTextReader(stringReader);
rDataSet.ReadXml(xmlTextReader);
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (xmlTextReader != null)
{

xmlTextReader.Close();
stringReader.Close();
stringReader.Dispose();
}
}
return rDataSet;
}


别太注重效率、有时候要看方便不
wwfgu00ing 2010-08-19
  • 打赏
  • 举报
回复
xmldocument
zsyok 2010-08-19
  • 打赏
  • 举报
回复
js xmldocument 都可以,看你要怎样的处理
lostuser 2010-08-19
  • 打赏
  • 举报
回复
学习。。。
sh_suyuelin 2010-08-19
  • 打赏
  • 举报
回复
学习了。
winner2050 2010-08-19
  • 打赏
  • 举报
回复
XMLReader 性能是最高的。

现在读自定义配置文件我都用XMLReader了。
wuyq11 2010-08-19
  • 打赏
  • 举报
回复
基本还是使用XMLReader,XmlDom与Linq to Xml比,Linq to XML还是要好一些
http://www.nearinfinity.com/blogs/page/jferner?entry=performance_linq_to_sql_vs
jdhlowforever 2010-08-19
  • 打赏
  • 举报
回复
学习了
george010 2010-08-19
  • 打赏
  • 举报
回复
SAX是比较快,不用把整个文件加载到内存,但是不支持随机访问。Dom把文档加载到内存中,耗费资源,但是可以随机访问
宝_爸 2010-08-19
  • 打赏
  • 举报
回复
js不知道。

C#方面,应该XmlReader比较快吧,毕竟是SAX的实现。
XDocument(Linq to XML) 和XmlDocument都是DOM,估计差不多。

XmlSerializer是最慢的,好像用到了动态编译。
一克代码 2010-08-19
  • 打赏
  • 举报
回复
个人觉得js好点!

js不用依赖。net库!

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧