[](https://search.maven.org/#artifactdetails%7Ccom.github.xmlet%7CxsdParser%7C1.0.7%7Cjar)
[](https://sonarcloud.io/dashboard?id=com.github.xmlet%3AxsdParser)
[](https://sonarcloud.io/component_measures/domain/Coverage?id=com.github.xmlet%3AxsdParser)
[](https://sonarcloud.io/dashboard?id=com.github.xmlet%3AxsdParser)
[](https://sonarcloud.io/dashboard?id=com.github.xmlet%3AxsdParser)
# XsdParser
<div align="justify">
XsdParser is a library that parses a XML Definition file (.xsd) into a list of java objects. Each different XSD tag has
a corresponding Java class and the attributes of a given XSD type are represented as fields of that class. All these classes derive from the
same abstract class, <i>XsdAbstractElement</i>. All Java representations of the XSD elements follow the schema definition
for XSD. For example, the <i>xsd:annotation</i> tag only allows <i>xsd:appinfo</i> and <i>xsd:documentation</i> as children nodes,
and also can have an attribute named <i>id</i>, therefore XsdParser has the following class (simplified for example purposes):
<br />
<br />
</div>
```java
public class XsdAnnotation extends XsdAbstractElement {
private String id;
private List<XsdAppInfo> appInfoList = new ArrayList<>();
private List<XsdDocumentation> documentations = new ArrayList<>();
// (...)
}
```
<div align="justify">
The set of rules followed by this library can be consulted in the following URL: <a href="http://www.datypic.com/sc/xsd/s-xmlschema.xsd.html">XSD Schema</a>
</div>
## Installation
<div align="justify">
First, in order to include it to your Maven project, simply add this dependency:
<br />
<br />
</div>
```xml
<dependency>
<groupId>com.github.xmlet</groupId>
<artifactId>xsdParser</artifactId>
<version>1.1.2</version>
</dependency>
```
## Usage example
<div align="justify">
A simple example:
<br />
<br />
</div>
```java
public class ParserApp {
public static void main(String [] args) {
String filePath = "Your file path here.";
XsdParser parserInstance1 = new XsdParser(filePath);
//or
String jarPath = "Your jar path here.";
String jarXsdPath = "XSD file path, relative to the jar root.";
XsdParserJar parserInstance2 = new XsdParserJar(jarPath, jarXsdPath);
Stream<XsdElement> elementsStream = parserInstance1.getResultXsdElements(filePath);
Stream<XsdSchema> schemasStream = parserInstance1.getResultXsdSchemas(filePath);
}
}
```
<div align="justify">
After parsing the file like shown above it's possible to start to navigate in the resulting parsed elements. In the
image below it is presented the class diagram that could be useful before trying to start navigating in the result.
There are multiple abstract classes that allow to implement shared features and reduce duplicated code.
<br />
<br />
<img src="https://raw.githubusercontent.com/xmlet/XsdParser/master/src/main/java/org/xmlet/xsdparser/xsdelements/xsdelements.png"/>
</div>
### Navigation
<div align="justify">
Below a simple example is presented. After parsing the XSD snippet the parsed elements can be accessed with the respective
java code.
<br />
<br />
</div>
```xml
<?xml version='1.0' encoding='utf-8' ?>
<xsd:schema xmlns='http://schemas.microsoft.com/intellisense/html-5' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
<xsd:group name="flowContent">
<xsd:all>
<xsd:element name="elem1"/>
</xsd:all>
</xsd:group>
<xs:element name="html">
<xs:complexType>
<xsd:choice>
<xsd:group ref="flowContent"/>
</xsd:choice>
<xs:attribute name="manifest" type="xsd:anyURI" />
</xs:complexType>
</xs:element>
</xsd:schema>
```
<div align="justify">
The result could be consulted in the following way:
<br />
<br />
</div>
```java
public class ParserApp {
public static void main(String [] args) {
//(...)
XsdElement htmlElement = elementsStream.findFirst().get();
XsdComplexType htmlComplexType = htmlElement.getXsdComplexType();
XsdAttribute manifestAttribute = htmlComplexType.getXsdAttributes().findFirst().get();
XsdChoice choiceElement = htmlComplexType.getChildAsChoice();
XsdGroup flowContentGroup = choiceElement.getChildrenGroups().findFirst().get();
XsdAll flowContentAll = flowContentGroup.getChildAsAll();
XsdElement elem1 = flowContentAll.getChildrenElements().findFirst().get();
}
}
```
## Parsing Strategy
<div align="justify">
In order to minimize the number of passages in the file, which take more time to perform, this library chose to parse
all the elements and then resolve the references present. To parse the XSD file we use the DOM library, which converts
all the XSD elements into <i>Node</i> objects, from where we extract all the XSD information into our XSD respective classes.
<br />
<br />
Our parse process is also based on a tree approach, which means that when we invoke the <i>XsdSchema parse</i> function
the whole document will be parsed, because each <i>XsdAbstractElement</i> class extracts its respective information, i.e. a
<i>XsdSchema</i> instance extracts information from the received xsd:schema <i>Node</i> object, and also invokes the
respective parse function for each children elements present in its current <i>Node</i> object.
</div>
### Type Validations
<div align="justify">
This library was born with an objective in mind, it should strictly follow the XSD language rules. To guarantee that
we used the Visitor pattern. We used this pattern to add a layer of control regarding different XSD types interactions.
In the presented code snippet we can observe how this works:
<br />
<br />
</div>
```java
class XsdComplexContentVisitor extends XsdAnnotatedElementsVisitor {
private final XsdComplexContent owner;
@Override
public void visit(XsdRestriction element) {
owner.setRestriction(ReferenceBase.createFromXsd(element));
}
@Override
public void visit(XsdExtension element) {
owner.setExtension(ReferenceBase.createFromXsd(element));
}
}
```
<div align="justify">
In this example we can see that <i>XsdComplexContentVisitor</i> class only implements two methods, <i>visit(XsdRestriction element)</i>
and <i>visit(XsdExtension element)</i>. This means that the <i>XsdComplexContentVisitor</i> type only allows these two
types, i.e. <i>XsdRestriction</i> and <i>XsdExtension</i>, to interact with <i>XsdComplexContent</i>, since these two
types are the only types allowed as <i>XsdComplexContent</i> children elements.
</div>
<div align="justify">
The XSD syntax also especifies some other restrictions, namely regarding attribute possible values or types. For example
the <i>finalDefault</i> attribute of the xsd:schema elements have their value restricted to six distinct values:
<br />
<br />
<ul>
<li>
DEFAULT ("")
</li>
<li>
EXTENSION ("extension")
</li>
<li>
RESTRICTION ("restriction")
</li>
<li>
LIST("list")
</li>
<li>
UNION("union")
</li>
<li>
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
XsdParser XsdParser是一个将XML定义文件(.xsd)解析为Java对象列表的库。 每个不同的XSD标记都有一个对应的Java类,并且给定XSD类型的属性表示为该类的字段。 所有这些类都源自同一抽象类XsdAbstractElement 。 XSD元素的所有Java表示形式都遵循XSD的架构定义。 例如, xsd:annotation标记仅允许xsd:appinfo和xsd:documentation作为子节点,并且还可以具有名为id的属性,因此XsdParser具有以下类(出于示例目的而进行了简化): public class XsdAnnotation extends
资源推荐
资源详情
资源评论











格式:zip 资源大小:22.8KB

格式:zip 资源大小:33.7KB

格式:zip 资源大小:11.4MB









格式:zip 资源大小:597.9KB



格式:xsd 资源大小:61.2KB



格式:zip 资源大小:4.0KB
收起资源包目录





































































































共 146 条
- 1
- 2
资源评论

- weixin_423142892023-11-02运行 出错,找不到文件

火君
- 粉丝: 35
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 学生信息管理数据库设计研究报告.doc
- 大数据时代档案管理工作如何与时俱进.docx
- 物联网工程专业计算机组成原理教学改革探索.docx
- 软件工程专业本科实践教学改革研究.docx
- 校园监控系统设计方案(本地监控和网络集中管理结合).doc
- 鼎利微博FTP功能操作指导.ppt
- 数控编程实验指导说明书(修改).doc
- 现代中庆网络化多媒体教室建设方案3110DG-L.doc
- 新工科背景下通信原理教学研究.docx
- 大数据与机器学习构建动态企业级画像系统.docx
- 浅述机电设各安装工程项目管理.docx
- 这篇文章详细探讨了基于属性偏序原理的属性偏序结构图表示算法,涵盖了从理论基础到具体实现的多个方面(论文复现含详细代码及解释)
- 数据库系统在计算机体系结构中的应用.docx
- 云南水电厂技术监督评价大刚(自动化).doc
- 基于计算机视觉技术的细胞检测模型研究与应用
- 【机械臂控制】基于事件触发的复合阻抗控制方法设计与仿真:提高机械臂力位跟踪精度及通信资源利用率(论文复现含详细代码及解释)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
