
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
nokogiri_schematron_builder
Advanced tools
Build Schematron XML documents using Nokogiri.
Add this line to your application's Gemfile:
gem "nokogiri_schematron_builder"
And then execute:
$ bundle
Or install it yourself as:
$ gem install nokogiri_schematron_builder
Add this line to your application:
require "nokogiri/xml/schematron/schema"
Create the schema using the domain-specific language:
schema = Nokogiri::XML::Schematron::Schema.new(title: "Example schema") do
ns(prefix: "ex", uri: "http://example.com/ns#")
pattern(title: "Example pattern") do
rule(context: "/") do
assert(test: "count(ex:A) >= 1", message: "element \"ex:A\" is REQUIRED")
end
rule(context: "/ex:A") do
assert(test: "count(ex:B) >= 0", message: "element \"ex:B\" is OPTIONAL")
end
rule(context: "/ex:A/ex:B") do
assert(test: "not(ex:C)", message: "element \"ex:C\" is NOT RECOMMENDED")
end
end
end
Or, equivalently:
schema = Nokogiri::XML::Schematron::Schema.new(title: "Example schema") do
ns(prefix: "ex", uri: "http://example.com/ns#")
pattern(title: "Example pattern") do
context("/") do
require("ex:A") do
permit("ex:B") do
reject("ex:C")
end
end
end
end
end
Next, construct a Nokogiri::XML::Builder
object:
builder = schema.to_builder(encoding: "UTF-8")
Finally, generate the XML:
xml = builder.to_xml
The result is:
<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron">
<sch:title>Example schema</sch:title>
<sch:ns prefix="ex" uri="http://example.com/ns#"/>
<sch:pattern>
<sch:title>Example pattern</sch:title>
<sch:rule context="/">
<sch:assert test="count(ex:A) >= 1">element "ex:A" is REQUIRED</sch:assert>
</sch:rule>
<sch:rule context="/ex:A">
<sch:assert test="count(ex:B) >= 0">element "ex:B" is OPTIONAL</sch:assert>
</sch:rule>
<sch:rule context="/ex:A/ex:B">
<sch:assert test="not(ex:C)">element "ex:C" is NOT RECOMMENDED</sch:assert>
</sch:rule>
</sch:pattern>
</sch:schema>
After checking out the repo, run bin/setup
to install dependencies. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/pnnl/nokogiri_schematron_builder.
FAQs
Unknown package
We found that nokogiri_schematron_builder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.