digitalmars.D.learn - MemoryConduit
- Alberto (47/47) Feb 13 2007 I can write xml on buffer/file without problems, but I have some little
- kris (18/72) Feb 13 2007 It's not quite clear what you wish to do, but I'll have a go? First,
- Alberto (9/17) Feb 13 2007 because they didn't work for me, (some strange error on compile), now
- kris (2/20) Feb 13 2007 What tool are you using to build your project?
- Alberto (6/7) Feb 13 2007 I'm using build (bud) under windows (the project must works on windows :...
- kris (6/17) Feb 13 2007 Yep, I removed that as simply being unnecessary coupling.
- Alberto (19/20) Feb 13 2007 Now I can compile every tango example without problems with build, but
- John Reimer (8/33) Feb 14 2007 I actually think I'll have to remove the build-all.bat eventually becaus...
- kris (7/9) Feb 13 2007 The reason for the Eof is that you need to flush the output first. In
- John Demme (7/61) Feb 13 2007 I just added support today for reader.parse(IBuffer).
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?
Feb 13 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?It's not quite clear what you wish to do, but I'll have a go? First, it's worth cleaning up a bit using "auto": void readerTest3() { auto handler = new MyOutputHandler; auto reader = new TeqXMLReader!(T)(256); auto file = new FileConduit ("sample-32BE.xml"); reader.parse (file, handler, Encoding.UTF_32); } Now the questions: 1) why do you require MemoryConduit? Have you constructed some in-memory XML for parsing? 2) it's not clear why you're using protocols for this (Reader/Writer) when you can use mc.write(void[]) and/or mc.read(void[]) 3) is there a version of reader.parse() that accepts a Buffer instance instead? If not, then there probably ought to be (since it would save you some effort).
Feb 13 2007
1) why do you require MemoryConduit? Have you constructed some in-memory XML for parsing?yes, I must transfer xml file using POST method of HTTP (text/xml). So a servlet of my HTTP server (I use mango) read the xml and must parse it.2) it's not clear why you're using protocols for this (Reader/Writer) when you can use mc.write(void[]) and/or mc.read(void[])because they didn't work for me, (some strange error on compile), now that I have downloaded the last version from svn, mc.write(void[]) works. With that my problem with MemoryConduit is solved. But now tango give me an error when I include tango.io.FileConduit. c:\dmd\tango\tango\io\FileProxy.obj(FileProxy) Error 42: Symbol Undefined _D12TypeInfo_AAa6__initZ3) is there a version of reader.parse() that accepts a Buffer instance instead? If not, then there probably ought to be (since it would save you some effort).no, I didn't find it.
Feb 13 2007
Alberto wrote:What tool are you using to build your project?1) why do you require MemoryConduit? Have you constructed some in-memory XML for parsing?yes, I must transfer xml file using POST method of HTTP (text/xml). So a servlet of my HTTP server (I use mango) read the xml and must parse it.2) it's not clear why you're using protocols for this (Reader/Writer) when you can use mc.write(void[]) and/or mc.read(void[])because they didn't work for me, (some strange error on compile), now that I have downloaded the last version from svn, mc.write(void[]) works. With that my problem with MemoryConduit is solved. But now tango give me an error when I include tango.io.FileConduit. c:\dmd\tango\tango\io\FileProxy.obj(FileProxy) Error 42: Symbol Undefined _D12TypeInfo_AAa6__initZ
Feb 13 2007
What tool are you using to build your project?I'm using build (bud) under windows (the project must works on windows :\) Of course I'm using lastest tango+mango. io 1676 2 hours kris: removed FileProxy? dependency from FileConduit?; was just overhead Ater the last update of tango all works. Thanks.
Feb 13 2007
Alberto wrote:Yep, I removed that as simply being unnecessary coupling. But that should not have affected your build in any legitimate manner. Everyone else has been building and linking these modules for ages and not run into a problem. I'd like to get to the bottom of it ... Would imagine you'll have some difficulty building the examples?What tool are you using to build your project?I'm using build (bud) under windows (the project must works on windows :\) Of course I'm using lastest tango+mango. io 1676 2 hours kris: removed FileProxy? dependency from FileConduit?; was just overhead Ater the last update of tango all works. Thanks.
Feb 13 2007
Would imagine you'll have some difficulty building the examples?Now I can compile every tango example without problems with build, but with the build-all.bat I have some problem. for example, if I did something like (cutted from build.all): C:\dmd\tango\example> dmd conduits\composite.d ..\tango\io\protocol\Reader.d ..\tango\io\Buffer.d ..\tango\io\model\IBuffer.d ..\tango\io\model\IConduit.d ..\tango\io\protocol\model\IReader.d ..\tango\io\protocol\model\IProtocol.d ..\tango\io\protocol\Writer.d ..\tango\io\FileConst.d ..\tango\io\protocol\model\IWriter.d ..\tango\io\FileConduit.d ..\tango\sys\Common.d ..\tango\io\FileProxy.d ..\tango\io\FilePath.d ..\tango\text\convert\Utf.d ..\tango\io\DeviceConduit.d ..\tango\io\Conduit.d -I.. -op I get: ..\tango\io\FileProxy.obj(FileProxy) Error 42: Symbol Undefined _D5tango4util4time3Utc3Utc7convertFS5tango3sys5win325Types8FIL ETIMEZE5tango4core4Type4Time --- errorlevel 1 The same happens with system\argparser.d and all other conduits examples.
Feb 13 2007
On Wed, 14 Feb 2007 01:40:26 +0100, Alberto wrote:I actually think I'll have to remove the build-all.bat eventually because, if you are using the svn latest code, the code changes end up rendering build-all quite useless. It the meantime, if you use windows, you can use the jake version of it (jake-all.bat) and it sould succeed. rebuild also appears to work well. I haven't tried bud, but it will probably work too. -JJRWould imagine you'll have some difficulty building the examples?Now I can compile every tango example without problems with build, but with the build-all.bat I have some problem. for example, if I did something like (cutted from build.all): C:\dmd\tango\example> dmd conduits\composite.d ..\tango\io\protocol\Reader.d ..\tango\io\Buffer.d ..\tango\io\model\IBuffer.d ..\tango\io\model\IConduit.d ..\tango\io\protocol\model\IReader.d ..\tango\io\protocol\model\IProtocol.d ..\tango\io\protocol\Writer.d ..\tango\io\FileConst.d ..\tango\io\protocol\model\IWriter.d ..\tango\io\FileConduit.d ..\tango\sys\Common.d ..\tango\io\FileProxy.d ..\tango\io\FilePath.d ..\tango\text\convert\Utf.d ..\tango\io\DeviceConduit.d ..\tango\io\Conduit.d -I.. -op I get: ..\tango\io\FileProxy.obj(FileProxy) Error 42: Symbol Undefined _D5tango4util4time3Utc3Utc7convertFS5tango3sys5win325Types8FIL ETIMEZE5tango4core4Type4Time --- errorlevel 1 The same happens with system\argparser.d and all other conduits examples.
Feb 14 2007
Alberto wrote:this give me: end-of-file whilst readingThe reason for the Eof is that you need to flush the output first. In Tango pretty much all IO above the level of a Conduit is buffered, so you'd need to do this: or
Feb 13 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 teqdruid.com http://www.teqdruid.com/
Feb 13 2007