SlideShare a Scribd company logo
Java and XML Schema
XSOM
XML Schema Object Model

Raji GHAWI
19/01/2009
Import required packages

import
import
import
import

com.sun.xml.xsom.*;
com.sun.xml.xsom.XSModelGroup.*;
com.sun.xml.xsom.impl.*;
com.sun.xml.xsom.parser.*;
Create the parser

XSOMParser parser = new XSOMParser();
parser.setErrorHandler(new MyErrorHandler());
MyErrorHandler

public class MyErrorHandler implements ErrorHandler{
public void warning(SAXParseException se){
System.err.println("warning : "+se.getMessage());
}
public void error(SAXParseException se){
System.err.println("error : "+se.getMessage());
}
public void fatalError(SAXParseException se){
System.err.println("fatal error : "+se.getMessage());
}
}
Parse an XML schema file

try {
parser.parse(new File("./example.xsd"));
// ....
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (SAXException se) {
se.printStackTrace();
}
XSSchemaSet

XSSchemaSet schemaSet = parser.getResult();
Iterator<XSSchema> schemaIter = schemaSet.iterateSchema();
while (schemaIter.hasNext()) {
XSSchema schema = (XSSchema) schemaIter.next();
if(schema.getTargetNamespace().
equals("http://www.w3.org/2001/XMLSchema"))
continue;
// ....
}
<xs:element name="product">
<xs:complexType>
<xs:attribute name="prodid" type="xs:positiveInteger" />
</xs:complexType>
</xs:element>

anonymous complex type

<xs:element name="member" type="personinfo" />
<xs:complexType name="personinfo">
<xs:sequence>
<xs:element name="firstname" type="xs:string" />
<xs:element name="lastname" type="xs:string" />
</xs:sequence>
</xs:complexType>

named complex type

<xs:element name="car" default="Audi">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Audi" />
<xs:enumeration value="Golf" />
<xs:enumeration value="BMW" />
</xs:restriction>
</xs:simpleType>
</xs:element>

anonymous simple type

<xs:element name="car2" type="carType" fixed="BMW" />
<xs:simpleType name="carType">
<xs:restriction base="xs:string">
<xs:enumeration value="Audi" />
<xs:enumeration value="Golf" />
<xs:enumeration value="BMW" />
</xs:restriction>
</xs:simpleType>

named simple type

<xs:element name="dateborn" type="xs:date" abstract="true" />

primitive type
Elements

System.out.println("--------- elements ---------");
Iterator<XSElementDecl> elemIter = schema.iterateElementDecls();
while (elemIter.hasNext()) {
XSElementDecl elem = elemIter.next();
System.out.println(describeElement(elem));
}
Elements
public static String describeElement(XSElementDecl elem) {
String txt = elem.getName();
XSType type = elem.getType();
txt += (" t ("+type.toString()+")");
if (elem.isGlobal())
txt += " (global)";
else if (elem.isLocal())
txt += " (local)";
if (elem.isAbstract())
txt += " t(abstract)";
XmlString defaultValue = elem.getDefaultValue();
if(defaultValue!=null){
txt += " t(default='"+defaultValue+"')";
}

}

XmlString fixedValue = elem.getFixedValue();
if(fixedValue!=null){
txt += " t(fixed='"+fixedValue+"')";
}
return txt;
--------- elements --------car (anonymous simple type) (global) (default='Audi')
member (personinfo complex type) (global)
product (anonymous complex type) (global)
dateborn (date simple type) (global) (abstract)
car2 (carType simple type) (global) (fixed='BMW')
Attributes

System.out.println("--------- attributes ---------");
Iterator<XSAttributeDecl> attIter = schema.iterateAttributeDecls();
while (attIter.hasNext()) {
XSAttributeDecl att = attIter.next();
System.out.println(describeAttribute(att));
}
Attributes
public static String describeAttribute(XSAttributeDecl att) {
String txt = att.getName()+" t "+att.getType().getName();
XmlString defaultValue = att.getDefaultValue();
if(defaultValue!=null){
txt += " t(default='"+defaultValue+"')";
}
XmlString fixedValue = att.getFixedValue();
if(fixedValue!=null){
txt += " t(fixed='"+fixedValue+"')";
}
// isRequired ??
return txt;
}

<xs:attribute
<xs:attribute
<xs:attribute
<xs:attribute

name="lang1"
name="lang2"
name="lang3"
name="lang4"

type="xs:string"
type="xs:string"
type="xs:string"
type="xs:string"

/>
default="EN" />
fixed="EN" />
use="required" />

--------- attributes --------lang1 string
lang3 string (fixed='EN')
lang2 string (default='EN')
lang4 string
Types

System.out.println("--------- types ---------");
Iterator<XSType> typeIter = schema.iterateTypes();
while (typeIter.hasNext()) {
XSType st = typeIter.next();
System.out.println(describeType(st));
}
Types
public static String describeType(XSType type) {
String txt = "";
if(type.isAnonymous()) txt += "(anonymous)";
else txt += type.getName();
if (type.isGlobal()) txt += " (global)";
else if (type.isLocal()) txt += " (local)";
if(type.isComplexType()) txt += " (complex)";
else if(type.isSimpleType()) txt += " (simple)";

}

int deriv = type.getDerivationMethod();
switch(deriv){
case XSType.EXTENSION:
txt += " (EXTENSION)";
break;
case XSType.RESTRICTION:
txt += " (RESTRICTION)";
break;
case XSType.SUBSTITUTION:
txt += " (SUBSTITUTION)";
break;
}
return txt;
--------- types --------carType (global) (simple) (RESTRICTION)
personinfo (global) (complex) (RESTRICTION)

Global Types only !!
How to get all types ?
public static Vector<XSType> allTypes = new Vector<XSType>();
Iterator<XSType> typeIter = schema.iterateTypes();
while (typeIter.hasNext()) {
XSType st = typeIter.next();
allTypes.addElement(st);
}

//

....

System.out.println("--------- types ---------");
for (int i = 0; i < allTypes.size(); i++) {
XSType type = allTypes.get(i);
System.out.println(describeType(type));
}

public static String describeElement(XSElementDecl elem) {
String txt = elem.getName();
XSType type = elem.getType();
if(!allTypes.contains(type)){
allTypes.addElement(type);
}
// ....
}

primitive type !!

--------- types --------carType (global) (simple) (RESTRICTION)
personinfo (global) (complex) (RESTRICTION)
(anonymous) (local) (simple) (RESTRICTION)
(anonymous) (local) (complex) (RESTRICTION)
date (global) (simple) (RESTRICTION)
How to ignore primitive types ?

public static String describeElement(XSElementDecl elem) {
String txt = elem.getName();
XSType type = elem.getType();
if(!allTypes.contains(type)){
if(type.isSimpleType()){
if(!type.asSimpleType().isPrimitive()){
allTypes.addElement(type);
}
} else {
allTypes.addElement(type);
}
}
// ....
}

--------- types --------carType (global) (simple) (RESTRICTION)
personinfo (global) (complex) (RESTRICTION)
(anonymous) (local) (simple) (RESTRICTION)
(anonymous) (local) (complex) (RESTRICTION)
Complex and Simple Types

// XSType type
if(type.isComplexType()){
XSComplexType complex = type.asComplexType();
//
} else if(type.isSimpleType()){
XSSimpleType simple = type.asSimpleType();
//
}

schema.iterateSimpleTypes();

schema.iterateComplexTypes();
XSComplexType

// XSComplexType complex
XSContentType contenetType = complex.getContentType();
if(contenetType instanceof EmptyImpl){
XSContentType empty = contenetType.asEmpty();
//
} else if(contenetType instanceof ParticleImpl){
XSTerm term = contenetType.asParticle().getTerm();
//
} else if(contenetType instanceof SimpleTypeImpl){
XSSimpleType st = contenetType.asSimpleType();
//
}
XSTerm

//

XSTerm term

if(term.isElementDecl()){
XSElementDecl elem = term.asElementDecl();
//
} else if(term.isModelGroup()){
XSModelGroup mg = term.asModelGroup();
//
} else if(term.isModelGroupDecl()){
XSModelGroupDecl mgd = term.asModelGroupDecl();
XSModelGroup mg = mgd.getModelGroup();
//
} else if(term.isWildcard()){
XSWildcard wildcard = term.asWildcard();
//
}
XSModelGroup

// XSModelGroup modelGroup
Compositor comp = modelGroup.getCompositor();
if(comp.equals(Compositor.SEQUENCE)){
//
} else if(comp.equals(Compositor.ALL)){
//
} else if(comp.equals(Compositor.CHOICE)){
//
}
XSParticle[] particles = modelGroup.getChildren();
for (int i = 0; i < particles.length; i++) {
XSTerm term = particles[i].getTerm();
// ....
}
XSSimpleType

// XSSimpleType simpe
if(simple.isList()){
XSListSimpleType lst = simple.asList();
//
} else if(simple.isUnion()){
XSUnionSimpleType ust = simple.asUnion();
//
} else if(simple.isRestriction()){
XSRestrictionSimpleType rst = simple.asRestriction();
//
}
XSRestrictionSimpleType
// XSRestrictionSimpleType restriction
XSType baseType = restriction.getBaseType();
// ....

Iterator<?> facets = restriction.getDeclaredFacets().iterator();
while (facets.hasNext()) {
XSFacet facet = (XSFacet) facets.next();
String name = facet.getName();
XmlString value = facet.getValue();
if(name.equalsIgnoreCase("enumeration")){
//
} else if(name.equalsIgnoreCase("minInclusive")){
//
} else if(name.equalsIgnoreCase("minExclusive")){
//
} else if(name.equalsIgnoreCase("maxInclusive")){
//
} else if(name.equalsIgnoreCase("maxExclusive")){
//
} else if(name.equalsIgnoreCase("whiteSpace")){
//
}
}
References


https://xsom.dev.java.net/
(Kohsuke Kawaguchi, Sun Microsystems )



http://www.stylusstudio.com/w3c/schema0/_index.htm

More Related Content

What's hot (20)

PDF
Agile Requirements with User Story Mapping
Andreas Hägglund
 
PPTX
Strategies for Large Scale Agile Transformation
Nishanth K Hydru
 
PDF
Agile Transformation Case Studies
Chandan Patary
 
KEY
Agile Estimating & Planning
AgileDad
 
PDF
Microsoft Office B
Christina Cecil
 
PDF
Çevik Proje Yönetimi Metodolojileri ve Scrum'ın Temelleri
Ozan Ozcan
 
PPT
Test Process Improvement
Momentum NI
 
PDF
Guia do Papel e Responsabilidade do Scrum Master
Paulo Lomanto
 
PDF
Agile Transformation v1.27
LeadingAgile
 
PDF
Agile Process Introduction
Nguyen Hai
 
PDF
Implementing Scrum with Kanban
Tiffany (Wells) Scott, PSM, PSPO
 
PPTX
How to measure the outcome of agile transformation
Rahul Sudame
 
PDF
Introduction-to-Lean-Six-Sigma.pdf
Muhammad Mamun Mia
 
PDF
Enterprise Agile Coaching - Professional Agile Coaching #3
Cprime
 
PPTX
Intro to Agile Portfolio Governance Presentation
Cprime
 
PPTX
What's new in the Scaled Agile Framework (SAFe) 6.0 - Agile Indy May 10th Meetup
Yuval Yeret
 
PDF
Turning Up the Magic in PI Planning
Em Campbell-Pretty
 
PDF
What is Agile Methodology?
QA InfoTech
 
PDF
Agile Estimation for Fixed Price Model
jayanth72
 
Agile Requirements with User Story Mapping
Andreas Hägglund
 
Strategies for Large Scale Agile Transformation
Nishanth K Hydru
 
Agile Transformation Case Studies
Chandan Patary
 
Agile Estimating & Planning
AgileDad
 
Microsoft Office B
Christina Cecil
 
Çevik Proje Yönetimi Metodolojileri ve Scrum'ın Temelleri
Ozan Ozcan
 
Test Process Improvement
Momentum NI
 
Guia do Papel e Responsabilidade do Scrum Master
Paulo Lomanto
 
Agile Transformation v1.27
LeadingAgile
 
Agile Process Introduction
Nguyen Hai
 
Implementing Scrum with Kanban
Tiffany (Wells) Scott, PSM, PSPO
 
How to measure the outcome of agile transformation
Rahul Sudame
 
Introduction-to-Lean-Six-Sigma.pdf
Muhammad Mamun Mia
 
Enterprise Agile Coaching - Professional Agile Coaching #3
Cprime
 
Intro to Agile Portfolio Governance Presentation
Cprime
 
What's new in the Scaled Agile Framework (SAFe) 6.0 - Agile Indy May 10th Meetup
Yuval Yeret
 
Turning Up the Magic in PI Planning
Em Campbell-Pretty
 
What is Agile Methodology?
QA InfoTech
 
Agile Estimation for Fixed Price Model
jayanth72
 

Similar to Java and XML Schema (20)

PPTX
XML Schema
Kumar
 
PPT
SAX PARSER
Saranya Arunprasath
 
PPT
Mazda Use of Third Generation Xml Tools
CardinaleWay Mazda
 
PPTX
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 2
Marco Gralike
 
PPT
XML Schema
yht4ever
 
PDF
IQPC Canada XML 2001: How to develop Syntax and XML Schema
Ted Leung
 
PPT
DOSUG XML Beans overview by Om Sivanesian
Matthew McCullough
 
PDF
Data formats
Katrien Verbert
 
PDF
SAX, DOM & JDOM parsers for beginners
Hicham QAISSI
 
PPT
unit_5_XML data integration database management
sathiyabcsbs
 
PPTX
Xml schema
Akshaya Akshaya
 
PPT
Xml Schema
vikram singh
 
PPTX
XML Fundamentals
Andres Felipe Rincon Rodriguez
 
PPTX
XML Schema.pptx
JohnsonDcunha1
 
PDF
Xml schema
Prabhakaran V M
 
PPTX
Xml session
Farag Zakaria
 
PPTX
Xml schema
sana mateen
 
PPTX
advDBMS_XML.pptx
IreneGetzi
 
PDF
Xml Schema Essentials R Allen Wyke Andrew Watt
qbcznaka519
 
XML Schema
Kumar
 
SAX PARSER
Saranya Arunprasath
 
Mazda Use of Third Generation Xml Tools
CardinaleWay Mazda
 
OPP2010 (Brussels) - Programming with XML in PL/SQL - Part 2
Marco Gralike
 
XML Schema
yht4ever
 
IQPC Canada XML 2001: How to develop Syntax and XML Schema
Ted Leung
 
DOSUG XML Beans overview by Om Sivanesian
Matthew McCullough
 
Data formats
Katrien Verbert
 
SAX, DOM & JDOM parsers for beginners
Hicham QAISSI
 
unit_5_XML data integration database management
sathiyabcsbs
 
Xml schema
Akshaya Akshaya
 
Xml Schema
vikram singh
 
XML Schema.pptx
JohnsonDcunha1
 
Xml schema
Prabhakaran V M
 
Xml session
Farag Zakaria
 
Xml schema
sana mateen
 
advDBMS_XML.pptx
IreneGetzi
 
Xml Schema Essentials R Allen Wyke Andrew Watt
qbcznaka519
 
Ad

More from Raji Ghawi (12)

PPTX
Database Programming Techniques
Raji Ghawi
 
PPTX
Java and XML
Raji Ghawi
 
PPTX
Java and SPARQL
Raji Ghawi
 
PPTX
Java and OWL
Raji Ghawi
 
PPTX
SPARQL
Raji Ghawi
 
PPTX
XQuery
Raji Ghawi
 
PPTX
XPath
Raji Ghawi
 
PPT
Ontology-based Cooperation of Information Systems
Raji Ghawi
 
PPT
OWSCIS: Ontology and Web Service based Cooperation of Information Sources
Raji Ghawi
 
PPT
Coopération des Systèmes d'Informations basée sur les Ontologies
Raji Ghawi
 
PPT
Building Ontologies from Multiple Information Sources
Raji Ghawi
 
PPT
Database-to-Ontology Mapping Generation for Semantic Interoperability
Raji Ghawi
 
Database Programming Techniques
Raji Ghawi
 
Java and XML
Raji Ghawi
 
Java and SPARQL
Raji Ghawi
 
Java and OWL
Raji Ghawi
 
SPARQL
Raji Ghawi
 
XQuery
Raji Ghawi
 
XPath
Raji Ghawi
 
Ontology-based Cooperation of Information Systems
Raji Ghawi
 
OWSCIS: Ontology and Web Service based Cooperation of Information Sources
Raji Ghawi
 
Coopération des Systèmes d'Informations basée sur les Ontologies
Raji Ghawi
 
Building Ontologies from Multiple Information Sources
Raji Ghawi
 
Database-to-Ontology Mapping Generation for Semantic Interoperability
Raji Ghawi
 
Ad

Recently uploaded (20)

PPTX
Designing Production-Ready AI Agents
Kunal Rai
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Advancing WebDriver BiDi support in WebKit
Igalia
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Designing Production-Ready AI Agents
Kunal Rai
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Advancing WebDriver BiDi support in WebKit
Igalia
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 

Java and XML Schema

  • 1. Java and XML Schema XSOM XML Schema Object Model Raji GHAWI 19/01/2009
  • 3. Create the parser XSOMParser parser = new XSOMParser(); parser.setErrorHandler(new MyErrorHandler());
  • 4. MyErrorHandler public class MyErrorHandler implements ErrorHandler{ public void warning(SAXParseException se){ System.err.println("warning : "+se.getMessage()); } public void error(SAXParseException se){ System.err.println("error : "+se.getMessage()); } public void fatalError(SAXParseException se){ System.err.println("fatal error : "+se.getMessage()); } }
  • 5. Parse an XML schema file try { parser.parse(new File("./example.xsd")); // .... } catch (IOException ioe) { ioe.printStackTrace(); } catch (SAXException se) { se.printStackTrace(); }
  • 6. XSSchemaSet XSSchemaSet schemaSet = parser.getResult(); Iterator<XSSchema> schemaIter = schemaSet.iterateSchema(); while (schemaIter.hasNext()) { XSSchema schema = (XSSchema) schemaIter.next(); if(schema.getTargetNamespace(). equals("http://www.w3.org/2001/XMLSchema")) continue; // .... }
  • 7. <xs:element name="product"> <xs:complexType> <xs:attribute name="prodid" type="xs:positiveInteger" /> </xs:complexType> </xs:element> anonymous complex type <xs:element name="member" type="personinfo" /> <xs:complexType name="personinfo"> <xs:sequence> <xs:element name="firstname" type="xs:string" /> <xs:element name="lastname" type="xs:string" /> </xs:sequence> </xs:complexType> named complex type <xs:element name="car" default="Audi"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="Audi" /> <xs:enumeration value="Golf" /> <xs:enumeration value="BMW" /> </xs:restriction> </xs:simpleType> </xs:element> anonymous simple type <xs:element name="car2" type="carType" fixed="BMW" /> <xs:simpleType name="carType"> <xs:restriction base="xs:string"> <xs:enumeration value="Audi" /> <xs:enumeration value="Golf" /> <xs:enumeration value="BMW" /> </xs:restriction> </xs:simpleType> named simple type <xs:element name="dateborn" type="xs:date" abstract="true" /> primitive type
  • 8. Elements System.out.println("--------- elements ---------"); Iterator<XSElementDecl> elemIter = schema.iterateElementDecls(); while (elemIter.hasNext()) { XSElementDecl elem = elemIter.next(); System.out.println(describeElement(elem)); }
  • 9. Elements public static String describeElement(XSElementDecl elem) { String txt = elem.getName(); XSType type = elem.getType(); txt += (" t ("+type.toString()+")"); if (elem.isGlobal()) txt += " (global)"; else if (elem.isLocal()) txt += " (local)"; if (elem.isAbstract()) txt += " t(abstract)"; XmlString defaultValue = elem.getDefaultValue(); if(defaultValue!=null){ txt += " t(default='"+defaultValue+"')"; } } XmlString fixedValue = elem.getFixedValue(); if(fixedValue!=null){ txt += " t(fixed='"+fixedValue+"')"; } return txt; --------- elements --------car (anonymous simple type) (global) (default='Audi') member (personinfo complex type) (global) product (anonymous complex type) (global) dateborn (date simple type) (global) (abstract) car2 (carType simple type) (global) (fixed='BMW')
  • 10. Attributes System.out.println("--------- attributes ---------"); Iterator<XSAttributeDecl> attIter = schema.iterateAttributeDecls(); while (attIter.hasNext()) { XSAttributeDecl att = attIter.next(); System.out.println(describeAttribute(att)); }
  • 11. Attributes public static String describeAttribute(XSAttributeDecl att) { String txt = att.getName()+" t "+att.getType().getName(); XmlString defaultValue = att.getDefaultValue(); if(defaultValue!=null){ txt += " t(default='"+defaultValue+"')"; } XmlString fixedValue = att.getFixedValue(); if(fixedValue!=null){ txt += " t(fixed='"+fixedValue+"')"; } // isRequired ?? return txt; } <xs:attribute <xs:attribute <xs:attribute <xs:attribute name="lang1" name="lang2" name="lang3" name="lang4" type="xs:string" type="xs:string" type="xs:string" type="xs:string" /> default="EN" /> fixed="EN" /> use="required" /> --------- attributes --------lang1 string lang3 string (fixed='EN') lang2 string (default='EN') lang4 string
  • 12. Types System.out.println("--------- types ---------"); Iterator<XSType> typeIter = schema.iterateTypes(); while (typeIter.hasNext()) { XSType st = typeIter.next(); System.out.println(describeType(st)); }
  • 13. Types public static String describeType(XSType type) { String txt = ""; if(type.isAnonymous()) txt += "(anonymous)"; else txt += type.getName(); if (type.isGlobal()) txt += " (global)"; else if (type.isLocal()) txt += " (local)"; if(type.isComplexType()) txt += " (complex)"; else if(type.isSimpleType()) txt += " (simple)"; } int deriv = type.getDerivationMethod(); switch(deriv){ case XSType.EXTENSION: txt += " (EXTENSION)"; break; case XSType.RESTRICTION: txt += " (RESTRICTION)"; break; case XSType.SUBSTITUTION: txt += " (SUBSTITUTION)"; break; } return txt; --------- types --------carType (global) (simple) (RESTRICTION) personinfo (global) (complex) (RESTRICTION) Global Types only !!
  • 14. How to get all types ? public static Vector<XSType> allTypes = new Vector<XSType>(); Iterator<XSType> typeIter = schema.iterateTypes(); while (typeIter.hasNext()) { XSType st = typeIter.next(); allTypes.addElement(st); } // .... System.out.println("--------- types ---------"); for (int i = 0; i < allTypes.size(); i++) { XSType type = allTypes.get(i); System.out.println(describeType(type)); } public static String describeElement(XSElementDecl elem) { String txt = elem.getName(); XSType type = elem.getType(); if(!allTypes.contains(type)){ allTypes.addElement(type); } // .... } primitive type !! --------- types --------carType (global) (simple) (RESTRICTION) personinfo (global) (complex) (RESTRICTION) (anonymous) (local) (simple) (RESTRICTION) (anonymous) (local) (complex) (RESTRICTION) date (global) (simple) (RESTRICTION)
  • 15. How to ignore primitive types ? public static String describeElement(XSElementDecl elem) { String txt = elem.getName(); XSType type = elem.getType(); if(!allTypes.contains(type)){ if(type.isSimpleType()){ if(!type.asSimpleType().isPrimitive()){ allTypes.addElement(type); } } else { allTypes.addElement(type); } } // .... } --------- types --------carType (global) (simple) (RESTRICTION) personinfo (global) (complex) (RESTRICTION) (anonymous) (local) (simple) (RESTRICTION) (anonymous) (local) (complex) (RESTRICTION)
  • 16. Complex and Simple Types // XSType type if(type.isComplexType()){ XSComplexType complex = type.asComplexType(); // } else if(type.isSimpleType()){ XSSimpleType simple = type.asSimpleType(); // } schema.iterateSimpleTypes(); schema.iterateComplexTypes();
  • 17. XSComplexType // XSComplexType complex XSContentType contenetType = complex.getContentType(); if(contenetType instanceof EmptyImpl){ XSContentType empty = contenetType.asEmpty(); // } else if(contenetType instanceof ParticleImpl){ XSTerm term = contenetType.asParticle().getTerm(); // } else if(contenetType instanceof SimpleTypeImpl){ XSSimpleType st = contenetType.asSimpleType(); // }
  • 18. XSTerm // XSTerm term if(term.isElementDecl()){ XSElementDecl elem = term.asElementDecl(); // } else if(term.isModelGroup()){ XSModelGroup mg = term.asModelGroup(); // } else if(term.isModelGroupDecl()){ XSModelGroupDecl mgd = term.asModelGroupDecl(); XSModelGroup mg = mgd.getModelGroup(); // } else if(term.isWildcard()){ XSWildcard wildcard = term.asWildcard(); // }
  • 19. XSModelGroup // XSModelGroup modelGroup Compositor comp = modelGroup.getCompositor(); if(comp.equals(Compositor.SEQUENCE)){ // } else if(comp.equals(Compositor.ALL)){ // } else if(comp.equals(Compositor.CHOICE)){ // } XSParticle[] particles = modelGroup.getChildren(); for (int i = 0; i < particles.length; i++) { XSTerm term = particles[i].getTerm(); // .... }
  • 20. XSSimpleType // XSSimpleType simpe if(simple.isList()){ XSListSimpleType lst = simple.asList(); // } else if(simple.isUnion()){ XSUnionSimpleType ust = simple.asUnion(); // } else if(simple.isRestriction()){ XSRestrictionSimpleType rst = simple.asRestriction(); // }
  • 21. XSRestrictionSimpleType // XSRestrictionSimpleType restriction XSType baseType = restriction.getBaseType(); // .... Iterator<?> facets = restriction.getDeclaredFacets().iterator(); while (facets.hasNext()) { XSFacet facet = (XSFacet) facets.next(); String name = facet.getName(); XmlString value = facet.getValue(); if(name.equalsIgnoreCase("enumeration")){ // } else if(name.equalsIgnoreCase("minInclusive")){ // } else if(name.equalsIgnoreCase("minExclusive")){ // } else if(name.equalsIgnoreCase("maxInclusive")){ // } else if(name.equalsIgnoreCase("maxExclusive")){ // } else if(name.equalsIgnoreCase("whiteSpace")){ // } }
  • 22. References  https://xsom.dev.java.net/ (Kohsuke Kawaguchi, Sun Microsystems )  http://www.stylusstudio.com/w3c/schema0/_index.htm