GenX is a ShEx extension to leverage ShEx's unambiguous, ordered traversal of RDF graphs to produce XML documents.

Example

from the ShEx Demo (look for [Popup] or link in validation messages):

#BASE <http://base.example/#>
PREFIX ex: <http://ex.example/#>
PREFIX foaf: <http://xmlns.com/foaf/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX GenX: <http://shexspec.github.io/extensions/GenX/>

# directives:
#   =<function>?
#   $<namespace>
#   !debugger
                                %GenX:{ issue $http://ex.example/xml %}

start = <IssueShape>

<IssueShape> {
    ex:state (ex:unassigned ex:assigned) %GenX:{ @state =substr(19) %},
    ex:reportedBy @<Person>              %GenX:{ reported = %},
    ex:reportedOn xsd:dateTime           %GenX:{ [-1]@date %},
    (ex:reproducedBy @<EmployeeShape>    ,
     ex:reproducedOn xsd:dateTime        %GenX:{ @date %}
    )?                                   %GenX:{ reproduced = %},
    ex:related @<IssueShape>*
}                                        %GenX:{ @id %}
VIRTUAL <Person> {
    (foaf:name xsd:string                %GenX:{ full-name %}
     | foaf:givenName xsd:string+        %GenX:{ given-name %},
       foaf:familyName xsd:string        %GenX:{ family-name %}
    ),
    foaf:mbox IRI               %GenX:{ email-addr %}
}
<UserShape> & <Person> {
}
<EmployeeShape> {
    & <Person>,
    foaf:phone IRI+             %GenX:{ tel-number %}
}
#BASE <http://base.example/#>
PREFIX ex: <http://ex.example/#>
PREFIX foaf: <http://xmlns.com/foaf/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

<Issue1>
    ex:state        ex:unassigned ;
    ex:reportedBy   <User2> ;
    ex:reportedOn   "2013-01-23T10:18:00"^^xsd:dateTime ;
    ex:reproducedBy <Thompson.J> ;
    ex:reproducedOn "2013-01-23T11:00:00"^^xsd:dateTime ;
#    ex:related      <Issue2>, <Issue3> 
.

<User2>
    foaf:givenName "Bob" ;
    foaf:familyName "Smith" ;
    foaf:mbox <mailto:bob@example.org>
.

<Thompson.J>
    foaf:givenName "Joe", "Joseph" ;
    foaf:familyName "Thompson" ;
    foaf:phone <tel:+456> ;
    foaf:mbox <mailto:joe@example.org>
.

<issue xmlns="http://ex.example/xml" id="Issue1" state="unassigned">
<reported date="2013-01-23T10:18:00">
<given-name>Bob</given-name>
<family-name>Smith</family-name>
<email-addr>mailto:bob@example.org</email-addr>
</reported>
<reproduced date="2013-01-23T11:00:00">
<given-name>Joe</given-name>
<given-name>Joseph</given-name>
<family-name>Thompson</family-name>
<email-addr>mailto:joe@example.org</email-addr>
<tel-number>tel:+456</tel-number>
</reproduced>
</issue>

Issues

edited by: Eric Prud'hommeaux