Hi guys, sorry for being a pest, this is yet another post regarding XML::Rules. I'm just finishing the namespace support and would like to discuss it a bit before the public release. So that I can change the design if it doesn't sound right :-)

The way I've implemented the support is in short:

  1. remove the xmlns and xmlns:alias attributes automatically
  2. normalize the aliases used

What this means is that you (as the module user) specify what alias do you expect for what namespace and the module changes or adds the aliases used in the XML so that the <Foo> tag from the http://my.namespaces.com/foo namespace always invokes the 'foo:Foo' rule no matter whether it's written as

<Foo xmlns="http://my.namespaces.com/foo">...</Foo>
<root xmlns:f="http://my.namespaces.com/foo">... <f:Foo>...</f:Foo> </root>
or
<root xmlns="http://my.namespaces.com/foo">... <Foo>...</Foo> </root>

Does this sound like a sensible implementation to you?

The namespace support section of the docs follows:

=head1 Namespace support By default the module doesn't handle namespaces in any way, it doesn't + check for xmlns or xmlns:alias attributes and it doesn't strip or mangle the nam +espace aliases in tag or attribute names. This means that if you know for sure what n +amespace aliases will be used you can set up rules for tags including the alias +es and unless someone decides to use a different alias or makes use of the default n +amespace change your script will work. If you do specify any namespace to alias mapping in the constructor it + does start processing the namespace stuff. The xmlns and xmlns:alias attrib +utes are stripped from the datastructures and the aliases are transformed f +rom whatever the XML author decided to use to whatever your namespace mapp +ing specifies. Aliases are also added to all tags that belong to a default + namespace. Assuming the constructor parameters contain namespaces => { 'http://my.namespaces.com/foo' => 'foo', 'http://my.namespaces.com/bar' => 'bar', } and the XML looks like this: <root> <Foo xmlns="http://my.namespaces.com/foo"> <subFoo>Hello world</subfoo> </Foo> <other xmlns:b="http://my.namespaces.com/bar"> <b:pub> <b:name>NaRuzku</b:name> <b:address>at any crossroads</b:address> <b:desc>Fakt <b>desnej</b> pajzl.</b:desc> </b:pub> </other> </root> then the rules wil be called as if the XML looked like this: <root> <foo:Foo> <foo:subFoo>Hello world</foo:subfoo> </foo:Foo> <other> <bar:pub> <bar:name>NaRuzku</bar:name> <bar:address>at any crossroads</bar:address> <bar:desc>Fakt <b>desnej</b> pajzl.</bar:desc> </bar:pub> </other> </root> This means that the namespace handling will only normalize the aliases + used. It is possible to specify an empty alias, so eg. in case you are proce +ssing a SOAP XML and know the tags defined by SOAP do not colide with the tags in the e +nclosed XML you may simplify the parsing by removing all namespace aliases. If the XML references a namespace not present in the map you will get +a warning and the alias used for that namespace will be left intact!

Update 2007-2-12: Thanks for the lively discussion :-( The new version including this feature was just uploaded to CPAN.


In reply to XML::Rules (again) and namespace support by Jenda

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.