Module: Duxml::RelaxNG
Overview
contains methods to convert Rules into a valid RelaxNG schema file
Instance Attribute Summary
Attributes included from Duxml
Attributes included from Saxer
Instance Method Summary collapse
-
#relaxng(output_path = nil) ⇒ Nokogiri::XML::RelaxNG
RelaxNG schema object.
Methods included from Duxml
Methods included from Saxer
Instance Method Details
#relaxng(output_path = nil) ⇒ Nokogiri::XML::RelaxNG
Returns RelaxNG schema object.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/duxml/meta/grammar/relax_ng.rb', line 14 def relaxng(output_path=nil) doc = Doc.new doc << Element.new('grammar') doc.grammar[:xmlns] = 'http://relaxng.org/ns/structure/1.0' doc.grammar[:datatypeLibrary] = 'http://www.w3.org/2001/XMLSchema-datatypes' start = Element.new('start') start[:combine] = 'choice' ref = Element.new('ref') ref[:name] = rules.first.subject start << ref doc.grammar << start rules.each do |rule| rule.relaxng doc.grammar end # fill in empty doc definitions to make them legal element_defs = doc.grammar.Define.collect do |d| d.element if d.nodes.first.name == 'element' and d.element.nodes.empty? end.compact element_defs.each do |element_def| element_def << Element.new('empty') end doc.write_to output_path if output_path doc end |