XSD validation error using choices - java

I need either element A or B or both. If i use choices, then it throws an exception Element 'A' cannot have character [children], because the type's content type is element-only.
How to achieve the desired result.
<xsd:complexType>
<xsd:sequence>
<xsd:element name="A">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="C"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="B"/>
</xsd:sequence>
</xsd:complexType>
sample XML is
<start>
<A>
<C>hhg</C>
</A>
</start>
<start>
<A>
<C>hhg</C>
</A>
<B>fgeg</B>
</start>
<start>
<B>fergf</B>
</start>

Use minOccurs="0", e.g.:
<xs:element name="A" minOccurs="0">
...
<xs:element name="B" minOccurs="0"/>
For XML:
<root>
<start>
<A>
<C>hhg</C>
</A>
</start>
<start>
<A>
<C>hhg</C>
</A>
<B>fgeg</B>
</start>
<start>
<B>fergf</B>
</start>
</root>
Appropriate XSD should be:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="start">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="A">
<xs:complexType>
<xs:sequence>
<xs:element name="C" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" name="B" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="test">
<xs:choice>
<xs:element name="A">
<xs:complexType>
<xs:sequence>
<xs:element name="C"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="B"/>
</xs:choice>
</xs:complexType>
</xs:schema>
This is validated ok in Oxygen ...

Related

Issue with XSD schema in transforming data from XML to JSON format

I am trying to transform data from xml to json format, For that I have written xsd schema from the xml output to transform data from xml to json.
Following is my xml which needs to be transformed to json
<?xml version="1.0" encoding="UTF-8"?>
<SyncData>
<Employerid>12345</Employerid>
<ImporterEmail>abcdef#xyz.com</ImporterEmail>
<ReportEmail>abcdefggggg#xyz.com</ReportEmail>
<Employees>
<wd:WorkerSummary xmlns:is="java:com.workday.esb.intsys.xpath.
ParsedIntegrationSystemFunctions"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xdiff="urn:com.workday/esb/xdiff" xmlns:wd="urn:com.workday/bsvc">
<wd:ReferenceID/>
<wd:Name>abcdef,ghijklm</wd:Name>
<wd:Title/>
<wd:EmployeeId>JG00889</wd:EmployeeId>
<wd:EMail>sderf.rtyui#xyzz.com</wd:EMail>
<wd:AddressLine1>1400 Post Alm Tyui</wd:AddressLine1>
<wd:City>Bostonn</wd:City>
<wd:State>MC</wd:State>
<wd:Zip>11067</wd:Zip>
<wd:Country>AUS</wd:Country>
</wd:WorkerSummary>
</Employees>
</SyncData>
Following are the two different xsd schema’s that I have defined from the above stated xml and I am getting different error’s for each one.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.your-company.com/WorkermapSchema"
xmlns:tns="http://www.your-company.com/WorkermapSchema"
elementFormDefault="qualified">
<xs:element name="WorkerSummary">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="ReferenceID" />
<xs:element type="xs:string" name="Name" />
<xs:element type="xs:string" name="Title" />
<xs:element type="xs:string" name="EmployeeId" />
<xs:element type="xs:string" name="EMail" />
<xs:element type="xs:string" name="AddressLine1" />
<xs:element type="xs:string" name="City" />
<xs:element type="xs:string" name="State" />
<xs:element type="xs:string" name="Zip" />
<xs:element type="xs:string" name="Country" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The error I was getting with this schema is as following
com.workday.esb.xmltojson.XmlToJsonException: Root Element type not found "SyncData"
Since the above error says the Root Element “SyncData” not found, I have tried to define schema in other way with the Root Element as following.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="NewDataSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-
microsoft-com:xml-msdata" xmlns:app1="urn:com.workday/bsvc">
<xs:import namespace="urn:com.workday/bsvc"></xs:import>
<xs:element name="SyncData">
<xs:complexType>
<xs:sequence>
<xs:element name="Employerid" type="xs:string" minOccurs="0" />
<xs:element name="ImporterEmail" type="xs:string" minOccurs="0" />
<xs:element name="ReportEmail" type="xs:string" minOccurs="0" />
<xs:element name="Employees" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="WorkerSummary" type="xs:string"/>
<xs:element name="ReferenceID" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="NewDataSet" msdata:IsDataSet="true"
msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="SyncData" />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
After using the above xsd schema, I am not getting error related to Root Element “SyncData”, But I am getting a different error which I am not understanding what it is about, The error is as following.
org.codehaus.stax2.typed.TypedXMLStreamException: ParseError at [row,col]:[2,359] Message: Element content can not contain child START_ELEMENT when using Typed Access methods
Is there anything wrong in the schema or what is the error is about?
I have tried multiple attempts on xsd schema to execute it perfectly as required, but seems something is missing which I am not sure that is causing the failure.
Can you use this schema
<?xml version="1.0" encoding="utf-16"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="SyncData">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Employerid" type="xsd:int" />
<xsd:element name="ImporterEmail" type="xsd:string" />
<xsd:element name="ReportEmail" type="xsd:string" />
<xsd:element name="Employees">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="wd:WorkerSummary">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="wd:ReferenceID" type="xsd:string" />
<xsd:element name="wd:Name" type="xsd:string" />
<xsd:element name="wd:Title" type="xsd:string" />
<xsd:element name="wd:EmployeeId" type="xsd:string" />
<xsd:element name="wd:EMail" type="xsd:string" />
<xsd:element name="wd:AddressLine1" type="xsd:string" />
<xsd:element name="wd:City" type="xsd:string" />
<xsd:element name="wd:State" type="xsd:string" />
<xsd:element name="wd:Zip" type="xsd:int" />
<xsd:element name="wd:Country" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

s4s-att-invalid-value: Invalid attribute value for 'name' in element 'element'

XML
<ns2:Response xmlns:ns2="http://test.com/" Id="122212">
<Infos size="1">
<Info>
<name>test</name>
</Info>
</Infos>
</ns2:Response>
Generated XSD
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<!-- XML Schema Generated from XML Document on Mon Feb 20 2017 23:20:03 GMT+0530 (India Standard Time) -->
<!-- with XmlGrid.net Free Online Service http://xmlgrid.net -->
<xs:element name="ns2:Response">
<xs:complexType>
<xs:sequence>
<xs:element name="Infos">
<xs:complexType>
<xs:sequence>
<xs:element name="Info">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="size" type="xs:int"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="xmlns:ns2" type="xs:string"></xs:attribute>
<xs:attribute name="Id" type="xs:int"></xs:attribute>
</xs:complexType>
</xs:element>
Error
SAX Exception: s4s-att-invalid-value: Invalid attribute value for
'name' in element 'element'. Recorded reason:
cvc-datatype-valid.1.2.1: 'ns2:Response' is not a valid value for
'NCName'.
There are several changes required for your XML and XSD, including:
Change <xs:element name="ns2:Response"> to <xs:element
name="Response"> because element name declarations must be
non-colonized names (NCNAMEs).
Delete <xs:attribute name="xmlns:ns2".../> because namespaces
cannot be declared as attributes.
Add a targetNamespace to the XSD that matches the namespace of the root element in the XML document.
Import a separate XSD for those elements that you wish to be in no namespace (given that your root elements is in a namespace). You must use a separate XSD to accomplish this.
Altogether, your XML,
<?xml version="1.0" encoding="UTF-8"?>
<ns2:Response xmlns:ns2="http://test.com/"
Id="122212">
<Infos size="1">
<Info>
<name>test</name>
</Info>
</Infos>
</ns2:Response>
will validate successfully against these XSD:
Main
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
xmlns:ns="http://test.com/"
targetNamespace="http://test.com/">
<xs:import schemaLocation="Infos.xsd"/>
<xs:element name="Response">
<xs:complexType>
<xs:sequence>
<xs:element ref="Infos"/>
</xs:sequence>
<xs:attribute name="Id" type="xs:int"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
Imported (Infos.xsd)
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Infos">
<xs:complexType>
<xs:sequence>
<xs:element name="Info">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="size" type="xs:int"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
I was able to get a parsed file by, as the above answer suggests, adding a target namepsace to the schema and by adding the ns prefix to all elements.
<?xml version="1.0" encoding="UTF-8"?>
<ns2:Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://test.com testq1.xsd" xmlns:ns2="http://test.com" Id="122212">
<ns2:Infos size="1">
<ns2:Info>
<ns2:name>test</ns2:name>
</ns2:Info>
</ns2:Infos>
and the schema:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://test.com"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="Response">
<xs:complexType>
<xs:sequence>
<xs:element name="Infos">
<xs:complexType>
<xs:sequence>
<xs:element name="Info">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="size" type="xs:int"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="Id" type="xs:int"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
You can approach this in 2 ways.
Approach 1 - multiple schemas
The more typical approach is to have a schema one for each namespace used.
So you end up with schemas that look like this
SampleXml0.xsd
<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid Studio 2017 (https://www.liquid-technologies.com) -->
<xs:schema xmlns:ns2="http://test.com/" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://test.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import schemaLocation="C:\Temp\StackOverflow\42351409\SampleXml1.xsd" />
<xs:element name="Response">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" ref="Infos" />
</xs:sequence>
<xs:attribute name="Id" type="xs:unsignedInt" use="optional" />
</xs:complexType>
</xs:element>
</xs:schema>
SampleXml1.xsd
<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid Studio 2017 (https://www.liquid-technologies.com) -->
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Infos">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="Info">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="name" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="size" type="xs:unsignedByte" use="optional" />
</xs:complexType>
</xs:element>
</xs:schema>
Approach 2 - changing elementFormDefault
Now this is quite specific to your example, but as its only the root element that is qualified with a namespace its possible to change elementFormDefault to unqualified. This has the effect of forcing the elements defined as root element in the schema to have a namespace qualification, while the other elements do not.
<?xml version="1.0" encoding="utf-8" ?>
<!--Created with Liquid Studio 2017 (https://www.liquid-technologies.com)-->
<xs:schema xmlns:ns2="http://test.com/" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://test.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Response">
<xs:complexType>
<xs:sequence>
<xs:element name="Infos" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="Info" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="size" type="xs:unsignedByte" use="optional" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="Id" type="xs:unsignedInt" use="optional" />
</xs:complexType>
</xs:element>
</xs:schema>
I would probably recommend creating multiple schemas as elementformdefault is typically overlooked by client implementations and ignored.
Why three <xs:sequence> elements? do you really need that? Could you explain better how your code is organized? Usually it is pretty simple, like this:
<xsd:element name="ns2:Response">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="name" type="xs:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>

XML to Java and vice versa using xsd schema

Below is my Schema.xsd
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:ns1="http://www.example.org/address" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://www.example.org/address" schemaLocation="www.example.org_address.xsd"/>
<xs:element name="dependant" type="dependant"/>
<xs:element name="employee" type="employee"/>
<xs:complexType name="employee">
<xs:sequence>
<xs:element name="dependantVO" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element ref="dependant" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="address" type="ns1:address" minOccurs="0"/>
<xs:element name="dob" type="xs:dateTime" minOccurs="0"/>
<xs:element name="joiningBonus" type="xs:decimal" minOccurs="0"/>
<xs:element name="name" type="xs:string" minOccurs="0"/>
<xs:element name="permanent" type="xs:boolean"/>
<xs:element name="role" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="id" type="xs:int" use="required"/>
</xs:complexType>
<xs:complexType name="dependant">
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="0"/>
<xs:element name="relation" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Below is my address.xsd
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="http://www.example.org/address" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="address">
<xs:sequence>
<xs:element name="addressLine1" type="xs:string" minOccurs="0"/>
<xs:element name="addressLine2" type="xs:string" minOccurs="0"/>
<xs:element name="city" type="xs:string" minOccurs="0"/>
<xs:element name="zip" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Now if i marshal the object "Employee" below is the generated employee.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<employee id="12">
<dependantVO>
<dependant>
<name>Vin Diesel</name>
<relation>Friend</relation>
</dependant>
<dependant>
<name>Black Ryan</name>
<relation>GF</relation>
</dependant>
</dependantVO>
<address>
<addressLine1>My Company</addressLine1>
<addressLine2>bangalore east</addressLine2>
<city>Bangalore</city>
<zip>560549</zip>
</address>
<dob>2015-07-28T10:04:34.599+05:30</dob>
<joiningBonus>10234.35467000000062398612499237060546875</joiningBonus>
<name>Paul Walker</name>
<permanent>true</permanent>
<role>SE</role>
</employee>
I have a problem of ordering the xml tags. Eg: Suppose i want addressline1 to be generated inside "employee" tag and outside "address" tag, also dependant name to be generated inside "employee" tag and outside "dependantVO" and "dependant" tag. Below is the xml that should be generated after the schema change
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<employee id="12">
<addressLine1>My Company</addressLine1>
<city>Bangalore</city>
<dependantVO>
<dependant>
<name>Vin Diesel</name>
<relation>Friend</relation>
</dependant>
<dependant>
<name>Black Ryan</name>
<relation>GF</relation>
</dependant>
</dependantVO>
<address>
<addressLine2>bangalore east</addressLine2>
<zip>560549</zip>
</address>
<dob>2015-07-28T10:04:34.599+05:30</dob>
<joiningBonus>10234.35467000000062398612499237060546875</joiningBonus>
<name>Paul Walker</name>
<permanent>true</permanent>
<role>SE</role>
</employee>
Note the addressLine1 tag and city tag is out of address tag and created inside employee tag. This is required because some of the common information are to be accessed easy from the generated xml. If someone tried this case or already done it, please help me out...

Error in creating classes using JAXB

I'm using JAXB for the first time and trying to create class files using my xsd files but unfortunately getting errors.
This is my xsd :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="DbOperation" type="DbOperation"/>
<xs:complexType name="DbOperation">
<xs:sequence>
<xs:element name="ruleList" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element ref="Rule" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Rule">
<xs:sequence>
<xs:element name="Action" type="xs:string" minOccurs="0"/>
<xs:element name="TableName" type="xs:string" minOccurs="0"/>
<xs:element name="conditionList" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element ref="Conditions" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Conditions">
<xs:sequence>
<xs:element name="Condition" type="Condition" minOccurs="0"/>
<xs:element name="Operator" type="xs:string" minOccurs="0"/>
<xs:element name="Condition" type="Condition" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Condition">
<xs:sequence>
<xs:element name="fieldName" type="xs:string" minOccurs="0"/>
<xs:element name="Operation" type="xs:string" minOccurs="0"/>
<xs:element name="Value" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
And these are the errors I'm getting :
parsing a schema...
[ERROR] src-resolve: Cannot resolve the name 'Rule' to a(n) 'element declaration
' component.
line 11 of file:/C:/Documents%20and%20Settings/priyanka.jain/Desktop/JAXB/Rule
.xsd
[ERROR] src-resolve: Cannot resolve the name 'Conditions' to a(n) 'element decla
ration' component.
line 25 of file:/C:/Documents%20and%20Settings/priyanka.jain/Desktop/JAXB/Rule
.xsd
[ERROR] cos-nonambig: Condition and Condition (or elements from their substituti
on group) violate "Unique Particle Attribution". During validation against this
schema, ambiguity would be created for those two particles.
line 32 of file:/C:/Documents%20and%20Settings/priyanka.jain/Desktop/JAXB/Rule
.xsd
Failed to parse a schema.
This is the sample xml for which I've created xsd:
<?xml version="1.0" encoding="UTF-8"?>
<DbOperation>
<Rule>
<Action>Delete</Action>
<TableName>
issue
</TableName>
<Conditions>
<Condition>
<fieldName>
trader
</fieldName>
<Operation>
>=
</Operation>
<Value>
250
</Value>
</Condition>
<Operator>AND</Operator>
<Condition>
<fieldName>
traderName
</fieldName>
<Operation>
=
</Operation>
<Value>
jk
</Value>
</Condition>
</Conditions>
</Rule>
</DbOperation>
Use an XML editor to validate your schema first...
You are referencing a type as if it were an element
<xs:element ref="Conditions" minOccurs="0" maxOccurs="unbounded"/>
<xs:complexType name="Conditions">
<xs:sequence> ....
<xs:element ref="Rule" minOccurs="0" maxOccurs="unbounded"/>
The "REF" attribute indicates that the element and not the type.
Error can be corrected in two ways:
first:
<xs:complexType name="DbOperation">
<xs:sequence>
<xs:element name="ruleList" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="Rule" type="Rule" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
second:
<xs:complexType name="DbOperation">
<xs:sequence>
<xs:element name="ruleList" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element ref="Rule" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:element name="Rule" type="Rule"/>

How to add inline schema in java with xml

I make xml file using Jaxb from a xml schema my existing xml file looks like
<transaction>
<id>
<in>computer</in>
<sn>1234567</sn>
<book>JAVA</book>
<author>klen</author>
</id>
<data>
<dateTime>2011-06-24T17:08:36.3727674+05:30</dateTime>
<key>Err</key>
</data>
</transaction>
but I want to add inline schema before <id> node
My schema is looking like
<xs:schema id="transaction" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="transaction" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="id">
<xs:complexType>
<xs:sequence>
<xs:element name="in" type="xs:string" minOccurs="0" />
<xs:element name="sn" type="xs:string" minOccurs="0" />
<xs:element name="book" type="xs:string" minOccurs="0" />
<xs:element name="author" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="data">
<xs:complexType>
<xs:sequence>
<xs:element name="dateTime" type="xs:dateTime" minOccurs="0" />
<xs:element name="key" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="productData">
<xs:complexType>
<xs:sequence>
<xs:element name="dateTime" type="xs:dateTime" minOccurs="0" />
<xs:element name="key" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
now I want to add this before node under node.
Is it possible using Jaxb in first time?I cannot generate xml file with inline schema using jaxb.Due to the large size of my xml I cannot do this using Dom parser.Presently I try that at first generate xml file with data using jaxb and then rewrite the xml file and add schema under <transaction> node before <id> node.
I will prefer sun provided api.I am new in java so if some codesnips will be added it will be help full for me.

Categories