Any know the reason xmlReader/xmlWriter only provide Create method rather than constructors

Just interesting to know. Why the constructors are protected for those classes.

-------------Problems Reply------------

Because XmlReader/XmlWriter are abstract classes and it doesn't make much sense to have a public constructor in an abstract class. This is a common factory pattern. You use the static Create method which will return a proper implementation based on the argument types in a way that is completely transparent to the developer.

There are specialized types of XMLReader classes like Dictionary Readers, TextReaders etc. that derive from the abstract XMLReader class. You can instantiate those.

Category:c# Views:0 Time:2010-12-23
Tags: .net c#

Related post

  • How to set XmlWriter.XmlWriterSettings when created from XPathNavigator.AppendChild()? 2012-02-10

    I need to set the OmitXmlDeclaration property of the XmlWriterSettings for a XmlWriter to false to not have XML declarations created. The issue is that I have created the XmlWriter from a call of a XPathNavigator.AppendChild() method. Code below: pub

  • Recompiling PHP with xmlreader, xmlwriter enabled 2011-03-08

    I've noticed that the PHP make that I'm using on a dev box doesn't have the xmlreader and xmlwriter extensions enabled. I understand that I need to recompile PHP to enable those extensions (or maybe more accurately remove the disabling, since they ar

  • IntelliSense unavailable for C++/CLI Visual Studio 2010 - XmlReader/XmlWriter nonmanaged alternative 2011-08-01

    I wrote an application wich generates an XML file using XmlReader and XmlWriter (with managed code) in Visual Studio 2010 C++, using cli. Now the problem appears that no IntelliSense is available for C++/CLI. Is there an alternative for cli? Otherwis

  • How to read/write complex object with XmlWriter/XmlReader 2010-12-11

    I've been trying to find an easy way to write XML using the XmlReader/XmlWriter. I don't really like using the interface "IXmlSerializable", but I've got no choice for some of my dataclass. Anyway, what I want to do is quite simple: private MyClass m

  • XML indenting when injecting an XML string into an XmlWriter 2009-05-13

    I have an XmlTextWriter writing to a file and an XmlWriter using that text writer. This text writer is set to output tab-indented XML: XmlTextWriter xtw = new XmlTextWriter("foo.xml", Encoding.UTF8); xtw.Formatting = Formatting.Indented; xtw.IndentCh

  • How to write System.Xml.Linq.XElement using XmlWriter to a stream 2009-12-08

    I have an XElement instance and I wish to write to a stream using XmlWriter class. Why? Well, one of the configuration settings defines whether to use binary Xml or not. Based on this setting a suitable XmlWriter instance is created - either by XmlWr

  • How to write out an EntityReference (e.g.  ) to an XmlWriter, read by XmlNodeReader? 2010-10-29

    Background I'm reading and writing an XML document using reader and writer, with filtering logic in between the read and write operations to determine which parts read should be written back out (effectively it strips some tags out) ... My choice of

  • C# .NET XMLWriter/Reader problem 2010-12-12

    I've been having problems writing XML and reading it in. I have a handwritten XML that gets read in fine, but after I write the XML it acts funny. The output of the WriteXML: It works if you hit enter after

  • Investigating XMLReader object 2011-05-31

    I had asked a question about how to investigate the contents of XMLWriter object while debugging. I am trying to check the contents of an XmlReader object that is created from a memory stream in a similar way as given in the answer of the linked ques

  • XmlReader.ReadContentAsObject always returns string type 2011-08-30

    According to the MSDN documentation, XMLWriter.WriteValue writes xsd type information to the xml for simple CLR types. Then XMLReader.ReadContentAsObject supposedly reads out the appropriately-typed object when the XML is parsed. However, this always

  • How to enable XMLReader in PHP without reconfiguring PHP? 2011-12-11

    My PHP info has this: Configure Command : '--with-libxml-dir=/usr' '--enable-xml' '--disable-xmlreader' '--disable-xmlwriter' i.e. my xmlwriter & xmlreader have not been enabled during installation. libxml libXML support active libXML Compiled Ve

  • Difference Between XMLReader.Create() and new XMLTextReader() 2009-10-11

    I would like to learn the difference between XMLReader.Create and new XMLTextReader() to read XML. Why would I choose one over the other? Is there a performance difference? I know XMLReader is an abstract type for XMLTextReader, at least that is what

  • XmlWriterSettings have no effect on XmlWriter created from XmlDocument 2010-02-10

    I need to use ISO Latin 1 encoding, but using the code below the writer settings defaults back to UTF8. What am I missing here? XmlDocument xmlDoc = new XmlDocument(); XmlWriterSettings settings = new XmlWriterSettings(); settings.ConformanceLevel =

  • How is it that the abstract class XmlWriter can be instantiated using XmlWriter.Create(-? 2010-05-21

    Just looking to clarify my understanding of the workings of the XmlWriter and abstract classes in general. My thinking is (was) that an abstract class can not be instantiated, although it can contain base methods that can be used by an inheriting cla

  • Why do DownloadStringAsync results have strange characters when XmlReader results don't? 2010-07-01

    I am using an RSS feed as a data source. I've adjusted how I retrive the data to use the WebClient.DownloadStringAsync method. Before I was using XmlReader.Create method. I'm then using the results as a data source to bind to a TextBlock in WPF. Sinc

  • XMLWriter vs XMLDictionaryWriter 2010-08-30

    What's the difference between XMLWriter and XMLDictionaryWriter? In which cases is each one generally used? --------------Solutions------------- XmlWriter is an abstract class of which XmlDictionaryWriter is one of the classes that inherits from it a

  • XMLReader from a string content 2010-12-23

    I'm trying to generate XML from another XML using a XslTransform. I get both files (source XML and XSL transformation file) as string content, so I'm trying to pass the XSL file to XslTransform.Load() method as XmlReader. Now the XmlReader has to be

  • Building an XML file iteratively with XmlWriter 2011-01-02

    I want to be able to use XmlWriter (C#, .NET) to create an XML document with multiple calls to a method that generates XML and then a single call to a final method that closes everything off. When I try to call this method multiple times: private voi

  • Output XML to ASP.NET TextBox with formatting using XmlWriter? 2011-02-28

    I am building an XML string programatically using the XmlWriter ... sb = New StringBuilder() writer = XmlWriter.Create(sb) writer.WriteStartDocument() writer.WriteStartElement("root") writer.WriteStartElement("element1") writer.WriteAttributeString("

Copyright (C), All Rights Reserved.

processed in 0.218 (s). 11 q(s)