Validing with an XSD in ruby

published: 06 Sep 2008 | tags:

    xml = generate_xml
    require 'xml'
    Tempfile.open(self.class.to_s) do |tmp|
      tmp.write(xml)
      tmp.close
      document = XML::Document.file(tmp.path)
      schema_doc = XML::Document.file("some.xsd")
      schema = XML::Schema.document(schema_doc)
      assert document.validate(schema), "the xml isn't valid.  look above for error."
    end