Re: DOM LS: DOMParserFilter vs. DOMParser.parseWithContext's action argument

Christian Parpart wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hello,
> 
> well, I still have this problem, and no one replied to the very earlier post 
> that included this issue, so I'll ask in a single post again :)

Sorry for the delay on this, hopefully this will clear things up for you.

> 
> DOMParserFilter.startElement() and DOMParserFilter.acceptNode() are to be 
> invoked by the DOMParser while parsing the input. 
> DOMParser.parseWithContext() gets an addition action parameter that decides 
> how to handle the parsed context.
> 
> So, there are some things not very clear for me:
> if FILTER_ACCEPT is returned, the action parameter is to be handled
> if FILTER_REJECT is returned, the action parameter is ignored(?)
> if FILTER_SKIP is returned, how to handle the action parameter?
> if FILTER_INTERRUPT is returned, how to handle the action parameter?

There's not really any relationship between the actions that are 
returned from the filter and the action that's passed to 
parseWithContext(), thinking that there is a relationship between the 
two only confuses things, at least in my mind.

Try to think of the parsing process (in this case, when calling 
parseWithContext()) as a synchronous pipeline that executes as follows. 
You have a piece of XML, it's tokenized n' so on, then a DOM node is 
created (attributes are set, etc), the filter is called, and you either 
use that DOM node or not, depending on what the filter told you. Once 
you've done that for all of the data that's passed to 
parseWithContext(), you have a set of nodes, take that set of nodes and 
perform the action that's passed to parseWithContext().

The one thing that is *not* defined in the spec (I just noticed when 
reading some filter definitions when explaining this) is what happens to 
the node that's passed to the filter if FILTER_INTERRUPT is returned, 
does it get included in the resulting DOM tree or not? I intend to 
define that such that returning FILTER_INTERRUPT from startElement() 
causes the element to be rejected, but returning FILTER_INTERRUPT from 
endNode() causes the node to be included in the resulting document. I 
think that gives users the most felxibility with this API.

> Furthermore, what exactly is a "context"? Will parseWithContext only parse a 
> single Element node (including all child nodes)? Or can is parse more? If so, 
> what? And, how many?

A "context" is merely a node that's used as a reference point to know 
where to put the result of parseWithContext(), and as the spec states, 
it's also used to resolve namespaces etc.

As for what parseWithContext() can parse, the spec says "Parse an XML 
fragment...", that can be any well-formed fragment of XML, i.e. any 
number of elements, as long as the tree is balanced, or just a text 
node, and so on. Let me know if you feel this needs further 
clarification in the spec, and suggestions are very welcome, as always.

> 
> Many thanks,
> Christian Parpart.
> 
> - -- 
>  02:46:18 up 78 days, 17:49,  2 users,  load average: 0.12, 0.05, 0.05
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.2 (GNU/Linux)
> 
> iD8DBQE/MaTIPpa2GmDVhK0RArxIAJ9tRkb+Of9UTF+cijpj7K5yNrj0+ACcCCjV
> NdQU3SkUiwY6Tktsl3ZjtsM=
> =aN5S
> -----END PGP SIGNATURE-----
> 

-- 
jst

Received on Tuesday, 9 September 2003 22:04:09 UTC