Pete --
Thanks for the reply BUT, if you have elements that refer to the element
which needs to be duplicated, how are they referenced?
For example, after your suggestion below, I'll have the following in my
XSD file. Both 'amenitie's are children of 'schema'.
<!-- amenity with no children -->
<xsd:element name="amenities">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="amenity" type="xsd:string" minOccurs="0"
maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!-- amenity with two children -->
<xsd:element name="amenities">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="amenity" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<!-- used for amenity, belonging to amenities which has children -->
<xsd:element name="amenity">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="code" type="xsd:string" minOccurs="0"
maxOccurs="1"/>
<xsd:element name="name" type="xsd:string" minOccurs="0"
maxOccurs="1"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
Q1. With a binding file, will this validate?
Q2. If there's ANOTHER elment out there which references "amenities", how
does it do that, since both the "amenities" above are children of the
same schema? Since they have the same name (and the same xPath).
Do I have to forcficly make the amenities children of some other elements
simply so they have seperate xpaths?
Thx,
Aurangzeb
On Wed, 5 Feb 2003, Pete Thomas wrote:
:If you just want to be able to have two elements with the same name and then
:use the SourceGenerator to generate the java classes, then you need to
:provide an override for the normal Java class name - otherwise you'll end up
:with two classes generated but the last will overwrite the first.
:
:Specify the override in a binding file, e.g
:
:bindingDuplicates.xml :-
:
:
:<?xml version="1.0"?>
:<!-- This file contains the binding information -->
:<!-- for the invoice XML Schema -->
:<!-- It is meant to be used by the Castor Source Code Generator -->
:
:<cbf:binding xmlns:cbf="http://www.castor.org/SourceGenerator/Binding"
: defaultBindingType='element'>
:
: <!-- Binding the element to a class -->
: <cbf:elementBinding name="/CTP/AIP/REQUEST">
: <cbf:java-class name="RequestAIP"/>
: </cbf:elementBinding>
:
: <!-- Binding the element to a class -->
: <cbf:elementBinding name="/CTP/FAF/REQUEST">
: <cbf:java-class name="RequestFAF"/>
: </cbf:elementBinding>
:
:</cbf:binding>
:
:
:where name= is the xpath to the duplicated element
:
:then pass this binding file into the SourceGenerator e.g.
:
:java -classpath %JAVACLASSPATH% org.exolab.castor.builder.SourceGenerator -i
:C:/XML/XMLSchemas/your.xsd -package com.yourpackage -dest src -types j2
:-binding-file bindingDuplicates.xml
:
:
:when you marshall back to XML the original element name will be intact. It
:took me ages to get this working, it really should be documented somewhere.
:
:
:Pete
:
:
:
:-----Original Message-----
:From: Aurangzeb M. Agha [mailto:[EMAIL PROTECTED]]
:Sent: 05 February 2003 15:29
:To: [EMAIL PROTECTED]
:Subject: Re: [castor-dev] Can two XML elements with same name but
:different structures exist seperately?
:
:
:Thanks for the reply Sandor.
:
:I realized that I don't think this solution will work if other elements
:reference overview or generalInfo. Is there a way to accomplish this,
:that is allowing for these elements to be accessible outside the scope of
:'hotelInfo', as well?
:
:Also, a similar, but seperate question: what if the two child elements an
:element (call it, a) have different structures but the same name?
:
: Rgs,
: Zeb
:
::On Tue, 4 Feb 2003, Sandor KELEMEN wrote:
::
:::> I've been given an XML spec by a hotel provider for access to their
:::> system.
:::>
:::> In it, they define two elements, 'overview' and 'generalInfo'. Both of
:::> these elements are children of a mutual parent, 'hotelInfo'. However,
:::> according to their spec, 'overview' has a child element ALSO called
:::> 'generalInfo', but one with a different contents than the 'generalInfo'
:::> which is at the same level as 'overview'.
:::>
:::> First question: Is this legit?
:::
:::Yes.
:::
:::
:::> Second question: If so, how do you map this in a .xsd file?
:::
:::Here are two possible solutions:
:::
:::1.
:::----------------------------------------------------
:::<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
:::elementFormDefault="qualified" attributeFormDefault="unqualified">
::: <xsd:element name="hotelInfo">
::: <xsd:complexType>
::: <xsd:sequence>
:::
::: <xsd:element name="overview">
::: <xsd:complexType>
::: <xsd:sequence>
::: <xsd:element name="generalInfo">
::: <xsd:complexType>
::: <xsd:sequence>
::: <xsd:element name="numBedrooms" type="xsd:string"/>
::: <xsd:element name="numFloors" type="xsd:string"/>
::: </xsd:sequence>
::: </xsd:complexType>
::: </xsd:element>
::: </xsd:sequence>
::: </xsd:complexType>
::: </xsd:element>
:::
::: <xsd:element name="generalInfo">
::: <xsd:complexType>
::: <xsd:sequence>
::: <xsd:element name="hotelId" type="xsd:string"
:minOccurs="1"/>
::: <xsd:element name="name" type="xsd:string" minOccurs="1"/>
::: <xsd:element name="streetAddress1" type="xsd:string"
:::minOccurs="1"/>
::: <xsd:element name="streetAddress2" type="xsd:string"
:::minOccurs="0"/>
::: <xsd:element name="city" type="xsd:string" minOccurs="1"/>
::: <xsd:element name="postalCode" type="xsd:string"
:::minOccurs="1"/>
::: <xsd:element name="stateCode" type="xsd:string"
:::minOccurs="1"/>
::: </xsd:sequence>
::: </xsd:complexType>
::: </xsd:element>
::: </xsd:sequence>
::: </xsd:complexType>
::: </xsd:element>
:::</xsd:schema>
:::----------------------------------------------------
:::
:::2.
:::----------------------------------------------------
:::<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
:::elementFormDefault="qualified" attributeFormDefault="unqualified">
:::
::: <xsd:element name="hotelInfo">
::: <xsd:complexType>
::: <xsd:sequence>
:::
::: <xsd:element name="overview">
::: <xsd:complexType>
::: <xsd:sequence>
::: <xsd:element name="generalInfo" type="OverviewGeneralInfo"/>
::: </xsd:sequence>
::: </xsd:complexType>
::: </xsd:element>
:::
::: <xsd:element name="generalInfo" type="HotelInfoGeneralInfo"/>
::: </xsd:sequence>
::: </xsd:complexType>
::: </xsd:element>
:::
::: <xsd:complexType name="OverviewGeneralInfo">
::: <xsd:sequence>
::: <xsd:element name="numBedrooms" type="xsd:string"/>
::: <xsd:element name="numFloors" type="xsd:string"/>
::: </xsd:sequence>
::: </xsd:complexType>
:::
::: <xsd:complexType name="HotelInfoGeneralInfo">
::: <xsd:sequence>
::: <xsd:element name="hotelId" type="xsd:string" minOccurs="1"/>
::: <xsd:element name="name" type="xsd:string" minOccurs="1"/>
::: <xsd:element name="streetAddress1" type="xsd:string" minOccurs="1"/>
::: <xsd:element name="streetAddress2" type="xsd:string" minOccurs="0"/>
::: <xsd:element name="city" type="xsd:string" minOccurs="1"/>
::: <xsd:element name="postalCode" type="xsd:string" minOccurs="1"/>
::: <xsd:element name="stateCode" type="xsd:string" minOccurs="1"/>
::: </xsd:sequence>
::: </xsd:complexType>
:::
:::</xsd:schema>
:::----------------------------------------------------
:::
:::best regards,
:::Sanyi
:::
:::-----------------------------------------------------------
:::If you wish to unsubscribe from this mailing, send mail to
:::[EMAIL PROTECTED] with a subject of:
::: unsubscribe castor-dev
:::
::
::
:
:
--
Aurangzeb M. Agha | Email : [EMAIL PROTECTED]
| Home : +3 010 8959.558
34 Nafsika St. | Direct: +3 010 8995.875
Voula 16673 | Mobile: TBD
Greece | e-Fax : 978 246.0770
| PGP id: 0x68B3A763
"Those who would give up essential liberty to purchase a little
temporary safety deserve neither liberty nor safety."
- Benjamin Franklin
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev