• Stars
    star
    134
  • Rank 270,967 (Top 6 %)
  • Language
    HTML
  • Created over 12 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Generates web forms from xml schema documents (xsd)

xsd-forms


You want to make a web form that submits structured data (XML/JSON).

xsd-forms generates a web form for you based on an xml schema (XSD) that has been annotated with some presentation information.

xsd-forms has been deployed to a freely available web service for your convenience and immediate testing.

The form is javascript/html only and performs all validation using javascript.

This project is written in Scala with a small amount of Java.

Status: Released to Maven Central

Design

Xml schemas contain nearly everything we need for many web forms except for presentation information. Instead of seeking full separation of presentation from the data model (the xml schema) there are significant advantages in annotating the xsd itself according to a special schema to indicate presentation details. For one, refactoring is much easier without specialized IDE tooling that can read both our xsd and our presentation format.

Primary Use Case

  • A developer needs to create a web form.
  • The developer creates an annotated schema as per xsd-forms and generates pure html and javascript (no server side scripting).
  • The developer links the form to a server side component that processes the submitted xml.

As the submitted xml is compliant with a schema, the xml can be unmarshalled by a tool (see jaxb, scalaxb, xsd.exe into schema generated objects. Consequently any change in the schema will be reflected by compilation errors in the processing code if a statically typed language is used (such as Java, Scala, C#, etc.).

The features of javascript libraries like http://jquery.com mean that generating an html/javascript form that on submit posts xml that is compliant with the schema is a viable approach. The resultant css/html/javascript can be plugged in to any web server and presentation aspects can be overriden using annotations on the schema, css overrides and custom jquery script (the ability to separate script from structure is a nice feature of jquery in this instance).

Examples

Generated Form Annotated schema Comment
Demo form schema Feature showcase
Australian Census 2011 schema Based on the 2011 Australian Census form (pdf)
AMSA Pollution report schema pdf

Note. The examples work fine in the Chrome, Firefox and Internet Explorer 9 browsers (other browsers not tested yet). IE 9 will not display the above demos because they are sourced from htmlpreview.github.io which does not furnish the js with the appropriate mime-type. You can use the web service to display the demos succesfully for IE 9. IE is not being selenium tested yet but a SauceConnect job may be set up for that soon.

FAQ

I've already got a schema, can I generate a form from it?

Probably not! xsd-forms only supports a subset of xsd features. It was enough work for me to get this far, believe me! Supported features are documented in another section below. Your options are:

  • use an XSLT to translate xml to match your schema
  • translate the xml using some standard parser (xpath expressions etc)
  • generate classes from both schemas and write code to translate using the generated classes. This method gives you compile-time indications as the schemas change through time (and isn't change inevitable!). This is my preferred option.

What xsd features are supported?

These xsd features are supported:

  • elements only, not attributes
  • sequence, choice
  • minOccurs, maxOccurs on elements or anonymous complex types
  • extension of complex types
  • restrictions by regex pattern, enumerations, ranges on numerics, maxLength, minLength, length
  • base simple types: string, boolean, date, datetime, time, integer, decimal, int, short, long, positiveInteger, negativeInteger, nonPositiveInteger, nonNegativeInteger, double, float
  • no explicit support for populating form fields (say from xml). xsd defaults will be honoured. JQuery overrides can be used to do custom initialization.

Bearing in mind the above restrictions, these features are supported:

  • top level elements
  • top level complex types
  • top level simple types
  • anonymous complex types
  • anonymous complex content
  • anonymous simple types

How do I generate a form?

You need to make a schema using only the elements and types that are supported by xsd-forms. You can generate the form without adding any annotations at that point and it will use element names and such as defaults. A starter schema looks like this:

<xs:schema targetNamespace="http://org.moten.david/example"
  xmlns="http://org.moten.david/example" xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:i="http://moten.david.org/xsd-forms">
  <xs:annotation i:numberItems="true">
    <xs:appinfo>
      <i:header><![CDATA[
<h2>Title of the form</h2>
]]></i:header>
      <i:footer><![CDATA[
    <p>Thanks for your time.</p>
]]></i:footer>
      <i:extraImports><![CDATA[
    <!-- more imports here -->
]]></i:extraImports>
      <i:extraScript><![CDATA[
  // extra script would go here
]]></i:extraScript>
      <i:extraCss><![CDATA[
  /* extra css would go here */
]]></i:extraCss>
    </xs:appinfo>
  </xs:annotation>
  <xs:element name="name" type="xs:string">
    <xs:annotation i:label="Full name" />
  </xs:element>
</xs:schema>

Deploying this simple schema to the web service mentioned below gives you this form.

How do I annotate my schema?

Every element in your schema optionally can have a contained <xs:annotation/> element. Place attributes on that element from the xsd-forms schema like below:

annotations-demo.xsd ---> form

For a full list of annotations and their meanings see the top of the file annotation.scala.

This is what the form from annotations-demo.xsd looks like:

Generate using web service

A web service is available. At this service you can

  • Submit a schema document to the service and receive a zip archive of the generated site.
  • Submit a schema document and view the generated form

Generate using a local web service

You need to have built everything once only:

mvn clean install

Then

cd xsd-forms-generator-webapp
mvn package jetty:run

Then go to http://localhost:8080 and fill in the form.

Generate using java/scala:

Add the following maven dependency to your pom.xml (you will need to have built the project from source so that the dependency is available in your local repository):

<dependency>
  <groupId>com.github.davidmoten.xsdforms</groupId>
  <artifactId>xsd-forms-generator</artifactId>
  <version>0.2.1</version>
</dependency>

and call

xsdForms.generateZip(..) 

or

xsdForms.generateHtml(...)

or

xsdForms.generateDirectory(...)

Generate using maven plugin

<plugin>
  <groupId>com.github.davidmoten.xsdforms</groupId>
  <artifactId>xsd-forms-maven-plugin</artifactId>
  <version>0.2.1</version>
  <executions>
    <execution>
	  <goals>
		<goal>generate</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <!-- schema location can be on classpath or file system. Classpath is checked first -->
    <schema>/demo.xsd</schema>
  </configuration>
</plugin>

Here is a demonstration using xsd-forms-maven-plugin.

What do I need to do after I have designed a schema?

The default generated form just displays the captured xml on the page under the submit button. You will likely want to post the generated xml to a web server or perhaps email the xml to an address. To do that just set extraScript to the script below to override the submit behaviour:

//for example, display the xml in an alert box
processXml = function (xml) {
  alert(xml);
} 

Can I submit JSON instead?

Yep. Use this extraScript (using xml2json.js):

//for example, display json in an alert box
processXml = function (xml) {
  var result = toJson(xml);
  //alert or you could do a jquery ajax call to submit to a web server
  alert(result);
}

How do I override the appearance of the generated form?

Easy, just use javascript (jquery) in the extraScript. For instance, building on the above example:

//override the appearance of first input box
$('#item-6-instance-1_1_1').css("background", "aqua");

//override the default value of first input box
$('#item-6-instance-1_1_1').val("bingo");

An alternative is to put your own css overrides in xsd-forms-overrides.css.

How can I do my own thing with the xml?

Use this extraScript:

//override the processXml function
processXml = function(xml) {
  //do whatever you want here!!
};

How do I submit the xml/json to a web server?

Use this extraScript:

processXml = postXml('http://posttestserver456.com/post.php');

Or for more control use this extraScript and modify it:

//submit the xml to a web service using http post
processXml = function (xml) {
  var data = new Object();
  data.xml = xml;
  //disable submit button
  $('#submit').hide();
  $.ajax({
  type: 'POST',
  url: 'http://posttestserver456.com/post.php',
  data: data,
  success: 
    function (dat,textStatus,jqXHR) {
      $('#submit').hide();
    },
  error:
    function (jqXHR,textStatus,errorThrown) {
      alert(textStatus + '\n'+ errorThrown);
     $('#submit').show();
    },
  async:false
});
}

How do I pre-populate a form?

Schema default values will be set but if you want to for instance restore a form so a user can edit it then you need to write the necessary javascript as in the above examples. Using javascript/jquery you can call web services or extract parameters from the current url to populate the form.

Can I use the same schema for multiple different forms?

Yes. Just choose a different root element for each form.

Scope

The generated form should

  • perform all schema defined validation (e.g. regex pattern checks etc)
  • notify validation failures in a good practice way
  • build schema compliant xml from the input fields
  • not allow submission until all validation passes
  • offer ui options for handling xs:choice
  • offer ui options for handling xs:enumeration
  • follow good practice presentation standards
  • facilitate tweaking of presentation using css override on every element
  • support small screen/large screen
  • support common mobile platforms

Building

Technical overview

The use case is

  • Given an xml schema, generate html, javascript and css files that will capture input, perform validation and prepare an xml representation of the form detail compliant with the schema.

Building from source

You need maven 3 installed and git binaries.

git clone https://github.com/davidmoten/xsd-forms.git
cd xsd-forms
mvn clean install

Running selenium tests

To run selenium tests (firefox, and chrome if setup):

mvn clean install -Dselenium=true

More options

Disable the chrome driver:

-Dchrome=false

Disable the firefox driver:

-Dfirefox=false

If you have the chromedriver executable installed ensure it is on the $PATH. For example, on linux

export PATH=/opt/chromedriver:$PATH

where /opt/chromedriver is the directory containing the chromedriver executable.

Viewing a sample form

cd xsd-forms-generator
mvn jetty:run

Then go to http://localhost:8080/demo-form.html.

Run the generator

cd xsd-forms-generator-webapp
mvn package jetty:run

Then go to http://localhost:8080/

Development plan

  • use jquery to insert clones of div blocks to model maxOccurs > 1
  • demonstrate choice presentation options (inline and post, labelled and unlabelled)
  • implement choice presentation options
  • clean up generated jquery code
  • improve presentation
  • enable css override
  • generate xml
  • unit tests of form generation
  • unit tests of form behaviour (selenium?) including xml schema compliance
  • use templating instead of coding divs directly in scala?
  • combine templating with css to make themes

More Repositories

1

rtree

Immutable in-memory R-tree and R*-tree implementations in Java with reactive api
Java
1,038
star
2

rxjava-jdbc

Efficient execution and functional composition of database calls using jdbc and RxJava Observables
Java
804
star
3

geo

Geohash utitlies in java
Java
399
star
4

rxjava2-jdbc

RxJava2 integration with JDBC including Non-blocking Connection Pools
Java
386
star
5

rxjava-extras

Utilities for use with rxjava
Java
269
star
6

rxjava2-extras

Utilities for use with RxJava 2
Java
167
star
7

state-machine

Finite state machine class generator for java, exports graphml, supports immutability!
Java
124
star
8

hilbert-curve

Java utilities for transforming distance along N-dimensional Hilbert Curve to a point and back. Also supports range splitting queries on the Hilbert Curve.
Java
93
star
9

rxjava-file

RxJava observables for files including NIO events
Java
83
star
10

big-sorter

Java library that sorts very large files of records by splitting into smaller sorted files and merging
Java
74
star
11

rtree2

Immutable in-memory R-Tree and R*-Tree for Java with Iterable API
Java
71
star
12

openapi-to-plantuml

Converts OpenAPI 3.0 definitions to Plant UML text for visualisation of your API.
Java
56
star
13

flatbuffers

Maven artifacts containing compiled flatbuffers binaries and flatbuffers-java runtime library
Java
53
star
14

jenkins-ec2-https

How to setup Jenkins CI on EC2 with https access
Shell
53
star
15

predict4java

java library for satellite position prediction
Java
44
star
16

rtree-multi

Java library implementing immutable R-tree and R*-tree for n dimensions
Java
43
star
17

sparse-hilbert-index

Java library to create and search random access files (including in S3) using the space-filling hilbert index (sparse)
Java
40
star
18

java-builder-pattern-tricks

Tricks to use with the java builder pattern
40
star
19

cake-pattern

Examples of cake pattern in scala for injecting singleton and non-singleton dependencies
Scala
34
star
20

bplustree

B+-tree in java that stores to disk using memory mapped files, supports range queries and duplicate keys
Java
33
star
21

rtree-3d

3D R-Tree in java
Java
32
star
22

jax-maven-plugin

maven plugin support for xjc, wsimport, wsgen, schemagen for Java 8,9,10,11+
Java
31
star
23

websockets-log-tail

Follow a stream (like a log file) from a server in the browser.
Java
28
star
24

grumpy

OGC WMS server allowing custom rendered layers in java
Java
28
star
25

odata-client

Java client generator for a service described by OData CSDL 4.0 metadata. Includes Microsoft Graph clients (v1.0 and Beta), Graph Explorer client, Analytics for DevOps, Dynamics CRM clients
Java
28
star
26

word-wrap

Java library for word wrapping text including streaming and custom stringWidth
Java
27
star
27

aws-maven-plugin

Deploys resources to AWS using maven
Java
27
star
28

rxjava-slf4j

Logging utilities for use with RxJava
Java
25
star
29

aws-lightweight-client-java

A lightweight java client for the AWS API. Signs requests with AWS Version 4 and offers helpful builders.
Java
25
star
30

rxjava2-http

Transmit RxJava2 Flowable over http with non-blocking backpressure
Java
18
star
31

xuml-tools

Executable UML tools (xml schema, java model compiler, java + javascript model viewer) based on miUML metamodels
Java
16
star
32

reels

Actor framework for Java, non-blocking, performant
Java
16
star
33

audio-recognition

Matches audio to small vocabulary using fast fourier transforms
Java
15
star
34

rxjava2-aws

RxJava 2 utilities for use with AWS especially SQS, S3
Java
13
star
35

rxjava2-file

Java
13
star
36

kool

j.u.s.Stream alternative (synchronous only), reusable, faster, more operators, easier to use.
Java
13
star
37

guava-mini

Optional, Preconditions, Objects, Lists, Sets classes taken from guava
Java
10
star
38

jns

3D Navier-stokes solver for incompressible fluids using java 8 for regions including obstacles and surface
Java
10
star
39

ppk

Concise Public Private Key (PKCS) encryption utilities in java
Java
9
star
40

io-extras

IO java utilities, OutputStream as InputStream, BoundedBufferedReader
Java
9
star
41

functional-jpa

Functional style java helpers for jpa and guava
Java
9
star
42

rxjava-web-server

playing around with using Observables in a simple web server
Java
9
star
43

rxjava-aws

RxJava 1.x utilities for AWS (SQS, S3, ...)
Java
9
star
44

xjc-maven-plugin

Supports Java 8,9,10,11+, generates code from DTD or XSD
Java
8
star
45

bigsort

Uses RxJava to sort an arbitrarily large stream by serializing to temporary files and merging
Java
7
star
46

space-invaders-opengl

Runs the space invaders LWJGL demo as a main or an applet
Java
7
star
47

rxjava3-jdbc

Java
7
star
48

openapi-to-plantuml-aws-api

HTML
6
star
49

davidmoten.github.io

apidocs and other documentation
HTML
6
star
50

big-sorter-example

Demo maven project with big-sorter dependency and sample csv sort
Java
5
star
51

viem

Volatile Identifier Entity Matching (VIEM) algorithm and java library
Java
5
star
52

logan

Java webapp for time series analysis of log files
JavaScript
5
star
53

java-script-template

Template for a bash script that compiles and runs java commands
Shell
5
star
54

aws-helper

Type-safety additions for Java AWS Lambda in API Gateway context
Java
5
star
55

tile-joiner

Renders map service tiles to a BufferedImage in java and thence to a PNG for instance
Java
5
star
56

entity-tracking-in-memory

Matches timestamped geospatial position reports to entities in an in-memory dataset and maintains identifier uniqueness
Java
5
star
57

openapi-codegen

Java code generator from OpenAPI definition file
Java
5
star
58

one-time-link

Java webapp for creating one-time read links to encrypted information stored on the server file system
Java
4
star
59

http-test-server

Java
4
star
60

maven-s3-repo

Read from an S3-backed maven repository using standard http wagon authentication and serverless architecture
Java
4
star
61

plantuml-maven-plugin

Maven plugin for generating diagram images from PlantUML files
Java
4
star
62

decrypt-maven-plugin

Decrypts server passwords read from .m2/settings.xml
Java
4
star
63

java-data-structures

Practice implementations of some common data structures and algorithms in java
Java
4
star
64

low-mem

How to create low memory usage classes in java
Java
4
star
65

microsoft-dynamics-finance-client

Java client for Microsoft Dynamcis Finance and Operations API
Java
4
star
66

sonatype-parent

Parent pom.xml to ease deployment to Maven Central
4
star
67

java-builder2

Generate complex builder code using java code
Java
3
star
68

java-builder

Generate java builder pattern from a list of variable declarations
Java
3
star
69

rxjava3-pool

Java
3
star
70

api-gateway-java-lambda-cf-example

Example of integration of api gateway and java lambda using cloud-formation
Java
3
star
71

embedded-queue

Java
3
star
72

rxjava2-json

RxJava2 utitilies for consuming streaming json
Java
3
star
73

more-executors

More performant Java Executors
Java
3
star
74

timesheet

timesheet web application
Java
3
star
75

gedcom

Scala library to parse GEDCOM files (common genealogy format)
Scala
3
star
76

rxjava-extras-java-8

Utilities for use with RxJava 1.x and Java 8
Java
2
star
77

rxjava-parallel

implements a ParallelObservable as an experiment
Java
2
star
78

junit-extras

Utilities for use with junit
Java
2
star
79

rxjava-marble-template

Inkscape svg template mimicking rxjava style marble diagrams
2
star
80

beanstalk-template

Beanstalk java servlet application that supports client certificate authentication (load-balanced)
Java
2
star
81

git-properties-maven-plugin

Maven plugin to write a git.properties file to an output directory and to set maven properties for use in pom.xml
Java
2
star
82

jetty-demo

A demonstration webapp that can be started using mvn jetty:run
JavaScript
2
star
83

jks-util

Utilities for manipulating JKS files
Java
2
star
84

mp4-splicer

Java based tool for chopping and concatenating h264 video in mp4 containers
Java
2
star
85

c-vs-java

Performance comparison on 2D array of Java and C
Java
2
star
86

entity-tracking

Geopositional entity tracking using geohashing for queries
Java
1
star
87

log-analysis

superseded by logan
JavaScript
1
star
88

log-metrics

Detects changes to log files and parses logs to extract and publish metrics
Java
1
star
89

as-none-before

ASN.1 java compiler
GAP
1
star
90

pulley

Fiddling around with reactive pull in Java
Java
1
star
91

ets

Entity Tracking System
1
star
92

school-class-partitions

Algorithm discussion on splitting a group into classes while optimizing friend preferences, gender split, and exclusions
1
star
93

practice

miscellaneous algorithm practice
Java
1
star
94

mandelbrot

Generates a movie of a mandelbrot set zoom-in
Java
1
star
95

state-diagram-viewer

playing with GraphStream library for graph visualisation particularly a UML State Diagram
1
star
96

android-scala-sample

Android app using scala built with maven
Scala
1
star
97

github-stars

Service deployed to AWS API Gateway and Lambda using CF to cache github star counts
Java
1
star
98

geotemporal

Java based utilities supporting geo-temporal searching
Java
1
star
99

latex-renderer

Renders latex to png and other
Java
1
star
100

xuml-compiler

Automatically exported from code.google.com/p/xuml-compiler
Java
1
star