有没有办法从字符串创建 SyndicateFeed?
我正在尝试从本地存储的 XML 数据重新创建 SyndicateFeed 对象 (System.ServiceModel.Syndicate)。
如果我使用 XMLDocument,这会很容易。我会调用 LoadXml(string)。
SyndicateFeed 将仅从 XMLReader 加载。 XMLReader 将仅采用 Stream 或另一个 XMLReader 或 TextReader。
由于 XMLDocument 将加载一个字符串,因此我尝试按如下方式执行此操作(以扩展方法的形式):
public static SyndicationFeed ToSyndicationFeed(this XmlDocument document)
{
Stream thestream = Stream.Null;
XmlWriter thewriter = XmlWriter.Create(thestream);
document.WriteTo(thewriter);
thewriter.Flush();
XmlReader thereader = XmlReader.Create(thestream);
SyndicationFeed thefeed = SyndicationFeed.Load(thereader);
return thefeed;
}
我无法使其工作。即使 XMLDocument 中填充了要加载到 SyndicateFeed 中的 Feed,Stream 也始终为空。
您可以提供的任何帮助或指示都会非常有帮助。
谢谢, 罗伯托
I'm trying to recreate a SyndicationFeed object (System.ServiceModel.Syndication) from XML data that has been stored locally.
If I were working with XMLDocument, this would be easy.I'd call LoadXml(string).
The SyndicationFeed will only load from an XMLReader. The XMLReader will only take a Stream or another XMLReader or a TextReader.
Since XMLDocument will load a string, I've tried to do this as follows (in the form of a Extension Method):
public static SyndicationFeed ToSyndicationFeed(this XmlDocument document)
{
Stream thestream = Stream.Null;
XmlWriter thewriter = XmlWriter.Create(thestream);
document.WriteTo(thewriter);
thewriter.Flush();
XmlReader thereader = XmlReader.Create(thestream);
SyndicationFeed thefeed = SyndicationFeed.Load(thereader);
return thefeed;
}
I can't get this to work. The Stream is always empty even though the XMLDocument is populated with the Feed to be loaded into the SyndicationFeed.
Any help or pointers you can give would be most helpful.
Thanks,
Roberto
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 StringReader 扩展了 TextReader,因此这应该可以工作:
Since StringReader extends TextReader, this should work: