AW: [Xml-compile] Using the DOM built by the toolkit

Michael Ludwig m.ludwig at epages.com
Mon Feb 20 11:01:40 GMT 2012


> Von: Mark Overmeer
> * Michael Ludwig (m.ludwig at epages.com) [120220 10:00]:

> > Let's say I also want the DOM directly to apply an XSL
> > transformation. What's the best way to obtain a reference to
> > the DOM already built?
> 
> If you can convince me that this DOM-tree has a use, I could add that
> to the ::Trace object.  It will only delay the moment of destruction
> of the tree, so is not a performance hit... but probably there is a
> better way to satisfy your real need.

Well, the need ist to get an HTML report of the data I receive via the
web service. The best way to produce one from XML is to apply an XSL
transformation. This is done using libxslt, the companion library to
libxml2. The Perl interface is XML::LibXSLT, and it works very well.
You need to supply a libxml2 DOM as input to the transformation.

As your toolkit has already done the work of parsing the XML and
producing the DOM, you might just as well make it available for
downstream processing (on a par with the HTTP request and response
objects). All those objects are by-products of the work done by your
toolkit. Making them available for downstream processing might seem
odd from the vantage point of your toolkit, which transforms the XML
into a Perl data structure; but not so odd if you consider that there
are powerful toolchains that work on those HTTP and DOM objects.

As far as I can see, the moment you're returning the Trace object to
the user your toolkit is done using the DOM for its own purposes, so
even in case the user manipulated the DOM (which XSLT doesn't do)
there'd be no bad consequences for your toolkit.

Let me know if it takes more to convince you of the utility of this
approach.

> The implementation would be to change this in XML/Compile/Transport.pm
> 
>     if($textin)
>   - {   $xmlin = eval {$parser->parse_string($$textin)};
>   + {   $xmlin = $trace->{xmlin} = eval {$parser->parse_string($$textin)};
>         $trace->{error} = $@ if $@;
>     }

And what about adding an accessor for the DOM?

  $obj->request     # already there
  $obj->response    # ditto
  $obj->dom         # new!

https://metacpan.org/module/XML::Compile::SOAP::Trace

Michael



More information about the Xml-compile mailing list