1. Feb 27th, 2007

    Validating XML documents with Ruby code

    A simple DSL to keep it short and simple, declarations to define the structure, and imperative code to handle that which can’t easily be declared. Just a rough sketch, but wouldn’t this be easier than half functional XML Schema?

    validate do
      email.optional
      phone.optional
      im_handle.optional
      raise "Must specify at least one means of contact" unless
       email || phone || im_handle
    
      address.required do
        street.required
        city.required
        state.optional
        country.optional :default=>"US"
        raise "State required for all addresses in the US" if
          country == "US" && !state
        raise "Zipcode does not match the rest of the address" if
          valid_zipcode?(street, city, state, country, zipcode)
      end
    
    end
    1. Feb 27th, 2007

      http://realfiction.net/

      Hi there,
      I will try out this OpenID feature of yours. Looks good!
      Anyway, your example looks a lot like RelaxNG, so have a look at http://relaxng.org. I don’t think support is great out there and the syntax is also XML (so no lovely rubycode), but there’s quite a bit of beef behind it.
      Cheers

    2. Feb 27th, 2007

      Dr Nic

      *sniff* That’s beautiful.

    Your comment, here ⇓

    Or using OpenID