Hi
here is the example on LWM:
CL-USER 17 > (cxml:parse #P"CellCycle-1991Tys-2.xml" (cxml:make-whitespace-normalizer (make-instance 'sax:default-handler)) :validate nil) NIL
CL-USER 18 > (with-open-file (f #P"CellCycle-1991Tys-2.xml" :direction :input) (cxml:parse f (cxml:make-whitespace-normalizer (make-instance 'sax:default-handler)) :validate nil))
Error: Binary operation READ-BYTE attempted on character stream #<STREAM::LATIN-1-FILE-STREAM /Users/marcoxa/Projects/Genomics/biolosyst/sbmlambda/tests/CellCycle-1991Tys-2.xml>. 1 (abort) Return to level 0. 2 Return to top loop level 0.
Type :b for backtrace or :c <option number> to proceed. Type :bug-form "<subject>" for a bug report template or :? for other options.
CL-USER 19 : 1 >
And here is the doc string for cxml:parse
"@arg[input]{A string, pathname, octet vector, or stream.} @arg[handler]{A @class{SAX handler}} @arg[validate]{Boolean. Defaults to @code{nil}. If true, parse in validating mode, i.e. assert that the document contains a DOCTYPE declaration and conforms to the DTD declared.} ... @arg[recode]{Boolean. (Ignored on Lisps with Unicode support.) Recode rods to UTF-8 strings. Defaults to true. Make sure to use @fun{utf8-dom:make-dom-builder} if this option is enabled and @fun{rune-dom:make-dom-builder} otherwise.} @return{The value returned by @fun{sax:end-document} on @var{handler}.}
Parse an XML document from @var{input}, which can be a string, pathname, octet vector, or stream. ... All SAX parsing functions share the same keyword arguments. Refer to @fun{parse} for details on keyword arguments."
It appears that you need a 'xstream', but this is against the doc string content (and IMHO, against common sense).
Cheers
-- Marco Antoniotti
Hi,
Quoting Marco Antoniotti (marcoxa@cs.nyu.edu):
here is the example on LWM:
what is LWM?
CL-USER 17 > (cxml:parse #P"CellCycle-1991Tys-2.xml" (cxml:make-whitespace-normalizer (make-instance 'sax:default-handler)) :validate nil) NIL
CL-USER 18 > (with-open-file (f #P"CellCycle-1991Tys-2.xml" :direction :input) (cxml:parse f (cxml:make-whitespace-normalizer (make-instance 'sax:default-handler)) :validate nil))
Error: Binary operation READ-BYTE attempted on character stream #<STREAM::LATIN-1-FILE-STREAM /Users/marcoxa/Projects/Genomics/biolosyst/sbmlambda/tests/CellCycle-1991Tys-2.xml>. 1 (abort) Return to level 0. 2 Return to top loop level 0.
[...]
Parse an XML document from @var{input}, which can be a string, pathname, octet vector, or stream.
[...]
It appears that you need a 'xstream', but this is against the doc string content (and IMHO, against common sense).
Not an xstream, no (those are internal to cxml and would only be used very rarely by user code).
What you need is a _binary_ stream though (and the docstring could indeed be improved to say "octet vector, or octet stream" rather than just "octet vector, or stream".
In other words, add :element-type '(unsigned-byte 8) to the with-open-file.
d.
On Apr 21, 2011, at 15:06 , David Lichteblau wrote:
Hi,
Quoting Marco Antoniotti (marcoxa@cs.nyu.edu):
here is the example on LWM:
what is LWM?
Lispworks Mac
CL-USER 17 > (cxml:parse #P"CellCycle-1991Tys-2.xml" (cxml:make-whitespace-normalizer (make-instance 'sax:default-handler)) :validate nil) NIL
CL-USER 18 > (with-open-file (f #P"CellCycle-1991Tys-2.xml" :direction :input) (cxml:parse f (cxml:make-whitespace-normalizer (make-instance 'sax:default-handler)) :validate nil))
Error: Binary operation READ-BYTE attempted on character stream #<STREAM::LATIN-1-FILE-STREAM /Users/marcoxa/Projects/Genomics/biolosyst/sbmlambda/tests/CellCycle-1991Tys-2.xml>. 1 (abort) Return to level 0. 2 Return to top loop level 0.
[...]
Parse an XML document from @var{input}, which can be a string, pathname, octet vector, or stream.
[...]
It appears that you need a 'xstream', but this is against the doc string content (and IMHO, against common sense).
Not an xstream, no (those are internal to cxml and would only be used very rarely by user code).
What you need is a _binary_ stream though (and the docstring could indeed be improved to say "octet vector, or octet stream" rather than just "octet vector, or stream".
In other words, add :element-type '(unsigned-byte 8) to the with-open-file.
Ok. But the file is not a binary file.
Marco
d.
-- Marco Antoniotti
Quoting Marco Antoniotti (marcoxa@cs.nyu.edu):
Ok. But the file is not a binary file.
The fundamental reason XML files need to be processed using binary streams instead of character streams in (portable) Common Lisp is that an XML parser needs to read the first few bytes before it can know which external format to parse the file as.
Implemented using a Common Lisp character stream, that would require a switch of the external format in the middle, using (setf stream-external-format). But that function doesn't exist in portable Lisp. (One of the few Lisps that supports it is Allegro with its simple-streams, but we aim to support more Lisps than just Allegro. We also aim for more speed than typical gray streams-based implementations of this idea offer.)
d.