Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Perl module for RELAX NG?

by mattr (Curate)
on Dec 05, 2006 at 07:20 UTC ( #587803=perlquestion: print w/ replies, xml ) Need Help??
mattr has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, Slashdot just has a story up today, Tim Bray Says RELAX, about RELAX NG an originator of XML recommending the RELAX notation instead. He notes ATOM syndication format is based on RELAX.

However I couldn't find any perl tools on the software list or on cpan (except a parser in CORBA::XMLSchemas that makes RELAX files). There is a lot of RELAX in Java land though it seems.

Is there anything out there? I hate editing XML and always thought a natural language style notation would be much better. That wish is approximated by RELAX NG's "flattened schema" like this example from Wikipedia:

start = element book { page+ }
page = element page { text }

My only other question is whether this notation could be extended (if it doesn't allow it already) to include not just a schema but the data inside it. My guess is it would then look a bit like a data structure serialized into perl..

Comment on Perl module for RELAX NG?
Re: Perl module for RELAX NG?
by mirod (Canon) on Dec 05, 2006 at 08:37 UTC

    libxml2 supports RelaxNG, and XML::LibXML exposes part of its API (see XML::LibXML::RelaxNG, so you might want to look into it. If you find that you need more of the API, a little proding of the maintainer would probably get you what you want (sending patches would work even better ;--).

    I don't know about extending the notation though.

      Thank you very much, I'll check it out. Funny I've messed with libxml2 enough but never saw relax ng.
Re: Perl module for RELAX NG?
by SheridanCat (Pilgrim) on Dec 05, 2006 at 17:23 UTC
    My only other question is whether this notation could be extended (if it doesn't allow it already) to include not just a schema but the data inside it. My guess is it would then look a bit like a data structure serialized into perl..

    RELAX NG is just the grammar, right? It just describes the structure and content of an XML file. Putting data into it seems weird. Correct me if I'm wrong, I only started looking at RELAX NG over the past week or so.

    And doing serialization in XML seems like overkill to me. We already have YAML if you want portable and human-readable serialization. But, of course, there is more than one way to do it.

      Yes, you are right of course. I initially was mixed up over whether this was a replacement for just the schema definition or for XML itself too. I also thought YAML would be the choice then but RELAX seems to borrow from regular expressions which is nice, and I don't quite see how to link various YAML documents in a YAML stream to a RELAX definition.

      Actually I was most impressed that there are java tools that will generate classes based on RELAX NG definitions. Which made me think RELAX-like language might be very nice as a way to quickly define lots of things, like classes, db schemas, business logic, etc. I have to study it more to really understand how far it goes though. There are so many meta description languages out now for small domains so I had a hope. Not too long ago I was looking at some of the modules that help you design classes quickly in Perl but every module has its pros and cons of course. Thank you and all other posters.

        <shameless-plug> If you want a schema language for data structures written in a data structure, then take a look at Kwalify. Note that you can replace "data structure" in the above sentence by YAML file, JSON data, Data::Dumper dump or anything else dealing with (Perl) data structures.</shameless-plug>
Re: Perl module for RELAX NG?
by jhourcle (Prior) on Dec 05, 2006 at 19:49 UTC
    My only other question is whether this notation could be extended (if it doesn't allow it already) to include not just a schema but the data inside it. My guess is it would then look a bit like a data structure serialized into perl..

    It's for specifying the schema, such as with DTD or LDAP schema. If you're looking for transfering data, you probably want to look at YAML, JSON, WDDX or some other interchange format.

      Thanks I certainly will, YAML I've seen to some extent though there is probably more to learn, JSON is up on the top of my list. WDDX I have not had experience with yet. Thanks.
Re: Perl module for RELAX NG?
by shmem (Canon) on Dec 05, 2006 at 21:04 UTC
    Is there anything out there? I hate editing XML and always thought a natural language style notation would be much better.

    For natural style XML notation read the meditation tmoertel wrote some time ago about Embedding a mini-language for XML construction into Perl. The notation he came up with is very similar to RELAX.

    I've made a module out of his idea which I didn't publish. Code using it...

    I guess that could easily be tweaked (for some value of "easy" :-) to make a cool RELAX module...

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      Whoooweee! Wow, you don't mess around do you, ask for a rock and get a rocket back. Looks like it beats the heck out of Template::Toolkit doesn't it? Thank you for sharing your code. At the very least it makes html documents a lot easier for me to read and more concise. Great!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://587803]
Approved by BrowserUk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2014-09-22 12:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (191 votes), past polls