开发者

Porting XmlTextReader to XmlReader with same behaviour

开发者 https://www.devze.com 2023-04-08 14:50 出处:网络
I want to port some C# code with the full .NET Framework as target into Silverlight-compatible code. One of the problems I\'ve encountered is that in the original code, an instance of XmlTextReader i

I want to port some C# code with the full .NET Framework as target into Silverlight-compatible code.

One of the problems I've encountered is that in the original code, an instance of XmlTextReader is used:

var xmlReader = new XmlTextReader(streamReader) {
    WhitespaceHandling = WhitespaceHandling.None,
    xmlResolver = null
};

However, in Silverlight, only XmlReader is available. Therefore, I'm wondering how to convert from the original XmlTextReader.

In the documentation of XmlTextReader, it's stated that

In the .NET Framework version 2.0 release, the recommended practice is to create XmlReader instances using the XmlReader.Create method. This allows you to take full advantage of the new features introduced in this release. For more information, see Creating XML Readers.

This supports开发者_开发知识库 the theory that a port should be possible.

How does the initialization of a XmlReader has to look like to process the XML files exactly the same as the XmlTextReader instance mentioned above?

var settings = new XmlReaderSettings {
    ...
}
var xmlReader = XmlReader.Create(streamReader, settings);


Its not possible to replicate this entirely. Silverlight XmlReader does not support ignoring significant whitespace. This therefore is close:-

 var settings = new XmlReaderSettings { IgnoreWhitespace = true, XmlResolver = null };

I think you should just go with that and see what happens.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号