Groups | Blog | Home
all groups > dotnet xml > november 2003 >

dotnet xml : XMLTextReaders only work on streams??


Christoph Schittko [MVP]
11/11/2003 8:45:01 PM
You can also pass any kind of TextReader to the XmlTextReader constructor,
such as the StreamReader or the StringReader.

The StringReader in particular seems to be what you are looking for:

string myXml = "<?xml version="1.0" ?><christoph>spends too much time on the
computer</christoph>";
XmlTextReader reader = new XmlTextReader( new StringReader( myXml ) );

// do all you XmlReader stuff here...

--
HTH
Christoph Schittko [MVP, XmlInsider]
Software Architect, .NET Mentor

[quoted text, click to view]

Chris Ericoli
11/12/2003 10:13:03 AM
Hi,

I am finding that quite commonly i need to instantiate an XML reader against
an in memory string, as opposed to a stream obtained from a file or URI.
While the XMLDocument class has a means of contructing against a string
(.LoadXML), i am unaware of any similar method for the xmlreaders, as they
all seem to require a stream, meaning that i have to create a stream from
the string etc..

Anybody aware of something I am missing.

Cheers

Chris

Chris Ericoli
11/13/2003 8:14:21 AM
Christoph..

Thanks for that - exactly what i needed.

Ta

Chris


"Christoph Schittko [MVP]" <christophdotnetINVALID@austin.rr.com> wrote in
message news:O4En5bMqDHA.2584@TK2MSFTNGP09.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button