When perfection isn’t good enough
One of the many possible problems with using CPAN modules is that they often just implement the parts of the problems the author needed a solution for. But once in a while you run into the opposite problem: The module implements parts of a standard that you just don’t want.
Some time ago I had to parse parts of the WebDAV protocol. WebDAV properties are transmitted using XML with namespaces, which is one thing I think XML::Simple is particular bad for. So I turned to XML::LibXML (which is becoming my XML module of choice either way).
So, the WebDAV RFC have examples like this:
<?xml version="1.0" encoding="utf-8" ?>
<D:propfind xmlns:D="DAV:">
<D:prop xmlns:R="http://ns.example.com/boxschema/">
<R:bigbox/>
<R:author/>
<R:DingALing/>
<R:Random/>
</D:prop>
</D:propfind>
Unfortunately XML::LibXML insists on namespace URI’s to conform to the URI specification, which DAV: doesn’t. Due to XML::LibXML’s perfection I’m not able to just use it. Solution:
sub escapeNamespace {
$_[0] =~ s/(xmlns(?::\w+)?)="(?!urn|http)([^"]+)"/$1="urn:xxx:$2"/g;
$_[0] =~ s/(xmlns(?::\w+)?)=""/$1="urn:xxx:nonamespace"/g;
}
I’m not quite sure that the second substitution is needed by the standard, but the Litmus webdav test suite needs it…
Henning Makholm said,
June 2, 2009 @ 1:41 pm
Just hope you don’t need to communicate with someone who use single quotes for attribute values …
Peter Makholm said,
June 2, 2009 @ 1:59 pm
Don’t worry. My real code is almost twice as long.
Matt S Trout said,
June 3, 2009 @ 2:07 am
If you’re interested, I have a Catalyst::Action::DAV that includes a version of Net::DAV::Server with significant fixes – I never quite sorted out the CPAN permissions since the client’s needs changed. If it’s any use to you, mail mst shadowcat.co.uk and I’ll hook you up with a commit bit.