yaxo problem/question
Bijan Parsia
bparsia at email.unc.edu
Thu Jun 13 13:49:14 UTC 2002
On Thu, 13 Jun 2002, Rob Whitfield wrote:
> Hi Karl,
>
> I don't understand your comment. If I want an instance of an
> OrderedCollection I do:
>
> foo := OrderedCollection new.
Sure, but you *don't* want an instance of the parser.
At least, not to send #parseDocumentFrom: to.
#parseDocumentFromFileNamed: is a class method. In SAXHandler (the
superclass of XMLDOMParser) it returns an instance of a parser. That's
because, I take it, conceputally the parser is acting as a "lazy
stream" over the "parse" of the document.
In XMLDOMParser, #parseDocuemntFrom: returns an instance of the
*parsed* document.
Check the code:
parseDocumentFrom: aStream
^(super parseDocumentFrom: aStream) document
This is very natural for DOM work, since you expect to work with the
parsed document tree rather than a parser.
If you want to manipulate the parser itself, I suggest looking at
SAXHandler class>>parseDocumentFrom:
parseDocumentFrom: aStream
| driver parser |
driver _ SAXDriver on: aStream.
driver validating: true.
parser _ self new driver: driver.
parser startDocument.
parser parseDocument.
^parser
As you can see, it takes a bit more set up. And then you'll probably just
want to send "document' to this thing to get the full parsed document.
If you want to generate a different tree than an XMLDocument, you should
subclass SAXHandler (or XMLDOMParser if you want only a slightly different
tree).
> I can then add items to the collection using foo. How is XMLDOMParser
> different?
In one sense, isn't not different at all. But you *are* systematically
misusing it. You seem to not understand the difference between class
methods instance methods.
> Assuming you are right what would be the correct way of doing
> what I want?
It's still not clear to me what you want :)
Cheers,
Bijan Parsia.
More information about the Squeak-dev
mailing list
|