Re: [Zopexmlmethods-devel] Interface for XPathMethod?
Brought to you by:
arielpartners,
philikon
|
From: Philipp v. W. <ph...@we...> - 2003-06-09 16:38:20
|
Craeg Strong wrote:
> It seems that most processors have encapsulated
> XPath expressions in a type, and have a notion of
> pre-compiling them, all except for Sablotron.
That's why I would vote for this:
class IXPathProcessor(Interface):
def compile(expression):
"return compiled expression as IXPathExpression"
class IXPathExpression(Interface):
def evaluateString(xmlString, xmlURL, xpath):
"return result of xpath evaluation as string"
# doesn't have to be pretty printed
def evaluateDOM(xmlNode, xmlURL, xpath):
"return a list of DOM nodes matching xpath"
# yes, this would probably only be useful for 4Suite...
All except Sablotron would wrap their expression type in an object
implementing IXPathExpression. For Sablotron, that object simply stores
the expression in itself.
I think this makes it cleaner and people are used to this kind of
semantics for example from the re package (x = re.compile(...);
x.match(...))
> As a matter of fact, how about I start out implementing
> only FourSuite, and simply leave the other processors
> _not_ implementing IXPathProcessor for now.
Sounds good.
> That's interesting, because now we need to know both
>
> a) a compiletime notion of whether a particular
> processor supports feature X (either yes, no, or
> yes but we haven't implemented it yet)
>
> b) a runtime notion of whether a particular processor
> is currently installed
>
> For (a) I guess we just say
> if IXPathProcessor.isImplementedBy(processor):
> # try it...
Well, since we're going into the guts of ProcessorChooser anyway, I vote
for turning ProcessorChooser into ProcessorRegistry (doesn't have to be
renamed, although I would favour it), which would work similar to my
GeneratorRegistry.
It just provides a facility to register processor and query them
according to certain implementation features. I think we should not
query for strings like 'xslt', 'xpath', 'dtd', but for interfaces
(IXSLTProcessor, IXPathProcessor, etc.). That way we solve your issue a)
right at its root and b) becomes obsolent, because processors register
themselves (like my object Generators).
Thoughts?
Philipp
|