gpt4 book ai didi

java - Castor 为复杂类型生成类不起作用

转载 作者:行者123 更新时间:2023-12-01 05:51:14 26 4
gpt4 key购买 nike

您好,我有以下内容,它没有使用bindigs.xml 文件为复杂类型生成类文件。

示例.xsd 文件

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Data">
<xs:annotation>
<xs:documentation>This section contains the supply chain message
data</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:choice>
<xs:element name="PurchaseOrder">
<xs:complexType>
<xs:sequence>
<xs:element name="LineItem" type="LineItemType" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="OrderNumber" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="OrderReceipt">
<xs:complexType>
<xs:sequence>
<xs:element name="LineItem" type="ReceiptLineItemType" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="OrderNumber" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:complexType name="SkuType">
<xs:annotation>
<xs:documentation>Contains Product Identifier</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="Number" type="xs:integer"/>
<xs:element name="ID" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ReceiptSkuType">
<xs:annotation>
<xs:documentation>Contains Product Identifier</xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="SkuType">
<xs:sequence>
<xs:element name="InternalID" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="LineItemType">
<xs:sequence>
<xs:element name="Sku" type="SkuType"/>
<xs:element name="Value" type="xs:double"/>
<xs:element name="BillingInstructions" type="xs:string"/>
<xs:element name="DeliveryDate" type="xs:date"/>
<xs:element name="Number" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ReceiptLineItemType">
<xs:sequence>
<xs:element name="Sku" type="ReceiptSkuType"/>
<xs:element name="Value" type="xs:double"/>
<xs:element name="PackingDescription" type="xs:string"/>
<xs:element name="ShipDate" type="xs:dateTime"/>
<xs:element name="Number" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

绑定(bind).xml

<binding xmlns="http://www.castor.org/SourceGenerator/Binding" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.castor.org/SourceGenerator/Binding
C:\\Castor\\xsd\\binding.xsd"
defaultBinding="element">

<elementBinding name="/Data/PurchaseOrder/LineItem">
<java-class name="PurchaseOrderLineItem"/>
</elementBinding>

<elementBinding name="/Data/OrderReceipt/LineItem">
<java-class name="OrderReceiptLineItem1"/>
</elementBinding>

<elementBinding name="/complexType:ReceiptLineItemType/Sku">
<java-class name="Xxxxxx"/>
</elementBinding>

<elementBinding name="/complexType:LineItemType/Sku">
<java-class name="Yyyyyy"/>
</elementBinding>

</binding>

pom.xml插件配置:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>castor-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<bindingfile>src/main/castor/binding.xml</bindingfile>
<schema>src/main/castor/sample.xsd</schema>
<packaging>com.sg.defi.castor.correspondence</packaging>
<properties>src/main/castor/castorbuilder.properties</properties>
</configuration>
</plugin>

在任何 .properties 文件中是否需要更改任何内容,以便使用给定复杂类型的绑定(bind).xml 文件的名称生成类文件。

最佳答案

想通了! ,

将复杂类型的 binding.xml 修改为

<elementBinding name="/complexType:ReceiptLineItemType/Sku">    
<java-class name="Xxxxxx"/>
</elementBinding>

Change the above code to

<complexTypeBinding name="complexType:ReceiptLineItemType/Sku">
<java-class name="Xxxxxx"/>
</complexTypeBinding>

非常遗憾的是,castor 网站本身以错误的方式发布了示例

http://www.castor.org/how-to-use-a-binding-file-with-source-generation.html

关于java - Castor 为复杂类型生成类不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4624946/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com