修改大的XML文件

昨天在这儿看到一个链结:msdn上的一篇关于名为Efficient Techniques for Modifying Large XML Files的文章。修改XML文件对我来说,一直是件头痛的事件,当XML文件很大时,用XmlDocument处理效率就很低了,但这篇文章也没有给出一个满意的答案,全文讲了两个例子:感觉第一个例子还有点趣:使用XML 的 inclusion概念来使的文章便于扩展。他创建了两个文档,第一个是well format的xml文档,第二个是xml引用文档,内容如下:

Logfile.xml:
<?xml version="1.0"?>
<!DOCTYPE logfile [
<!ENTITY events   
 SYSTEM "logfile-entries.txt">
]>
<logfile>
&events;
</logfile>

logfile-entries.txt:
<event>
 <ip>127.0.0.1</ip>
 <http_method>GET</http_method>
 <file>index.html</file>
 <date>2004-04-01T17:35:20.0656808-08:00</date>
</event>
<event>
  <ip>127.0.0.1</ip>
  <http_method>GET</http_method>
  <file>logo.gif</file>
  <date>2004-04-01T17:35:25.238220-08:00</date>
  <referrer>http://www.example.com/index.html</referrer>
</event>

一看,便知其意。这种方法处理Append确实很棒。但其它形式的修改就无能为力了。

文章的第二部分,如何使用XmlTextReader和XmlTextWriter来快速检索和写数据,他的意思还是想避开使用XmlDocument.在这个例子中,他使用到了XmlNameTable,意思是地址比较比串比较速度快。

如下:XmlNameTable xnt = new NameTable(); //XmlNameTable是抽象类,NameTable是它的一个具体实现。
      string ip = xnt.Add("ip");
      XmlTextReader xr = new XmlTextReader(xnt);//使用XmlNameTable初始化XmlTextTable

      xr.Read();
      if(xr.Name == ip) //估计作者的意思是这儿比较会加快速度。
      {}
然后作者在文章未尾,又给了连接:Object Comparison Using XmlNameTable with XmlReader
     
有如下内容:The XmlNameTable class enables the implementations of the XmlReader class to use pointer comparisons instead of string comparisons when parsing data or performing comparison operations on XML documents. The use of this table gives performance gains to the XmlReader derived classes when comparing and using element and attribute names.
估计就是作者想表达的意思。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值