Java/XSD parsing

泄露秘密 提交于 2020-01-01 09:28:12

问题


I doubt if there is something like this but I thought to ask though:
Does anyone know if there is a library in Java that reads an xsd file and "creates" the defined elements e.g. in a String format to use in the code?
E.g. read in the following schema:

<?xml version="1.0" encoding="utf-8"?>
        <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
          <xs:element name="Address">
            <xs:complexType>
              <xs:sequence>
                  <xs:element name="Street" type="xs:string" />
                  <xs:element name="Town" type="xs:string" />
                  <xs:element name="Country" type="xs:string" minOccurs="0" />
                </xs:element>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:schema>

And have a String in the following format:

<Address>  
  <Street></Street>
  <Town></Town>
  <Country></Country>
</Address>

Automatic tools do something similar, i.e. parse a WSDL and from the types section create for example JAXB classes that can be instances of the elements defined in schema.
Is there any library to do this?

UPDATE:
For example in Eclipse when creating an xml descriptor for a web application it presents a tree table with all the required elements for the users to fill in according to schema. How do they do it? I imagine they parse the xsds included in the jars
Any input is very welcome.
Thank you!


回答1:


If its a WSDL file with which you want to generate Java classes, then Axis WSDL2Java (based on JAXB) can be used to get classes based on the schema defined in the WSDL.

JAXB also offers binding framework which you might want to look up.

http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/twbs_jaxbschema2java.html

Above link should be useful.




回答2:


oXygen has an XML instance generator that can generate a set of XML document samples based on a given XML Schema.

You can also invoke it from the commandline.



来源:https://stackoverflow.com/questions/4484610/java-xsd-parsing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!