An open API service indexing awesome lists of open source software.

https://github.com/katydid/validator-go-relaxng

Translates RelaxNG to Relapse
https://github.com/katydid/validator-go-relaxng

relaxng relaxng-grammar translates-relaxng validation xml

Last synced: 4 months ago
JSON representation

Translates RelaxNG to Relapse

Awesome Lists containing this project

README

          

#Translates RelaxNG to Katydid

Translates Simplified [RelaxNG](http://relaxng.org/) Grammars to the [Katydid](https://github.com/katydid/katydid) Relapse Grammar.

There is a playground available here http://katydid.github.io/relaxng/play/

Simplification is defined at these two resources:
- http://debeissat.nicolas.free.fr/relaxng_simplification.php
- http://books.xmlschemata.org/relaxng/relax-CHP-15-SECT-1.html

## Usage

```
simplifiedRelaxNG := `






foo



`
relaxing, _ := ParseGrammar([]byte(simplifiedRelaxNG))
relapse, _ := Translate(relaxing)
input := ""
if err := Validate(relapse, []byte(input)); err != nil {
fmt.Println("invalid")
}
fmt.Println("valid")
// Output: valid
```

For more see the [go package documentation](https://godoc.org/github.com/katydid/relaxng)

### RelaxNG Test Suite

[![Build Status](https://travis-ci.org/katydid/relaxng.svg?branch=master)](https://travis-ci.org/katydid/relaxng)

```
passed: 146
failed: 0
namespace tests skipped: 13
datatypeLibrary tests skipped: 1
incorrect grammars skipped: 213
```

Steps:
- The RelaxNG Test Suite is run through the simplifier which also eliminates all the incorrect grammars.
- Next these simplified RelaxNG XML Grammars are parsed and translated to Katydid Relapse.
- Finally the translated Relapse is used to validate the XML.

Viewing all tests can be done in the playground by going to this [link](http://katydid.github.io/relaxng/play/index.html?testsuite=049.1.v), which will load the first test, and then clicking the *NextTest* button.

### Example 1

The Simplified RelaxNG Grammar

```






foo


```

is translated to this Relapse Grammar

```
@element1
#element1={
elem_foo:(|@ws);
(@ws)*;
}
#ws=->whitespace($string)
#text=->anytext($string)
```

### Example 2

The Simplified RelaxNG Grammar

```






foo

bar



```

is translated to this Relapse Grammar

```
@element1
#element1={
elem_foo:attr_bar:(@text)*;
(@ws)*;
}
#ws=->whitespace($string)
#text=->anytext($string)
```

### Example 3

The Simplified RelaxNG Grammar

```






foo



bar






bar









baz1





baz2


```

is translated to this Relapse Grammar

```
@element1
#element1={
elem_foo:(
[
attr_bar:@ws,
@element2
] |
[
attr_bar:(@text)*,
@element3
]
);
(@ws)*;
}
#element2={
elem_baz1:(|@ws);
(@ws)*;
}
#element3={
elem_baz2:(|@ws);
(@ws)*;
}
#ws=->whitespace($string)
#text=->anytext($string)
```

## Known Issues

There are quite a few known issues:
- Only simplified grammars are supported.
- [namespaces are not supported](https://github.com/katydid/relaxng/issues/2).
- datatypes: only string and token are currently supported.
- datatypeLibraries are not supported.

I don't really intend to fix these, but you never know.

### Only handles simplified relaxng grammars.

http://www.kohsuke.org/relaxng/rng2srng/ seems to be quite effective at converting the full spectrum of what is possible within the relaxng grammar to the simplified grammar.

```
java -jar rng2srng.jar full.rng > simplified.rng
```