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

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.
  • Have you tried to combine Schematron with RELAX NG? It’s quite easily possible, as RNG has extension points that allow for such an undertaking, and Schematron gives you rule- as opposed to grammar-based validation. In short, Schematron rules are arbitrary XPath expressions that must match/be true in the contexts you specify for them. Particularly with suitable XPath extension functions, that lets you validate pretty much any kind of constraint whatsoever.

    (You can also use Schematron standalone, but

    • Actually, I have trang installed and used that to convert the compact grammar to XML. I had stuff like this:

      element card {

          ## if: defined $card->revision
          attribute revision { xsd:positiveInteger }?,
          element name    { xsd:string },
          element email   { xsd:string },

          ## method: phone_numbers
          element phone   { xsd:string }*
      }

      And it was getting converted to this:

      <?xml version="1.0" encoding="UTF-8"?>
      <element name="card" xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
        <optional>
          <attribute name="revision">
            <a:documentation>if: defined $card-&gt;revision</a:documentation>
            <data type="positiveInteger"/>
          </attribute>
        </optional>
        <element name="name">
          <data type="string"/>
        </element>
        <element name="email">
          <data type="string"/>
        </element>
        <zeroOrMore>
          <element name="phone">
            <a:documentation>method: phone_numbers</a:documentation>
            <data type="string"/>
          </element>
        </zeroOrMore>
      </element>

      And I was using XML::LibXML to break that down into a data structure, but it was getting rather ugly. With YAML, I get the data structure for free. I have to say, though, that I didn't look at Schematron. I've never used it before.

      Currently I have almost all of the basics in place for what I'm doing, so I'm not likely to switch now. However, I've clearly separated out my parser from everything else. As a result, if I ever need to switch to another parsing system, it should be trivial once the other parser is written. (Heh. Famous last words.)