Java 获取xsd文件body,使用Java获取.XSD文件的对象表示

该博客介绍了如何利用Castor XML库在Java中获取XML Schema(XSD)的静态类型表示。作者希望遍历XSD文件中的所有简单类型和复杂类型,获取元素及其类型等信息,并提供了Castor XML的Schem类和SchemaReader作为解决方案,这些类提供了如getComplexTypes()等方法,便于程序化地访问XSD文档的内容。
摘要由CSDN通过智能技术生成

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
XSD专程XML,非常实用。class CSaxContentHandler : public ISAXContentHandler { public: CSaxContentHandler(); virtual ~CSaxContentHandler(); virtual long __stdcall QueryInterface(const struct _GUID &, void **); virtual unsigned long __stdcall AddRef(void); virtual unsigned long __stdcall Release(void); virtual HRESULT STDMETHODCALLTYPE putDocumentLocator( /* [in] */ ISAXLocator __RPC_FAR *pLocator); virtual HRESULT STDMETHODCALLTYPE startDocument(void); virtual HRESULT STDMETHODCALLTYPE endDocument(void); virtual HRESULT STDMETHODCALLTYPE startPrefixMapping( /* [in] */ wchar_t __RPC_FAR *pwchPrefix, /* [in] */ int cchPrefix, /* [in] */ wchar_t __RPC_FAR *pwchUri, /* [in] */ int cchUri); virtual HRESULT STDMETHODCALLTYPE endPrefixMapping( /* [in] */ wchar_t __RPC_FAR *pwchPrefix, /* [in] */ int cchPrefix); virtual HRESULT STDMETHODCALLTYPE startElement( /* [in] */ wchar_t __RPC_FAR *pwchNamespaceUri, /* [in] */ int cchNamespaceUri, /* [in] */ wchar_t __RPC_FAR *pwchLocalName, /* [in] */ int cchLocalName, /* [in] */ wchar_t __RPC_FAR *pwchRawName, /* [in] */ int cchRawName, /* [in] */ ISAXAttributes __RPC_FAR *pAttributes); virtual HRESULT STDMETHODCALLTYPE endElement( /* [in] */ wchar_t __RPC_FAR *pwchNamespaceUri, /* [in] */ int cchNamespaceUri, /* [in] */ wchar_t __RPC_FAR *pwchLocalName, /* [in] */ int cchLocalName, /* [in] */ wchar_t __RPC_FAR *pwchRawName, /* [in] */ int cchRawName); virtual HRESULT STDMETHODCALLTYPE characters( /* [in] */ wchar_t __RPC_FAR *pwchChars, /* [in] */ int cchChars); virtual HRESULT STDMETHODCALLTYPE ignorableWhitespace( /* [in] */ wchar_t __RPC_FAR *pwchChars, /* [in] */ int cchChars); virtual HRESU
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值