MemoryConduit

John Demme me at teqdruid.com
Tue Feb 13 22:23:08 PST 2007


Alberto wrote:

> I can write xml on buffer/file without  problems, but I have some little
> problem parsing an xml from a buffer.
> This is part of the sax example:
> 
> void readerTest3()
> {
> ISAXReader!(T) reader = new TeqXMLReader!(T)(256);
> FileConduit file = new FileConduit("sample-32BE.xml",
> FileConduit.ReadExisting);
> MyOutputHandler handler = new MyOutputHandler();
> reader.parse(file, handler, Encoding.UTF_32);
> }
> 
> I read the sax source:
> /**
>    All SAX parsers must implement this interface.
>  */
> interface ISAXReader(T=char) {
>   /**
> Tells the parser to begin processing a document
> 
> Params:
> source =      The IConduit that the parser should draw xml content from
> handler =     The client interface who's methods the parser should call
> encoding =    If the client knows it, tell the parser the text encoding
> of the incoming XML.
> If not specified, the parser will guess, and failing that assume
> UTF8N.  The
> enum for these types is in mango.convert.Unicode.
> */
> public void parse(IConduit source, ISAXHandler!(T) handler, Encoding
> encoding=Encoding.Unknown);
> }
> 
> I must pass a conduit, ok.
> I have tried to use MemoryConduit (I suppose that is the right way to do
> what I want) but without success, something like:
> 
> char[] msg = "blabla";
> char[] xml;
> auto mc = new MemoryConduit();
> auto write = new Writer (mc);
> auto read = new Reader (mc);
> write (msg);
> xml.length = msg.length;
> read (xml);
> Stdout(xml);
> mc.close();
> 
> this give me:
> end-of-file whilst reading
> 
> I can't use the method writer because is not accessible, so how can I
> use MemoryConduit?

I just added support today for reader.parse(IBuffer).

Have fun :)

-- 
~John Demme
me at teqdruid.com
http://www.teqdruid.com/


More information about the Digitalmars-d-learn mailing list