episode file for maven-jaxb22-plugin - maven-jaxb2-plugin

I have a schema A.xsd that imports B.xsd and its one of the complex element <complex-element>. Now I have created the .episode file from compiling the B.xsd and used as input to A.xsd. But except for the <complex-element>, all other child elements classes are regenerated again.
A.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://example.com/a" xmlns="http://example.com/a"
xmlns:tns="http://example.com/b" elementFormDefault="qualified">
<xs:import namespace="http://example.com/b" schemaLocation="b.xsd" />
<xs:element name="root">
<xs:complexType>
<xs:all>
<xs:element name="element1" type="xs:string" minOccurs="0" />
<!-- more elements -->
<xs:element name="elementx" type="xs:string" />
<xs:element ref="tns:complex-element" minOccurs="0" />
</xs:all>
<xs:attribute name="version" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:schema>
B.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://example.com/b" xmlns="http://example.com/b"
elementFormDefault="qualified">
<xs:element name="complex-element">
<xs:complexType>
<xs:all>
<xs:element name="list" type="list" minOccurs="0"
maxOccurs="1" />
<xs:element name="code" type="code" minOccurs="0"
maxOccurs="1" />
<xs:element name="message" type="xs:string" minOccurs="0"
maxOccurs="1" />
</xs:all>
</xs:complexType>
</xs:element>
<xs:complexType name="list">
<xs:sequence>
<xs:element name="file" type="file" minOccurs="1"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:simpleType name="code">
<xs:restriction base="xs:string">
<xs:enumeration value="S1" />
<xs:enumeration value="S2" />
<xs:enumeration value="S3" />
</xs:restriction>
</xs:simpleType>
<!-- more elements -->
</xs:schema>
pom.xml
<execution>
<id>aschema</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generateDirectory>src/main/java</generateDirectory>
<schemaIncludes>
<include>a.xsd</include>
</schemaIncludes>
<bindingIncludes>
<include>a.xjb</include>
</bindingIncludes>
<cleanPackageDirectories>false</cleanPackageDirectories>
<episode>false</episode>
<args>
<arg>-b</arg>
<arg>${basedir}/src/main/resources/b-episode</arg>
<arg>-Xinheritance</arg>
<arg>-Xxew</arg>
<arg>-Xannotate</arg>
</args>
<verbose>true</verbose>
</configuration>
</execution>
After execution, the Class ComplexElement gets correctly referenced to existing package, but all of the child elements <list> and <code> generates class under the package of org.example.com.a instead to refer existing classes inside org.example.com.b package.
b-episode
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" if-exists="true"
version="2.1">
<bindings xmlns:tns="http://example.com/b"
if-exists="true" scd="x-schema::tns">
<schemaBindings map="false">
<package name="org.example.com.b" />
</schemaBindings>
<bindings if-exists="true" scd="tns:complex-element">
<class ref="org.example.com.b.ComplexElement" />
</bindings>
<bindings if-exists="true" scd="~tns:list">
<class ref="org.example.com.b.List" />
</bindings>
<bindings if-exists="true" scd="~tns:file">
<class ref="org.example.com.b.File" />
</bindings>
<!-- and so on ... -->
</bindings>

Please follow the documentation on using episodes.
In short, instead of using the .episode file as a file, include the compiled artifact of the schema A.xsd as an episodes/episode in the plugin configuration:
<dependencies>
...
<dependency>
<groupId>com.acme.foo</groupId>
<artifactId>a-schema</artifactId>
<version>1.0</version>
</dependency>
...
</dependencies>
<build>
<defaultGoal>test</defaultGoal>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<configuration>
<extension>true</extension>
<episodes>
<episode>
<groupId>com.acme.foo</groupId>
<artifactId>a-schema</artifactId>
<!-- Version is not required if the artifact is
configured as dependency -->
</episode>
</episodes>
</configuration>
</plugin>
</plugins>
</build>
So you shouldn't -b ${basedir}/src/main/resources/b-episode etc.
Disclaimer: I'm the author of maven-jaxb2-plugin.

Related

tag validation in XSD File

Someone knows, how to implement the following validate in the XSD file:
When the tag TIPO has the value SER, it is mandatory to register the tag DETALLES_SERVICIOS otherwise if the value is EQU, it is optional
I am using the XSD version 1.0 and I can not implement a way to do this validation.
Thanks in advance for the help.
XML
<REQUERIMIENTO>
<DETALLES_SOLICITUDES>
<ID_PLAN>BP-7138</ID_PLAN>
<ID_SUBPRODUCTO>AUT</ID_SUBPRODUCTO>
<CANTIDAD>1</CANTIDAD>
<TIPO>SER</TIPO>
<DETALLES_SERVICIOS>
<NOMBRE_USUARIO>JANIO</NOMBRE_USUARIO>
<NUMERO_SERIE>12345</NUMERO_SERIE>
<IN_BODEGA>130</IN_BODEGA>
</DETALLES_SERVICIOS>
</DETALLES_SOLICITUDES>
<DETALLES_SOLICITUDES>
<ID_PLAN>0</ID_PLAN>
<ID_SUBPRODUCTO>SAMSUNG A510 G</ID_SUBPRODUCTO>
<CANTIDAD>1</CANTIDAD>
<TIPO>EQU</TIPO>
</DETALLES_SOLICITUDES>
</REQUERIMIENTO>
XSD
<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid Technologies Online Tools 1.0 (https://www.liquid-technologies.com) -->
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="REQUERIMIENTO">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="DETALLES_SOLICITUDES">
<xs:complexType>
<xs:sequence>
<xs:element name="ID_PLAN" type="xs:string" />
<xs:element name="ID_SUBPRODUCTO" type="xs:string" />
<xs:element name="CANTIDAD" type="xs:string" />
<xs:element name="TIPO">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="SER"/>
<xs:enumeration value="EQU"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" name="DETALLES_SERVICIOS">
<xs:complexType>
<xs:sequence>
<xs:element name="NOMBRE_USUARIO" type="xs:string" />
<xs:element name="NUMERO_SERIE" type="xs:unsignedShort" />
<xs:element name="IN_BODEGA" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
It is not possible to implement this in XSD-1.0, but if you find a way to use XSD-1.1, you can use the following xs:assert expression after your second xs:sequence element:
<xs:assert test="((TIPO = 'SER') and DETALLES_SERVICIOS) or (TIPO='EQU')" />
EDIT: thx to #MichaelKay to make sure that it isn't possible at all.

XML validation using XSD failing [duplicate]

This is my sample XML code:
<Address>
<StreetAddress></StreetAddress>
<OtherDestination />
<City>TORONTO</City>
</Address>
That is currently using this XSD:
<xs:element name="Address" nillable="true">
<xs:complexType>
<xs:sequence minOccurs="0">
<xs:element ref="StreetAddress" minOccurs="0"/>
<xs:element ref="OtherDestination" minOccurs="0"/>
<xs:element ref="City" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
I want to add an attribute id to Address element like this..
<Address id="first">
<StreetAddress></StreetAddress>
<OtherDestination />
<City>TORONTO</City>
</Address>
How should I change the existing XSD to fulfill my requirement?
An attribute declaration can be added within xs:complexType after the xs:sequence:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="Address">
<xs:complexType>
<xs:sequence>
<xs:element name="StreetAddress" minOccurs="0" type="xs:string"/>
<xs:element name="OtherDestination" minOccurs="0" type="xs:string"/>
<xs:element name="City" minOccurs="0" type="xs:string"/>
</xs:sequence>
<!------------------------------------------>
<!-- This is where to declare attributes: -->
<xs:attribute name="id" type="xs:string"/>
<!------------------------------------------>
</xs:complexType>
</xs:element>
</xs:schema>
The above XSD will validate your XML successfully.

SoapUI generates JSON property for namespace

I generate a WADL with CXF as described in CXF – Missing WADL method parameter element types with JSON JAX-RS services.
I tried to generate the JSON request body in SoapUI ("Recreates a default representation from the schema"), but I get the wrong JSON including namespace.
Code:
CXF configuration:
<bean id="wadlGenerator" class="org.apache.cxf.jaxrs.model.wadl.WadlGenerator">
<property name="linkJsonToXmlSchema" value="true" />
</bean>
<jaxrs:server address="/rest/1" id="test" staticSubresourceResolution="true">
<jaxrs:serviceBeans>
<ref bean="testResource" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider" />
<ref bean="wadlGenerator" />
</jaxrs:providers>
</jaxrs:server>
WADL:
<?xml version="1.0"?>
<application xmlns:prefix1="http://www.test.com/test" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://wadl.dev.java.net/2009/02">
<grammars>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.test.com/test" targetNamespace="http://www.test.com/test" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xs:import/>
<xs:element name="testModel" type="testModel"/>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.test.com/test" targetNamespace="http://www.test.com/test" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xs:complexType name="testModel">
<xs:sequence>
<xs:element name="id" type="xs:string"/>
<xs:element name="name" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</grammars>
<resources base="http://localhost:8080/test-app/services/rest/1">
<resource path="/test">
<method name="POST">
<request>
<representation mediaType="application/json" element="prefix1:testModel"/>
</request>
<response status="204"/>
</method>
</resource>
</resources>
</application>
JSON:
{
"#xmlns:test": "http://www.test.com/test",
"id": "?",
"name": "?"
}
Is that a bug/missing feature of SoapUI or is there something wrong with my WADL?

Unable to debug a map file due to Typed Polling schema in Biztalk

I have the below mentioned source schema.
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://schemas.microsoft.com/Sql/2008/05/TypedPolling/EmailNotifications" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="TypedPolling">
<xs:complexType>
<xs:sequence>
<xs:element name="TypedPollingResultSet0">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="TypedPollingResultSet0">
<xs:complexType>
<xs:sequence>
<xs:element name="strPortName" type="xs:string" />
<xs:element name="LastRun_UTC" type="xs:dateTime" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The destination schema is
<?xml version="1.0" encoding="utf-16" ?>
<xs:schema xmlns="http://_024_EmailNotifications_Schemas.BizTalkDTADBExtractMod" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://_024_EmailNotifications_Schemas.BizTalkDTADBExtractMod" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="Notification">
<xs:complexType>
<xs:sequence>
<xs:element name="strPortName" type="xs:string" />
<xs:element name="LastRun_UTC" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I have a map as shown below
The input file for the map is
<ns0:Root xmlns:ns0="http://schemas.microsoft.com/BizTalk/2003/aggschema">
<InputMessagePart_0>
<ns1:EmailNotifications xmlns:ns1="http://024_EmailNotifications_Schemas.XMLConfig">
<App>
<Name>App1</Name>
<Port>Port1</Port>
<Email>email</Email>
</App>
<App>
<Name>App2</Name>
<Port>Port2</Port>
<Email>Email2</Email>
</App>
<App>
<Name>App3</Name>
<Port>Port3</Port>
<Email>Email3</Email>
</App>
<App>
<Name>App4</Name>
<Port />
<Email>Email4</Email>
</App>
</ns1:EmailNotifications>
</InputMessagePart_0>
<InputMessagePart_1>
<ns2:TypedPolling xmlns:ns2="http://schemas.microsoft.com/Sql/2008/05/TypedPolling/EmailNotifications">
<TypedPollingResultSet0>
<TypedPollingResultSet0>
<strPortName>Port1</strPortName>
<LastRun_UTC>2016-01-29T10:20:10.083Z</LastRun_UTC>
</TypedPollingResultSet0>
<TypedPollingResultSet0>
<strPortName>Port2</strPortName>
<LastRun_UTC>2016-01-29T11:37:38.82Z</LastRun_UTC>
</TypedPollingResultSet0>
<TypedPollingResultSet0>
<strPortName>Port3</strPortName>
<LastRun_UTC>2016-01-29T11:37:39.353Z</LastRun_UTC>
</TypedPollingResultSet0>
</TypedPollingResultSet0>
</ns2:TypedPolling>
</InputMessagePart_1>
</ns0:Root>
When I try to run the debug option in the map, I get this error which is preventing me from debugging the map, and I don't have a clue how to fix it. Appreciate any help I can get
E:\temp\EmailNotifications\InputInternal.xml: error btm1044: Input validation error: The element 'TypedPolling' in namespace 'http://schemas.microsoft.com/Sql/2008/05/TypedPolling/EmailNotifications' has invalid child element 'TypedPollingResultSet0' in namespace 'http://schemas.microsoft.com/Sql/2008/05/TypedPolling/EmailNotifications'. List of possible elements expected: 'TypedPollingResultSet0'.
When you do not specify the maxOccurs, it defaults to 1. Try setting the nested <TypedPollingResultSet0> element's maxOccurs to unbounded:
<xs:element name="TypedPollingResultSet0">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="TypedPollingResultSet0">
I'm not 100% sure of what corrected my issue.
I changed the name space from ..../EmailNotifications to ..../EmailNotification
That resolved the wiggly line issue in the input xml file in the visual studio.
Then I regenerated the schema file from the input file and viola the issue got resolved.
Thanks Gruff for the help

xsd substitution or xlt transformation

How Do I Change this XSD using substitution to get the following outcome?
I have a XML that is being returned from my asp.net API from a Saas providor. The service comes from asp.net mvc however, I can only use asp classic, and i'm pretty limited in what i can do. I can send TSQL queries to the SQL server 2005... Other than that there's not much that can be done. So my only option for what i need (well my best current option) is this. The data returns from my asp classic page service.asp. service.asp returns the structured xml based off an XSD file that is in the same folder as my script to get the data. I'll show you what it currently returns, what the current xsd is, and what it should return, and the modifications I tried making to the XSD. Hopefully that's the info someone will need to help me as this isn't exactly my strong suite. Thanks!
Current XML Response
Currently the data returns like this:
<xmldata>
<group>
<groupid>1</groupid>
<parentid>2</parentid>
<item>133</item>
<ProductCode>blahblah</ProductCode>
<ProductName>blahblah</ProductName>
</group>
<group>
<groupid>2</groupid>
<parentid>2</parentid>
<item>134</item>
<ProductCode>blahblah</ProductCode>
<ProductName>blahblah</ProductName>
</group>
<group>
<groupid>2</groupid>
<parentid>2</parentid>
<item>313</item>
<ProductCode>blahblah</ProductCode>
<ProductName>blahblah</ProductName>
</group>
<group>
<groupid>3</groupid>
<parentid>2</parentid>
<item>46</item>
<ProductCode>blahblah</ProductCode>
<ProductName>blahblah</ProductName>
</group>
</xmldata>
Current XSD File
My current XSD File is structured as follows:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="xmldata" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop">
<xs:element name="xmldata" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="groups">
<xs:complexType>
<xs:sequence>
<xs:element msprop:TableNameXsd="groupid" name="groupid" msprop:SqlDbType="Int" msprop:IsIdentity="true" minOccurs="0" />
<xs:element name="ParentID" msprop:SqlDbType="Int" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="groupproductlink">
<xs:complexType>
<xs:sequence>
<xs:element msprop:TableNameXsd="groupproductlink" name="ID" msprop:SqlDbType="Int" msprop:IsIdentity="true" minOccurs="0" />
<xs:element name="groupID" msprop:SqlDbType="Int" minOccurs="0" />
<xs:element name="ProductCode" msprop:SqlDbType="Int" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Products">
<xs:complexType>
<xs:sequence>
<xs:element msprop:TableNameXsd="Products" name="AutoDropShip" msprop:maxLength="1" msprop:SQLTableAlias="p" msprop:SqlDbType="VarChar" msprop:SQLFrom="FROM vm.Products p INNER JOIN vm.Products_Descriptions pd ON p.ProductCode = pd.ProductCode INNER JOIN vm.PE pe ON p.ProductCode = pe.ProductCode INNER JOIN vm.Products_Memos pm ON p.ProductCode = pm.ProductCode" minOccurs="0" />
<xs:element name="productid" msprop:maxLength="30" msprop:SQLTableAlias="p" msprop:SqlDbType="VarChar" minOccurs="1" />
<xs:element name="ProductCode" msprop:SQLTableAlias="p" msprop:SqlDbType="Int" msprop:IsIdentity="true" minOccurs="0" />
<xs:element name="ProductName" msprop:maxLength="255" msprop:SQLTableAlias="p" msprop:SqlDbType="VarChar" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
What the XML Should Be
The XML Needs to be returned in the following way (please note the attribute becoming the element)
<groups>
**<1> //<---Element=groupID**
<item>133</item>
<parentid>2</parentid>
<ProductCode>blahblah</ProductCode>
<ProductName>blahblah</ProductName>
**</1> //<---Element=groupID
<2> //<---Element=groupID**
<item>134</item>
<parentid>2</parentid>
<ProductCode>blahblah</ProductCode>
<ProductName>blahblah</ProductName>
**</2> //<---Element=groupID
<2> //<---Element=groupID**
<item>313</item>
<parentid>2</parentid>
<ProductCode>blahblah</ProductCode>
<ProductName>blahblah</ProductName>e="1">
**</2> //<---Element=groupID
<3> //<---Element=groupID**
<item>46</item>
<parentid>2</parentid>
<ProductCode>blahblah</ProductCode>
<ProductName>blahblah</ProductName>
**</3> //<---Element=groupID**
</groups>
The XSD I attempted to use and didn't get any response
I tried transforming the XSD that I listed above to the following:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="groups" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:msprop="urn:schemas-microsoft-com:xml-msprop">
**<xs:element name="groups" *msdata:IsDataSet="true"* msdata:UseCurrentLocale="true">**
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="groupid" *msdata:IsDataSet="true"* msdata:UseCurrentLocale="true" msprop:TableNameXsd="groupid" msprop:SqlDbType="Int" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element msprop:TableNameXsd="groupid" name="groupid" msprop:SqlDbType="Int" msprop:IsIdentity="true" minOccurs="0" />
<xs:element name="ParentID" msprop:SqlDbType="Int" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="groupproductlink">
<xs:complexType>
<xs:sequence>
<xs:element msprop:TableNameXsd="groupproductlink" name="ID" msprop:SqlDbType="Int" msprop:IsIdentity="true" minOccurs="0" />
<xs:element name="groupID" msprop:SqlDbType="Int" minOccurs="0" />
<xs:element name="ProductCode" msprop:SqlDbType="Int" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Products">
<xs:complexType>
<xs:sequence>
<xs:element msprop:TableNameXsd="Products" name="AutoDropShip" msprop:maxLength="1" msprop:SQLTableAlias="p" msprop:SqlDbType="VarChar" msprop:SQLFrom="FROM vm.Products p INNER JOIN vm.Products_Descriptions pd ON p.ProductCode = pd.ProductCode INNER JOIN vm.PE pe ON p.ProductCode = pe.ProductCode INNER JOIN vm.Products_Memos pm ON p.ProductCode = pm.ProductCode" minOccurs="0" />
<xs:element name="productid" msprop:maxLength="30" msprop:SQLTableAlias="p" msprop:SqlDbType="VarChar" minOccurs="1" />
<xs:element name="ProductCode" msprop:SQLTableAlias="p" msprop:SqlDbType="Int" msprop:IsIdentity="true" minOccurs="0" />
<xs:element name="ProductName" msprop:maxLength="255" msprop:SQLTableAlias="p" msprop:SqlDbType="VarChar" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
However,
It doesn't work currently. I think maybe I need to use a substitution group, however unfortunately it's been years since I did this and I can't remember what exactly I need to do. I truly hope someone here has some better ideas!