Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Thursday February 28, 2008
10:40 AM

Bermuda RelaxNG Generation Started

[ #35787 ]

After Aristotle explained to me that there's no reasonable way I can auto-generate JSON and YAML from the same Bermuda island file which defines the XML output format, I've decided to stop work on that for a while. Instead, I'm focusing my energy on the XML work. Today I've normalized the attribute and element island syntax. They're the same, except that the only quantifier allowed on an attribute is '?' (optional). Then I turned to RelaxNG generation.

This island:

---
package: My::Card
island: card
name: card
attributes:
  - href:
      type: anyURI
      method: url
  - revision?:
      if: 'defined $instance->revision'
      type: positiveInteger
elements:
  - name:
      type: string
      attributes:
        some_attr:
          method: dummy_attribute
  - email*:
      type: string
  - phone+:
      method: phone_numbers
      type: string
  - active:
      data: yes

Allows you to automatically generate this xml from an object:

<?xml version="1.0" encoding="utf-8"?>
<card revision="3" href="http://www.example.com/">
  <name some_attr="foo">John Smith</name>
  <email>js@example.com</email>
  <email>js2@example.com</email>
  <phone>111</phone>
  <phone>222</phone>
  <active>yes</active>
</card>

But it also generates RelaxNG which properly validates that XML:

<?xml version="1.0" encoding="UTF-8"?>
<element name="card" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-da
  <attribute name="href">
    <data type="anyURI"/>
  </attribute>
  <optional>
    <attribute name="revision">
      <data type="positiveInteger"/>
    </attribute>
  </optional>
  <element name="name">
    <attribute name="some_attr">
      <text/>
    </attribute>
    <data type="string"/>
  </element>
  <zeroOrMore>
    <element name="email">
      <data type="string"/>
    </element>
  </zeroOrMore>
  <oneOrMore>
    <element name="phone">
      <data type="string"/>
    </element>
  </oneOrMore>
  <element name="active">
    <value>yes</value>
  </element>
</element>

Yeah, I have a lot more work to do (like switching to full grammars), but this is coming along nicely.

Currently we default to UTF8, but that's easy to change. Also, I don't yet have "includes" to reference another island. That might take some major reworking of the XML to get that right, but I want to refactor a lot more of what I'm doing in order to make this workable.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.