Skip to content

Generate all paths and element/attribute types from XSD files

Notifications You must be signed in to change notification settings

linus1412/XsdPathTypeGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java XSD Path Generator

What it does

Takes in an XSD file and generates all possible element and attribute paths along with the element or attribute type.

How it does it

Internally XsdPathTypeGenerator uses Apache's XmlBeans, with some modifications.

I couldn't quickly get XmlBeans setup as a project in IntelliJ or Eclipse to make my modifications (uses a convoluted Ant setup), so I ended up bringing XmlBeans in as a dependency and monkey patching the files I needed to change, which was fine for my use case.

Limitations

Because of the above it probably needs to be run as an application, not included in you projects as a library as you need to ensure the monkey patched files take precedence over the corresponding XmlBeans classes.

Example

XSD

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://smitek.co.uk/example/1">
    <xsd:element name="employee">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="name" type="xsd:string"/>
                <xsd:element name="age" type="xsd:integer"/>
                <xsd:element name="started" type="xsd:date"/>
                <xsd:element name="department">
                    <xsd:complexType>
                        <xsd:sequence>
                            <xsd:element name="name" type="xsd:string"/>
                        </xsd:sequence>
                        <xsd:attribute name="code" type="xsd:integer"/>
                    </xsd:complexType>
                </xsd:element>
            </xsd:sequence>
            <xsd:attribute name="active" type="xsd:boolean"/>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

Code

class Example {

  void example() {
      Map<String, String> pathTypes =
          new XsdPathTypeGenerator().generateMap("employee", "/simple.xsd");
  }

}

Output

A Map containing

Path Type
employee@active xsd:boolean
employee/name xsd:string
employee/age xsd:integer
employee/started xsd:date
employee/department@code xsd:integer
employee/department/name xsd:string

Examples

Have a look at the test for some more examples.

Some examples use XSD files from HMRC, the UK Tax Authority:

I hope this helps somebody.

About

Generate all paths and element/attribute types from XSD files

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published