You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Frank Rossol <fr...@otten-software.de> on 2008/04/30 11:15:58 UTC
Set does duplicate Element
Hello,
i have a strange problem using Typed Nodes set method.
I used the easypo.xsd schema from the samples directory to create the
java.classes.
Now I tried to import a Shipper-Node to the PurchaseOrderDocument using the
following code:
String podocpath = "<path to easypo.xml> ";
podoc = PurchaseOrderDocument.Factory.parse(podocpath);
String shipperpath = "<path to shipper.xml> ";
Shipper shipper = Shipper.Factory.parse(new File(shipperpath));
podoc.getPurchaseOrder().setShipper(shipper);
String test = podoc.toString();
easypo.xml
<?xml version='1.0' encoding='iso8859-1'?>
<purchase-order xmlns="http://openuri.org/easypo">
<customer>
<name>Gladys Kravitz</name>
<address>Anytown, PA</address>
</customer>
<date>2003-01-07T14:16:00-05:00</date>
<line-item>
<description>Burnham's Celestial Handbook, Vol 1</description>
<per-unit-ounces>5</per-unit-ounces>
<price>21.79</price>
<quantity>2</quantity>
</line-item>
<line-item>
<description>Burnham's Celestial Handbook, Vol 2</description>
<per-unit-ounces>5</per-unit-ounces>
<price>19.89</price>
<quantity>2</quantity>
</line-item>
<shipper>
<name>ZipShip</name>
<per-ounce-rate>0.74</per-ounce-rate>
</shipper>
</purchase-order>
shipper.xml
<?xml version='1.0' encoding='iso8859-1'?>
<shipper xmlns="http://openuri.org/easypo">
<name>ZipShip</name>
<per-ounce-rate>0.74</per-ounce-rate>
</shipper>
the toString() function produced the following output:
<purchase-order xmlns="http://openuri.org/easypo">
<customer>
<name>Gladys Kravitz</name>
<address>Anytown, PA</address>
</customer>
<date>2003-01-07T14:16:00-05:00</date>
<line-item>
<description>Burnham's Celestial Handbook, Vol 1</description>
<per-unit-ounces>5</per-unit-ounces>
<price>21.79</price>
<quantity>2</quantity>
</line-item>
<line-item>
<description>Burnham's Celestial Handbook, Vol 2</description>
<per-unit-ounces>5</per-unit-ounces>
<price>19.89</price>
<quantity>2</quantity>
</line-item>
<shipper>
<shipper>
<name>ZipShip</name>
<per-ounce-rate>0.74</per-ounce-rate>
</shipper>
</shipper>
</purchase-order>
Any Suggestions why the shipper-Node is not replaced.
Thanks Frank
Frank Rossol
Dipl. Inform. (FH)
otten|software GmbH
Röntgenring 7
D-40878 Ratingen
Amtsgericht Düsseldorf HRB 55584
Geschäftsführer: Dr.Marcus Otten
Tel +49 2102 30964-0
Fax +49 2102 30964-29
<ma...@otten-software.de> info@otten-software.de
<http://www.otten-software.de/> www.otten-software.de
RE: Set does duplicate Element
Posted by Radu Preotiuc-Pietro <ra...@bea.com>.
This boils down to the fact that you don't have a <shipper> global element, so if you want to parse the value of a Shipper type (which I believe is you intention based on the code snippet you wrote), then your XML needs to look like:
<xml-fragment>
<name>ZipShip</name>
<per-ounce-rate>0.74</per-ounce-rate>
</xml-fragment>
See the "Parsing an XML Fragment" thread for explanation on how to parse document fragments (documents that don't have a global Schema element as root): http://mail-archives.apache.org/mod_mbox/xmlbeans-user/200804.mbox/browser
Radu
________________________________
From: Frank Rossol [mailto:fr@otten-software.de]
Sent: Wednesday, April 30, 2008 2:16 AM
To: user@xmlbeans.apache.org
Subject: Set does duplicate Element
Hello,
i have a strange problem using Typed Nodes set method.
I used the easypo.xsd schema from the samples directory to create the java.classes.
Now I tried to import a Shipper-Node to the PurchaseOrderDocument using the following code:
String podocpath = "<path to easypo.xml> ";
podoc = PurchaseOrderDocument.Factory.parse(podocpath);
String shipperpath = "<path to shipper.xml> ";
Shipper shipper = Shipper.Factory.parse(new File(shipperpath));
podoc.getPurchaseOrder().setShipper(shipper);
String test = podoc.toString();
easypo.xml
<?xml version='1.0' encoding='iso8859-1'?>
<purchase-order xmlns="http://openuri.org/easypo">
<customer>
<name>Gladys Kravitz</name>
<address>Anytown, PA</address>
</customer>
<date>2003-01-07T14:16:00-05:00</date>
<line-item>
<description>Burnham's Celestial Handbook, Vol 1</description>
<per-unit-ounces>5</per-unit-ounces>
<price>21.79</price>
<quantity>2</quantity>
</line-item>
<line-item>
<description>Burnham's Celestial Handbook, Vol 2</description>
<per-unit-ounces>5</per-unit-ounces>
<price>19.89</price>
<quantity>2</quantity>
</line-item>
<shipper>
<name>ZipShip</name>
<per-ounce-rate>0.74</per-ounce-rate>
</shipper>
</purchase-order>
shipper.xml
<?xml version='1.0' encoding='iso8859-1'?>
<shipper xmlns="http://openuri.org/easypo">
<name>ZipShip</name>
<per-ounce-rate>0.74</per-ounce-rate>
</shipper>
the toString() function produced the following output:
<purchase-order xmlns="http://openuri.org/easypo">
<customer>
<name>Gladys Kravitz</name>
<address>Anytown, PA</address>
</customer>
<date>2003-01-07T14:16:00-05:00</date>
<line-item>
<description>Burnham's Celestial Handbook, Vol 1</description>
<per-unit-ounces>5</per-unit-ounces>
<price>21.79</price>
<quantity>2</quantity>
</line-item>
<line-item>
<description>Burnham's Celestial Handbook, Vol 2</description>
<per-unit-ounces>5</per-unit-ounces>
<price>19.89</price>
<quantity>2</quantity>
</line-item>
<shipper>
<shipper>
<name>ZipShip</name>
<per-ounce-rate>0.74</per-ounce-rate>
</shipper>
</shipper>
</purchase-order>
Any Suggestions why the shipper-Node is not replaced.
Thanks Frank
Frank Rossol
Dipl. Inform. (FH)
otten|software GmbH
Röntgenring 7
D-40878 Ratingen
Amtsgericht Düsseldorf HRB 55584
Geschäftsführer: Dr.Marcus Otten
Tel +49 2102 30964-0
Fax +49 2102 30964-29
info@otten-software.de <ma...@otten-software.de>
www.otten-software.de <http://www.otten-software.de/>
Notice: This email message, together with any attachments, may contain information of BEA Systems, Inc., its subsidiaries and affiliated entities, that may be confidential, proprietary, copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.