|
List Info
Thread: Proposal: SAX filter for conditional XML
|
|
| Proposal: SAX filter for conditional XML |

|
2007-06-03 09:11:02 |
I have a requirement to process some XML with conditional
constructs in,
looking somewhat like the following:
<message>
<switch cond="today()">
<case value="tuesday">Today is
Tuesday</case>
<case value="wednesday">Today is
Wednesday</case>
<otherwise>Today is neither Tuesday nor
Wednesday</otherwise>
</switch>
</message>
I have managed to write this as a SAX filter, which removes
the actual
<switch>, <case> and <otherwise> elements,
and all of the contents of any
<case> node that doesn't match.
The actual evaluation of the condition expression, and
matching it to one
of the cases, is done in specific methods, that allow for a
generic
implementation, leaving the specifics to some subclass being
used in an
application.
I couldn't find anything on CPAN that looked like it does
this already,
so I would like to propose to create such a module; likely
called
XML::Filter::Conditional
unless anyone has any objections, or better suggestions.
--
Paul "LeoNerd" Evans
leonerd leonerd.org.uk
ICQ# 4135350 | Registered Linux# 179460
http://www.leonerd.org.uk/
_______________________________________________
Perl-XML mailing list
Perl-XML listserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs
|
|
| Re: Proposal: SAX filter for conditional
XML |

|
2007-06-06 16:09:50 |
On Sun, 3 Jun 2007 15:11:02 +0100
Paul LeoNerd Evans <leonerd leonerd.org.uk> wrote:
> I couldn't find anything on CPAN that looked like it
does this already,
> so I would like to propose to create such a module;
likely called
>
> XML::Filter::Conditional
>
> unless anyone has any objections, or better
suggestions.
Given the complete lack of any objection, I have started
writing up the
code with a full CPAN wrapper around it; test scripts and
the like.
I've not managed to find a particularly nice way of doing
the tests; the
best so far I can do, is to build an array of all the method
calls the
'consumer' received, then run lots of assertions on the
values in that
array - see attached files.
Is this a good idea? Does anyone have any better ways of
doing this?
I wanted to avoid pulling in XML::SAX::Writer and asserting
on the built
strings, because this seemed to me to have a number of
issues with it.
--
Paul "LeoNerd" Evans
leonerd leonerd.org.uk
ICQ# 4135350 | Registered Linux# 179460
http://www.leonerd.org.uk/
_______________________________________________
Perl-XML mailing list
Perl-XML listserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs
|
|
|
|
| Re: Proposal: SAX filter for conditional
XML |
  New Zealand |
2007-06-06 17:43:07 |
On Wed, 2007-06-06 at 22:09 +0100, Paul LeoNerd Evans wrote:
> On Sun, 3 Jun 2007 15:11:02 +0100
> Paul LeoNerd Evans <leonerd leonerd.org.uk> wrote:
>
> > I couldn't find anything on CPAN that looked like
it does this already,
> > so I would like to propose to create such a
module; likely called
> >
> > XML::Filter::Conditional
> >
> > unless anyone has any objections, or better
suggestions.
>
> Given the complete lack of any objection, I have
started writing up the
> code with a full CPAN wrapper around it; test scripts
and the like.
I did give your question some thought, but failed to come up
with a
better name. There is some conceptual overlap with the
PETAL templating
tool. If your filter acquired some of PETAL's other
functionality then
it might outgrow the name 'Conditional'. I do like the idea
of
delegating the evaluation of the condition to the user's
Perl code.
> I've not managed to find a particularly nice way of
doing the tests; the
> best so far I can do, is to build an array of all the
method calls the
> 'consumer' received, then run lots of assertions on the
values in that
> array - see attached files.
>
> Is this a good idea? Does anyone have any better ways
of doing this?
I have used that approach and it's not without traps. If
you focus on
just the method calls you care about then you should be OK,
but the
different SAX parsers do have subtle differences in the
detail and order
of the events they generate.
> I wanted to avoid pulling in XML::SAX::Writer and
asserting on the built
> strings, because this seemed to me to have a number of
issues with it.
I'd be inclined towards a solution based around SAX writer
and using
XPath for your assertions. Rather than pull in the writer
module, you
could just make your test conditional on the availability
of
XML::SAX::Writer and a suitable XPath engine. Anyone who
was seriously
using the module is likely to have both. But if they didn't
then the
tests would simply be skipped.
Cheers
Grant
_______________________________________________
Perl-XML mailing list
Perl-XML listserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs
|
|
| Re: Proposal: SAX filter for conditional
XML |

|
2007-06-08 11:03:51 |
On Thu, Jun 07, 2007 at 10:43:07AM +1200, Grant McLean
wrote:
> I have used that approach and it's not without traps.
If you focus on
> just the method calls you care about then you should be
OK, but the
> different SAX parsers do have subtle differences in the
detail and order
> of the events they generate.
OK, with that in mind, I've come up with a slightly changed
version,
that ignores certain declared method names, and captures
certain others.
The AUTOLOAD then fails for anything else.
Also I've got it to merge consequetive 'characters' methods,
in case
some parser happens to throw more than one for some files.
See new attached.
If you think that looks better, I shall continue to write my
tests on
that base...
--
Paul "LeoNerd" Evans
leonerd leonerd.org.uk
ICQ# 4135350 | Registered Linux# 179460
http://www.leonerd.org.uk/
_______________________________________________
Perl-XML mailing list
Perl-XML listserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs
|
|
| Re: Proposal: SAX filter for conditional
XML |

|
2007-06-13 08:39:05 |
On Sun, Jun 03, 2007 at 03:11:02PM +0100, Paul LeoNerd Evans
wrote:
> I couldn't find anything on CPAN that looked like it
does this already,
> so I would like to propose to create such a module;
likely called
>
> XML::Filter::Conditional
>
> unless anyone has any objections, or better
suggestions.
I've now created an initial CPAN wrapper for this module.
Before I
upload it, I'll post it here first, in case anyone has any
suggestions
on things to change.
Items still on my TODO list:
* Make ->store_switch optional, by having it simply
return $e if it is
not present.
* Allow a simpler access to attributes in the same
namespace as the
switch/case tags, probably by a simple hashref of
attribute name =>
value passed in to the methods.
* Add another tuneable, that disallows
"interposed" content, between
the <switch> and <case> tags, surpressing
any whitespace or comments
found there, and throwing an exception if anything else
appears.
Should make for neater output.
--
Paul "LeoNerd" Evans
leonerd leonerd.org.uk
ICQ# 4135350 | Registered Linux# 179460
http://www.leonerd.org.uk/
_______________________________________________
Perl-XML mailing list
Perl-XML listserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs
|
|
|
[1-5]
|
|