RE: Problems getting started with xmlbeans

Wing Yew Poon <[email protected]> Mon, 22 Nov 2010 12:24:38 -0800 (PST)
Newsgroups gmane.text.xml.xmlbeans.user
Message-ID <076339bc-3f27-4004-96d6-544f5726ac16@default>
Duane,
if you did
 
    PurchaseOrderDocument newPODoc = PurchaseOrderDocument.Factory.newInstance();
    PurchaseOrder newPO = newPODoc.addNewPurchaseOrder();

then you have a purchase-order element.
If you just did
 
    PurchaseOrderDocument newPODoc = PurchaseOrderDocument.Factory.newInstance();

then you have nothing yet, just an empty document. If you try to output that, you get an empty xml fragment.
Hope that clarifies things.
- Wing Yew

  _____  

From: Duane Zamrok [mailto:[email protected]] 
Sent: Monday, November 22, 2010 11:44 AM
To: [email protected]
Subject: RE: Problems getting started with xmlbeans



Based upon the schema, your code, and my experience I would expect you to get something like the following.

 

<purchase-order/>

 

That said, Wing Yew Poon may have hit upon the problem when he mentioned that you're looking at a tutorial for 1.0. I advise you to take a look at the tutorial he linked and look into using XMLBeans 2.0+ instead of 1.0.

 

-Duane

 

From: PhilNad214 PhilNad214 [mailto:[email protected]] 
Sent: Monday, November 22, 2010 2:30 PM
To: [email protected]
Subject: Re: Problems getting started with xmlbeans

 

Sure (it's simply the one that comes with the distribution)...

<xs:schema
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:po="http://openuri.org/easypo"
   targetNamespace="http://openuri.org/easypo"
   elementFormDefault="qualified">

  <xs:element name="purchase-order">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="customer" type="po:customer"/>
        <xs:element name="date" type="xs:dateTime"/>
        <xs:element name="line-item" type="po:line-item" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element name="shipper" type="po:shipper" minOccurs="0" maxOccurs="1"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:complexType name="customer">
    <xs:sequence>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="address" type="xs:string"/>
    </xs:sequence>
    <xs:attribute name="age" type="xs:int"/>
    <xs:attribute name="moo" type="xs:int" default="100"/>
    <xs:attribute name="poo" type="xs:int" fixed="200"/>
  </xs:complexType>

  <xs:complexType name="line-item">
    <xs:sequence>
      <xs:element name="description" type="xs:string"/>
      <xs:element name="per-unit-ounces" type="xs:decimal"/>
      <xs:element name="price" type="xs:decimal"/>
      <xs:element name="quantity" type="xs:integer"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="shipper">
    <xs:sequence>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="per-ounce-rate" type="xs:decimal"/>
    </xs:sequence>
  </xs:complexType>

</xs:schema>




On Tue, Nov 23, 2010 at 7:59 AM, Duane Zamrok <HYPERLINK "mailto:[email protected]"[email protected]> wrote:

Can you post the schema as well?

 

Thanks

-Duane

 

From: PhilNad214 PhilNad214 [mailto:HYPERLINK "mailto:[email protected]" \[email protected]] 
Sent: Monday, November 22, 2010 12:17 AM
To: HYPERLINK "mailto:[email protected]" \[email protected]
Subject: Re: Problems getting started with xmlbeans

 

As a followup to this, here is an example:

import org.openuri.easypo.PurchaseOrderDocument;
public class POUpdater {
    POUpdater() {
        PurchaseOrderDocument pod = PurchaseOrderDocument.Factory.newInstance();
        System.out.println(pod.toString());
    }
    public static void main(String args[]) {
        POUpdater po = new POUpdater();
    }
}

... which outputs:

<xml-fragment/>

Shouldn't it output at least an XML structure with at least the basic structure of the bean?

On Mon, Nov 22, 2010 at 5:44 PM, PhilNad214 PhilNad214 <HYPERLINK "mailto:[email protected]" \[email protected]> wrote:

Hi, I posted here a couple of weeks ago some basic 'getting started' questions. I've just got back to this project and have started using some generated code - have created a bean and tried to convert to xml, but all I get is the namespace in the xml. I.e it is as if the document.toString() is just showing the top node, and not traversing its way through the object to generate all the xml.
Does this sound familiar to anyone? Any suggestions?

The next thing I thought I must be doing something wrong, so I've gone back to the getting started tutorial at http://xmlbeans.apache.org/documentation/tutorial_getstarted.html
However I cannot for the life of me find a tutorial folder (although I did find the easypo.xsd and have successfully generated an easypo.jar). I can't see the tutorial files on the apache xmlbeans website anywhere... where on earth do you get that from??

Thanks