本文介绍了使用Java获取.XSD文件的对象表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 在Java中获取XML模式(.XSD)的静态类型表示的最简单方法是什么? 更具体地说,希望能够以编程方式遍历XSD中所有已定义的simpleType:s和complexType:s,获取已定义的元素及其类型等。 以下内容: for(XsdComplexType complexType:document.getDefinedComplexTypes()){ .. } 请注意:我所说的是.XSD文档的对象表示。我不是要从XML模式中寻找 xjc 样式生成的Java类。 一种方法是只需将标准的XML阅读工具应用于.XSD文件,但我认为有一些开源库可以帮助我解决这个问题。如上面的伪代码所示,我想要一个XSD文档的静态类型表示。解决方案查看 Castor XML库的 Schema 类。和 SchemaReader 加载它起来。它应该是你正在寻找的。 包含如下方法: public java.util.Enumeration getComplexTypes()返回: an所有顶级ComplexType声明的枚举 What is the easiest way to obtain a statically typed representation of an XML schema (.XSD) in Java?More specifically I want to be able to programatically traverse all defined simpleType:s and complexType:s in the XSD, obtain defined elements and their types, etc.Something along the lines of:for (XsdComplexType complexType : document.getDefinedComplexTypes()) { ..}Please note: I'm talking about an object representation of the .XSD document. I'm not looking for xjc style generation of Java classes from an XML schema.One approach would be to simply apply standard XML reading tools to the .XSD file, but I'd assume there are open-source libraries around that could help me tackle the problem. As seen in the pseudo-code above I'd like a statically typed representation of the XSD document. 解决方案 Check out the Castor XML library's Schema class. And the SchemaReader to load it up. It should be exactly what you're looking for.Contains methods like: public java.util.Enumeration getComplexTypes() Returns: an Enumeration of all top-level ComplexType declarations 这篇关于使用Java获取.XSD文件的对象表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-05 05:28