`
stonefox
  • 浏览: 30951 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

Java Pasing and Analyzing XSD File.

阅读更多
Have got an assaignment to add a new feature to analyze XML Schema file, dot XSD file.
e.g.
<attribute name="arrivalMoment" use="required">

<simpleType>

<restriction base="integer">
<minInclusive value="0"/>
</restriction>
</simpleType>
</attribute>

I needed to create a tabel showing as
----------------------------
name | datatype |
----------------------------
arrivalMoment | integer |
----------------------------

Though it seems we can do this work by the common way just taking the xsd file as a simple xml file, there is packaged api to fix this kind of work.

org.apache.xerces.xs
org.apache.xerces.impl.xs
http://www.w3.org/Submission/2004/SUBM-xmlschema-api-20040309/xml-schema-api.html#ItemPSVI-itemValue

Then the job can be finished not too much complicated. As the sample statements to got the type of a element of a attribute component.
// to get types of elements
String dataType = ((XSElementDecl) ((XSParticleDecl) list.item(j)).getTerm()).getTypeDefinition().getBaseType().getName();
//complexType element.{
dataType = ((XSElementDecl) ((XSParticleDecl) list.item(j)).getTerm()).getTypeDefinition().getName();

// to get types of attribute componets
String dataType = ((XSAttributeUseImpl) list.item(j)).fAttrDecl.getTypeDefinition().getName();
//attribute define its type using a internal simpleType tag
dataType = ((XSAttributeUseImpl) list.item(j)).fAttrDecl.getTypeDefinition().getBaseType().getName();

In summary, while you need to parse a xml schema file by java code directly, a entire solution to parsing and analyzing XSD file provided by Xerces may help you.






0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics