xmltextreader_XmlTextReader越来越多

xmltextreader

xmltextreader

Random thought: I like the whole XmlReader philosophy. I use it much more often than XmlDocument. I haven't made an XmlDocument in a while. Every once in a while an XmlDocument shows up when you need an XmlNode for some SOAP stuff, but for the most part, I like XmlReaders.

随意的想法:我喜欢整个XmlReader哲学。 我使用它的次数比XmlDocument多得多。 我有一段时间没有制作XmlDocument了。 当您需要一个XmlNode来处理一些SOAP内容时,有时会出现一个XmlDocument,但是在大多数情况下,我喜欢XmlReaders。

Someone wanted a chunk of code that grabbed RSS Enclosures from a feed. They didn't care about the content, they just wanted the enclosures' attributes. Here's what I sent them 2 mins later.

有人想要从提要中获取RSS附件的大量代码。 他们不在乎内容,只想要附件的属性。 这是我2分钟后发送给他们的内容。

Sure this code could have been done with XmlDocument.SelectNodes (and I'm sure one of you will show me how) but without getting to much into premature optimization, I know that using an XmlReader will always give me better performance. Always. If use it for little one-off stuff like this, I know when I need real performance for a real app, the usage will be fresh in my mind.

当然,可以使用XmlDocument.SelectNodes来完成此代码(我敢肯定你们中的一个会向我展示如何做),但在不进行过早优化的情况下,我知道使用XmlReader总是可以为我带来更好的性能。 总是。 如果将它用于这样的一次性应用,我知道当我需要真正的应用程序的真正性能时,这种用法将是新鲜的。

using System;

使用系统;

using System.Xml;

使用System.Xml;

namespace ConsoleApplication1

命名空间ConsoleApplication1

{

{

    class Program

班级计划

    {

{

        static void Main(string[] args)

静态void Main(字符串[] args)

        {

{

            XmlTextReader tr =                new XmlTextReader("http://feeds.feedburner.com/ScottHanselman");

XmlTextReader tr =新的XmlTextReader(“ http://feeds.feedburner.com/ScottHanselman”);

            object enclosure = tr.NameTable.Add("enclosure");

对象附件= tr.NameTable.Add(“附件”);

            while (tr.Read())

而(tr.Read())

            {

{

                if (tr.NodeType == XmlNodeType.Element &&

如果(tr.NodeType == XmlNodeType.Element &&

                    Object.ReferenceEquals(tr.LocalName, enclosure))

Object.ReferenceEquals(tr.LocalName,附件))

                {

{

                    while (tr.MoveToNextAttribute())

同时(tr.MoveToNextAttribute())

                    {

{

                        Console.WriteLine(String.Format("{0}:{1}",                            tr.LocalName, tr.Value));

Console.WriteLine(String.Format(“ {0}:{1}”,tr.LocalName,tr.Value));

                    }

}

                }

}

            }

}

        }

}

    }

}

}

}

Now playing: Rent - Rent

正在播放:-

翻译自: https://www.hanselman.com/blog/xmltextreader-more-and-more

xmltextreader

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值