{"id":16102357,"url":"https://github.com/sshaw/ruby-jing","last_synced_at":"2025-08-16T16:33:05.157Z","repository":{"id":10370033,"uuid":"12512941","full_name":"sshaw/ruby-jing","owner":"sshaw","description":"RELAX NG schema validation in Ruby using the Jing CLI","archived":false,"fork":false,"pushed_at":"2022-06-23T02:49:01.000Z","size":621,"stargazers_count":3,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-27T19:50:04.355Z","etag":null,"topics":["java","relaxng","ruby","schema-validation","xml"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sshaw.png","metadata":{"files":{"readme":"README.rdoc","changelog":"Changes","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-31T23:16:31.000Z","updated_at":"2021-10-17T03:41:44.000Z","dependencies_parsed_at":"2022-09-04T23:50:19.304Z","dependency_job_id":null,"html_url":"https://github.com/sshaw/ruby-jing","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Fruby-jing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Fruby-jing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Fruby-jing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sshaw%2Fruby-jing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sshaw","download_url":"https://codeload.github.com/sshaw/ruby-jing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229805750,"owners_count":18126902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","relaxng","ruby","schema-validation","xml"],"created_at":"2024-10-09T18:53:38.290Z","updated_at":"2024-12-17T00:43:58.021Z","avatar_url":"https://github.com/sshaw.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"= Ruby Jing\n\n{\u003cimg src=\"https://github.com/sshaw/ruby-jing/actions/workflows/rake.yml/badge.svg\"/\u003e}[https://github.com/sshaw/ruby-jing/actions/workflows/rake.yml]\n{\u003cimg src=\"https://codeclimate.com/github/sshaw/ruby-jing.png\" /\u003e}[https://codeclimate.com/github/sshaw/ruby-jing]\n\nRELAX NG schema validation using the {Jing CLI}[http://www.thaiopensource.com/relaxng/jing.html]\n\n=== Overview\n\n  require \"jing\"\n\n  jing = Jing.new(\"schema.rng\")\n  begin\n    errors = jing.validate(\"doc.xml\")\n  rescue Jing::Error =\u003e e\n    abort \"what what what #{e}\"\n  end\n\n  if errors.none?\n    puts \"Valid!\"\n  else\n    errors.each do |error|\n      puts \"#{error[:message]} @ #{error[:line]}:#{error[:column]}\"\n    end\n  end\n\n  # This can also raise errors\n  abort \"Invalid!\" unless jing.valid?(\"/path/to/doc.xml\")\n\n=== Why use Java to validate instead of Ruby libraries like Nokorigi, REXML, libxml, etc..?\n\nSimple: good error messages. Let's look at the error messages provided by each of these libraries.\n\n \u003c!-- RNG schema --\u003e\n \u003celement name=\"addressBook\" xmlns=\"http://relaxng.org/ns/structure/1.0\"\u003e\n   \u003czeroOrMore\u003e\n     \u003celement name=\"card\"\u003e\n       \u003cattribute name=\"version\"\u003e\n         \u003cchoice\u003e\n           \u003cvalue\u003ev1\u003c/value\u003e\n           \u003cvalue\u003ev2\u003c/value\u003e\n         \u003c/choice\u003e\n       \u003c/attribute\u003e\n       \u003celement name=\"name\"\u003e\n         \u003ctext/\u003e\n       \u003c/element\u003e\n     \u003c/element\u003e\n   \u003c/zeroOrMore\u003e\n \u003c/element\u003e\n\n \u003c!-- XML A --\u003e\n \u003caddressBook\u003e\n   \u003ccard\u003e\u003c/card\u003e\n \u003c/addressBook\u003e\n\n \u003c!-- XML B --\u003e\n \u003caddressBook\u003e\n   \u003ccard verison=\"v100\"\u003e\n     \u003cname\u003eJohn Smith\u003c/name\u003e\n     \u003coops\u003eDoh!\u003c/oops\u003e\n   \u003c/card\u003e\n \u003c/addressBook\u003e\n\n==== Nokorigi/libxml\n\n  schema = Nokogiri::XML::RelaxNG(File.read(rng))\n  doc = Nokogiri::XML(File.read(xml))\n  errors = schema.validate(doc)\n  errors.each { |e| puts e }\n\nResulting errors:\n\n  # XML A\n  Element card failed to validate attributes\n  Expecting an element , got nothing\n\n  # XML B\n  Element card failed to validate attributes\n  Did not expect element oops there\n\n==== REXML\n\n  include REXML\n  doc = Document.new(File.read(xml))\n  validator = Validation::RelaxNG.new(File.read(rng))\n  validator.validate(doc)\n\nFails for XML A and XML B --it treats the XML declaration as a validation error!\n\n  Validation error.  Expected: :start_element( addressBook ) from \u003c S.1 #:start_element( addressBook ), \u003c Z.2 #:start_element( card ), :start_attribute( version ), \u003c C.3 :text( v1 ) or :text( v2 ) \u003e, :end_attribute(  ), :start_element( name ), :text(  ), :end_element(  ), :start_element( email ), :text(  ), :end_element(  ), :end_element(  ) \u003e, :end_element(  ), :end_document(  ) \u003e  but got \u003c?xml ... ?\u003e(\n   )\n\n==== Jing\n\n  jing = Jing.new(schema)\n  errors = jing.validate(xml)\n  errors.each { |e| puts e[:message] }\n\nResulting errors:\n\n  # XML A\n  element \"card\" missing required attribute \"version\"\n  element \"card\" incomplete; missing required element \"name\"\n\n  # XML B\n  value of attribute \"version\" is invalid; must be equal to \"v1\" or \"v2\"\n  element \"oops\" not allowed anywhere; expected the element end-tag\n\nBetter, don't ya think?\n\n=== More Info\n\n* {Docs}[http://rdoc.info/gems/ruby-jing/frames]\n* {Bugs}[http://github.com/sshaw/ruby-jing/issues]\n* {Source}[http://github.com/sshaw/ruby-jing]\n\n=== Author\n\nSkye Shaw [skye.shaw AT gmail.com]\n\n=== License\n\nReleased under the MIT License: www.opensource.org/licenses/MIT\n\n=== Jing Copying Conditions\n\nCopyright (c) 2001-2003 Thai Open Source Software Center Ltd\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n* Neither the name of the Thai Open Source Software Center Ltd nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsshaw%2Fruby-jing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsshaw%2Fruby-jing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsshaw%2Fruby-jing/lists"}