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
Ad

More Related Content

What's hot (20)

Pembuatan amilum
Pembuatan amilumPembuatan amilum
Pembuatan amilum
Herni Yunita
 
Laporan lengkap nitritometri
Laporan lengkap nitritometriLaporan lengkap nitritometri
Laporan lengkap nitritometri
Nisfah Hasik
 
ppt gel
ppt gelppt gel
ppt gel
andi septi
 
Kel 6 Antialergi_5D_Farmakologi.pptx
Kel 6 Antialergi_5D_Farmakologi.pptxKel 6 Antialergi_5D_Farmakologi.pptx
Kel 6 Antialergi_5D_Farmakologi.pptx
TiaraChaerulZhanah
 
Obat anastesi lokal dan umum
Obat anastesi lokal dan umumObat anastesi lokal dan umum
Obat anastesi lokal dan umum
Titis Utami
 
Kel 10. farmakoekonomi makalah-kualitas hidup
Kel 10. farmakoekonomi makalah-kualitas hidupKel 10. farmakoekonomi makalah-kualitas hidup
Kel 10. farmakoekonomi makalah-kualitas hidup
AMIRRAHMATILLAH
 
P 4 spektrometri massa
P 4 spektrometri massaP 4 spektrometri massa
P 4 spektrometri massa
yusbarina
 
Laporan Teknologi Farmasi
Laporan Teknologi FarmasiLaporan Teknologi Farmasi
Laporan Teknologi Farmasi
Eva Apriliyana Rizki
 
Hemiselulosa.pptx
Hemiselulosa.pptxHemiselulosa.pptx
Hemiselulosa.pptx
zuhryharyono1
 
Spektrofluorumeter
SpektrofluorumeterSpektrofluorumeter
Spektrofluorumeter
indahnurfianii
 
Glikogenolisis
Glikogenolisis Glikogenolisis
Glikogenolisis
Resty88
 
turbidi dan neflo
turbidi dan nefloturbidi dan neflo
turbidi dan neflo
Puspita Diah
 
Laporan lipid
Laporan lipidLaporan lipid
Laporan lipid
Elisa Elisa
 
Analisis spektrometri
Analisis spektrometriAnalisis spektrometri
Analisis spektrometri
Nozha Diszha
 
Cosy
CosyCosy
Cosy
Faradisa Anindita
 
Selenoid: browsers in containers
Selenoid: browsers in containersSelenoid: browsers in containers
Selenoid: browsers in containers
Ivan Krutov
 
2 aldehid dan keton
2 aldehid dan keton2 aldehid dan keton
2 aldehid dan keton
Universitas Muslim Indonesia Makassar
 
Jelaskan proses sintesis epinefrin dan nonepinefin
Jelaskan proses sintesis epinefrin dan nonepinefinJelaskan proses sintesis epinefrin dan nonepinefin
Jelaskan proses sintesis epinefrin dan nonepinefin
galuh apsari
 
Konsep dasar etika farmasi umum
Konsep dasar etika farmasi umumKonsep dasar etika farmasi umum
Konsep dasar etika farmasi umum
MaswanDaulay
 
Laporan lengkap nitritometri
Laporan lengkap nitritometriLaporan lengkap nitritometri
Laporan lengkap nitritometri
Nisfah Hasik
 
Kel 6 Antialergi_5D_Farmakologi.pptx
Kel 6 Antialergi_5D_Farmakologi.pptxKel 6 Antialergi_5D_Farmakologi.pptx
Kel 6 Antialergi_5D_Farmakologi.pptx
TiaraChaerulZhanah
 
Obat anastesi lokal dan umum
Obat anastesi lokal dan umumObat anastesi lokal dan umum
Obat anastesi lokal dan umum
Titis Utami
 
Kel 10. farmakoekonomi makalah-kualitas hidup
Kel 10. farmakoekonomi makalah-kualitas hidupKel 10. farmakoekonomi makalah-kualitas hidup
Kel 10. farmakoekonomi makalah-kualitas hidup
AMIRRAHMATILLAH
 
P 4 spektrometri massa
P 4 spektrometri massaP 4 spektrometri massa
P 4 spektrometri massa
yusbarina
 
Glikogenolisis
Glikogenolisis Glikogenolisis
Glikogenolisis
Resty88
 
Analisis spektrometri
Analisis spektrometriAnalisis spektrometri
Analisis spektrometri
Nozha Diszha
 
Selenoid: browsers in containers
Selenoid: browsers in containersSelenoid: browsers in containers
Selenoid: browsers in containers
Ivan Krutov
 
Jelaskan proses sintesis epinefrin dan nonepinefin
Jelaskan proses sintesis epinefrin dan nonepinefinJelaskan proses sintesis epinefrin dan nonepinefin
Jelaskan proses sintesis epinefrin dan nonepinefin
galuh apsari
 
Konsep dasar etika farmasi umum
Konsep dasar etika farmasi umumKonsep dasar etika farmasi umum
Konsep dasar etika farmasi umum
MaswanDaulay
 

Similar to Java and XML Schema (20)

Java 5 Features
Java 5 FeaturesJava 5 Features
Java 5 Features
sholavanalli
 
Java architecture for xml binding
Java architecture for xml bindingJava architecture for xml binding
Java architecture for xml binding
Hosein Zare
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)
Domenic Denicola
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
Loïc Descotte
 
RMI Java Programming Lab Manual 2019
RMI Java Programming Lab Manual 2019RMI Java Programming Lab Manual 2019
RMI Java Programming Lab Manual 2019
Gebreigziabher Ab
 
XML Support: Specifications and Development
XML Support: Specifications and DevelopmentXML Support: Specifications and Development
XML Support: Specifications and Development
Peter Eisentraut
 
Unfiltered Unveiled
Unfiltered UnveiledUnfiltered Unveiled
Unfiltered Unveiled
Wilfred Springer
 
Summary of C++17 features
Summary of C++17 featuresSummary of C++17 features
Summary of C++17 features
Bartlomiej Filipek
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
HamletDRC
 
Sax Dom Tutorial
Sax Dom TutorialSax Dom Tutorial
Sax Dom Tutorial
vikram singh
 
Design Patterns in .Net
Design Patterns in .NetDesign Patterns in .Net
Design Patterns in .Net
Dmitri Nesteruk
 
Xml generation and extraction using XMLDB
Xml generation and extraction using XMLDBXml generation and extraction using XMLDB
Xml generation and extraction using XMLDB
pallavi kasibhotla
 
Wien15 java8
Wien15 java8Wien15 java8
Wien15 java8
Jaanus Pöial
 
Java serialization
Java serializationJava serialization
Java serialization
Ecommerce Solution Provider SysIQ
 
What is new in Java 8
What is new in Java 8What is new in Java 8
What is new in Java 8
Sandeep Kr. Singh
 
Working With XML in IDS Applications
Working With XML in IDS ApplicationsWorking With XML in IDS Applications
Working With XML in IDS Applications
Keshav Murthy
 
zinno
zinnozinno
zinno
guest6a7933
 
Swift study: Closure
Swift study: ClosureSwift study: Closure
Swift study: Closure
Futada Takashi
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
Iram Ramrajkar
 
Namespaces
NamespacesNamespaces
Namespaces
zindadili
 
Java architecture for xml binding
Java architecture for xml bindingJava architecture for xml binding
Java architecture for xml binding
Hosein Zare
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)
Domenic Denicola
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
Loïc Descotte
 
RMI Java Programming Lab Manual 2019
RMI Java Programming Lab Manual 2019RMI Java Programming Lab Manual 2019
RMI Java Programming Lab Manual 2019
Gebreigziabher Ab
 
XML Support: Specifications and Development
XML Support: Specifications and DevelopmentXML Support: Specifications and Development
XML Support: Specifications and Development
Peter Eisentraut
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
HamletDRC
 
Xml generation and extraction using XMLDB
Xml generation and extraction using XMLDBXml generation and extraction using XMLDB
Xml generation and extraction using XMLDB
pallavi kasibhotla
 
Working With XML in IDS Applications
Working With XML in IDS ApplicationsWorking With XML in IDS Applications
Working With XML in IDS Applications
Keshav Murthy
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
Iram Ramrajkar
 
Ad

More from Raji Ghawi (12)

Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming Techniques
Raji Ghawi
 
Java and XML
Java and XMLJava and XML
Java and XML
Raji Ghawi
 
Java and SPARQL
Java and SPARQLJava and SPARQL
Java and SPARQL
Raji Ghawi
 
Java and OWL
Java and OWLJava and OWL
Java and OWL
Raji Ghawi
 
SPARQL
SPARQLSPARQL
SPARQL
Raji Ghawi
 
XQuery
XQueryXQuery
XQuery
Raji Ghawi
 
XPath
XPathXPath
XPath
Raji Ghawi
 
Ontology-based Cooperation of Information Systems
Ontology-based Cooperation of Information SystemsOntology-based Cooperation of Information Systems
Ontology-based Cooperation of Information Systems
Raji Ghawi
 
OWSCIS: Ontology and Web Service based Cooperation of Information Sources
OWSCIS: Ontology and Web Service based Cooperation of Information SourcesOWSCIS: Ontology and Web Service based Cooperation of Information Sources
OWSCIS: Ontology and Web Service based Cooperation of Information Sources
Raji Ghawi
 
Coopération des Systèmes d'Informations basée sur les Ontologies
Coopération des Systèmes d'Informations basée sur les OntologiesCoopération des Systèmes d'Informations basée sur les Ontologies
Coopération des Systèmes d'Informations basée sur les Ontologies
Raji Ghawi
 
Building Ontologies from Multiple Information Sources
Building Ontologies from Multiple Information SourcesBuilding Ontologies from Multiple Information Sources
Building Ontologies from Multiple Information Sources
Raji Ghawi
 
Database-to-Ontology Mapping Generation for Semantic Interoperability
Database-to-Ontology Mapping Generation for Semantic InteroperabilityDatabase-to-Ontology Mapping Generation for Semantic Interoperability
Database-to-Ontology Mapping Generation for Semantic Interoperability
Raji Ghawi
 
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming Techniques
Raji Ghawi
 
Java and SPARQL
Java and SPARQLJava and SPARQL
Java and SPARQL
Raji Ghawi
 
Ontology-based Cooperation of Information Systems
Ontology-based Cooperation of Information SystemsOntology-based Cooperation of Information Systems
Ontology-based Cooperation of Information Systems
Raji Ghawi
 
OWSCIS: Ontology and Web Service based Cooperation of Information Sources
OWSCIS: Ontology and Web Service based Cooperation of Information SourcesOWSCIS: Ontology and Web Service based Cooperation of Information Sources
OWSCIS: Ontology and Web Service based Cooperation of Information Sources
Raji Ghawi
 
Coopération des Systèmes d'Informations basée sur les Ontologies
Coopération des Systèmes d'Informations basée sur les OntologiesCoopération des Systèmes d'Informations basée sur les Ontologies
Coopération des Systèmes d'Informations basée sur les Ontologies
Raji Ghawi
 
Building Ontologies from Multiple Information Sources
Building Ontologies from Multiple Information SourcesBuilding Ontologies from Multiple Information Sources
Building Ontologies from Multiple Information Sources
Raji Ghawi
 
Database-to-Ontology Mapping Generation for Semantic Interoperability
Database-to-Ontology Mapping Generation for Semantic InteroperabilityDatabase-to-Ontology Mapping Generation for Semantic Interoperability
Database-to-Ontology Mapping Generation for Semantic Interoperability
Raji Ghawi
 
Ad

Recently uploaded (20)

Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 

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