HI Stephen,
Thank you very much for your cooperation. I am using 0.9.6-RC3, it is good
idea to migrate to latest version. I have done it.
After installing 0.9.7 also I am having the same problem.
------------------------------------------------------------------------------------------------------------------------------------------------
PROBLEM in Short:
I shall try to explain the problem briefly for others. Actully I am using
the two dummy elements in location attribute.
location="Details/Grade1"
location="Details/Grade2".
Then it is creating XML as
<Item>
<Details ...>
<Grade1 ...>
</Details>
<Details ...>
<Grade2 ...>
</Details>
</Item>
Help appreciated.
------------------------------------------------------------------------------------------------------------------------------------------------
PROBLEM in Detail:
I am really very sorry for not describing my actual problem specification
correctly. Actually in my project XML is different and is bit large. So I do
not want the same to present here on this forum.So I am describing the
problem with simple XML similar to actual problem statement.
My XML is similar to below Order.xml and with this it adds the many Details
elements.
<order orderid="O-1">
<Items>
<Item itemid="I-2">
<Details desc="chocolate">
<Grade1 quantity="10" unitprice="28.5"/>
<Grade2 quantity="5" unitprice="20"/>
</Details>
</Item>
<Item itemid="I-1">
<Details desc="Stuffed Penguin">
<Grade1 quantity="20" unitprice="30"/>
<Grade2 quantity="3" unitprice="25"/>
</Details>
</Item>
</Items>
</order>
Mapping.xml is as below,
...
<class name="Item">
<field name="itemid" type="string" direct="true">
<bind-xml name="itemid" direct="true" node="attribute"/>
</field>
<field name="description" type="string" direct="true">
<bind-xml name="desc" direct="true" node="attribute"
location="Details"/>
</field>
<field name="quantity1" type="integer" direct="true">
<bind-xml name="quantity" direct="true" node="attribute"
location="Details/Grade1"/>
</field>
<field name="unitPrice1" type="float" direct="true">
<bind-xml name="unitprice" direct="true" node="attribute"
location="Details/Grade1"/>
</field>
<field name="quantity2" type="integer" direct="true">
<bind-xml name="quantity" direct="true" node="attribute"
location="Details/Grade2"/>
</field>
<field name="unitPrice2" type="float" direct="true">
<bind-xml name="unitprice" direct="true" node="attribute"
location="Details/Grade2"/>
</field>
</class>
...
I have added some new fields in Item.java to simulate the problem and is as
below,
public class Item {
public String itemid;
public int quantity1;
public float unitPrice1;
public int quantity2;
public float unitPrice2;
public String description;
}
And output Order.xml after unmarshalling the Java Object in xml file is as
below,
<Order orderid="O-1">
<Items>
<Item itemid="I-2">
<Details desc="chocolate"/>
<Details>
<Grade1 quantity="10" unitprice="28.5"/>
</Details>
<Details>
<Grade2 quantity="5" unitprice="20.0"/>
</Details>
</Item>
<Item itemid="I-1">
<Details desc="Stuffed Penguin"/>
<Details>
<Grade1 quantity="20" unitprice="30.0"/>
</Details>
<Details>
<Grade2 quantity="3" unitprice="25.0"/>
</Details>
</Item>
</Items>
</Order>
Thanks and Regards,
Jitesh
------------------------------------------------------------------------------------------------------------------------------------------------
----- Original Message -----
From: "Stephen Bash" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, July 21, 2005 8:57 PM
Subject: Re: [castor-user] Regarding "field ->location" attribute
Jitesh-
What version of Castor are you running? I've got 0.9.7 and I get the
following when I add location="Details" to the mapping file:
<order orderid="O-1">
<Items>
<item itemid="I-2">
<Details>
<Quantity>5</Quantity>
<UnitPrice>28.5</UnitPrice>
<Description>Chocolate</Description>
</Details>
</item>
<item itemid="I-1">
<Details>
<Quantity>10</Quantity>
<UnitPrice>8.95</UnitPrice>
<Description>Stuffed Penguin</Description>
</Details>
</item>
</Items>
</order>
So at least on my machine, only one <Details> element is created for all
the items underneath it... Perhaps there is a property somewhere that I
have set that I don't remember, but this implies what you are looking for
is possible.
Does anyone else know if this change occurred from a version change or a
property somewhere? Thanks!
Stephen
Kalyani Jitesh wrote:
Dear All,
I am facing the problem with "field ->location" attribute. It is
creating the dummy element for each field of class.
I have xml like below,
<Items>
<Item itemid="I-1">
<Details>
<Description>Stuffed Penguin</Description>
<Quantity>10</Quantity>
<UnitPrice>8.95</UnitPrice>
</Details>
</Item>
<Item id="I-2">
<Details>
<Description>Chocolate</Description>
<Quantity>5</Quantity>
<UnitPrice>28.50</UnitPrice>
</Details>
</Item>
</Items>
And Item class as below
classs Item {
public String itemid;
public int quantity;
public float unitPrice;
public String description;
...
}
Item class is mapped as below in mapping.xml,
...
<class name="Item">
<field name="itemid" type="string" direct="true"
<bind-xml name="itemid" node="attribute"/>
</field>
<field name="quantity" type="integer" direct="true"
<bind-xml name="Quantity" node="element" location="Details"/>
</field>
<field name="unitPrice" type="float" direct="true"
<bind-xml name="UnitPrice" node="element" location="Details"/>
</field>
<field name="description" type="string" direct="true"
<bind-xml name="Description" node="element" location="Details"/>
</field
</class>
...
I am marshalling from above XML, it is working fine. But when I
unmarshall Java object in new xml file it is created as below,
<Items>
<Item itemid="I-1">
<Details>
<Description>Stuffed Penguin</Description>
</Details>
<Details>
<Quantity>10</Quantity>
</Details>
<Details>
<UnitPrice>8.95</UnitPrice>
</Details>
</Item>
<Item id="I-2">
<Details>
<Description>Chocolate</Description>
</Details>
<Details>
<Quantity>5</Quantity>
</Details>
<Details>
<UnitPrice>28.50</UnitPrice>
</Details>
</Item>
</Items>
How can I avoid creating many <Details> elements under <Item>.
Help appreciated.
Thanks and Regards,
Jitesh
-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to
the following address:
[EMAIL PROTECTED]
-------------------------------------------------
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------