使用JAVA将{XSD转换为XML样本格式

时间:2017-01-16 07:28:11

标签: java xml xsd jaxb jaxb2

我有一种XSD格式,我想要一种XML格式,它只包含XML的基本样本表示及其元素表示,而不管XSD中是否有重复规则。

以下是XSD数据:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:info1_module="info1" xmlns:info2="info2" xmlns:info3="info3" targetNamespace="info4" elementFormDefault="unqualified" attributeFormDefault="unqualified" version="1.2">
    <xsd:annotation>
        <xsd:documentation></xsd:documentation>
    </xsd:annotation>
    <xsd:import namespace="info" schemaLocation="location1"/>
    <xsd:import namespace="info" schemaLocation="location2"/>
    <xsd:element name="foodAndBeverageIngredientInformationModule" type="food_and_beverage_ingredient_information_module:TSD_FoodAndBeverageIngredientInformationModuleType"/>
    <xsd:complexType name="TSD_FoodAndBeverageIngredientInformationModuleType">
        <xsd:sequence>
            <xsd:element name="ingredientStatement" type="tsd_common:TSD_FormattedDescription5000Type" minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="additivesStatement" type="tsd_common:TSD_FormattedDescription1000Type" minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="foodAndBeverageIngredient" type="food_and_beverage_ingredient_information_module:TSD_FoodAndBeverageIngredientType" minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="avpList" type="tsd_common:TSD_AttributeValuePairListType" minOccurs="0"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="TSD_FoodAndBeverageIngredientType">
        <xsd:sequence>
            <xsd:element name="ingredientName" type="shared_common:Description70Type" maxOccurs="unbounded"/>
            <xsd:element name="ingredientSequence">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string">
                        <xsd:maxLength value="70"/>
                        <xsd:minLength value="1"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
            <xsd:element name="ingredientContentPercentage" type="xsd:decimal" minOccurs="0"/>
            <xsd:element name="ingredientCountryOfOriginCode" type="shared_common:CountryCodeType" minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="ingredientCatchZone" minOccurs="0" maxOccurs="unbounded">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:string">
                        <xsd:maxLength value="70"/>
                        <xsd:minLength value="1"/>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>
            <xsd:element name="isIngredientHighlighted" type="xsd:boolean" minOccurs="0"/>
            <xsd:element name="avpList" type="tsd_common:TSD_AttributeValuePairListType" minOccurs="0"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:schema>

XML:

<ingredientStatement languageCode=""></ingredientStatement>
<additivesStatement languageCode=""></additivesStatement>
<foodAndBeverageIngredient>
    <ingredientName languageCode=""></ingredientName>
    <ingredientContentPercentage></ingredientContentPercentage>
    <ingredientSequence></ingredientSequence>
    <ingredientCountryOfOriginCode></ingredientCountryOfOriginCode>
    <ingredientCatchZone></ingredientCatchZone>
    <isIngredientHighlighted></isIngredientHighlighted>
</foodAndBeverageIngredient>

请帮助我。

1 个答案:

答案 0 :(得分:0)

您可以使用Apache的xsd2inst开源和跨平台选项:XMLBeans