How do you convert a String object to stream (type) object?
I know it is more common to do the conversion in the other direction, but for me it is definitely the other way.
I have a web service input parameter of Type string. this parameter is actually an XML document payload. why this is so is a long story.
Anyway, I need to validate it. I 've written XML validation code in the past. The one real stumbling block here ISD this data type conversion.
I'm at a bit of a loss how to do this. ultimately I need to get the data into an xmlreader object coupled with the xmlreadersettings object (this is. NET 2.0 Asp.net APP ). looking at the object model for various system. XML namespace objects this does not appear to be a straightforward task.
Short of writing the string to disk and then opening it up with a filestream object, there's got to be a better way. Anyone have a better idea?
Thanks!
Mr bungle
Tuesday, July 18,200 6
Deleting... Approving...
Implement a class derived from stream, I. e. Declare a stringstream class, use your string to construct it, and implement the various abstract methods declared in stream such as read and canwrite. Christopher Wells
Tuesday, July 18,200 6
Deleting... Approving...
Use the stringreader class, e.g.
String xmltext =... Your XML ...;
Xmlreadersettings settings =... your settings ...;
Stringreader = new stringreader (xmltext );
Xmltextreader xmlreader = xmlreader. Create (stringreader, settings );
... Joe
Wednesday, July 19,200 6
Deleting... Approving...
There is also the memorystream object, convert your string into an array of bytes and write directly into the memorystream.
Memorystream memstream = new memorystream ();
Byte [] DATA = encoding. Unicode. getbytes (thestring );
Memstream. Write (data, 0, Data. Length );Foxedup
Wednesday, July 19,200 6
Deleting... Approving...
The system. Io. stringreader object worked like a charm and just required a single line of additional code. What a relief! Thanks for all the helpful replies. Mr bungle
Wednesday, July 19,200 6
Deleting... Approving...
This topic is archived. No further replies will be accepted.