You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by cheenu vasan <ch...@gmail.com> on 2006/02/20 10:35:50 UTC

Parsing array elements

Hi,

Here's my schema. I am able to compile this and this is perfectly alright.


?xml version="1.0" encoding="UTF-8" ?>
<xs:schema targetNamespace="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="BusRoute">
<xs:complexType>
  <xs:sequence>
    <xs:element name="Id" type="xs:string"/>

    <xs:element name="Bus">
        <xs:complexType>
            <xs:sequence>
                    <xs:element name="Id" type="xs:int"/>
                    <xs:element name="Type" type="xs:string"/>
                    <xs:element name="Model" type="xs:string"/>
               </xs:sequence>
               </xs:complexType>
    </xs:element>

    <xs:element name="Seat" maxOccurs="unbounded">
        <xs:complexType>
            <xs:sequence>
                           <xs:element name="Sn" type="xs:int"/>
                            <xs:element name="A" type="xs:string"/>
                            <xs:element name="Sx" type="xs:string"/>
                            <xs:element name="Q" type="xs:string"/>
                            <xs:element name="T" type="xs:string"/>
                            <xs:element name="Si" type="xs:string"/>

                    </xs:sequence>
                    </xs:complexType>
        </xs:element>


     </xs:sequence>
           </xs:complexType>
</xs:element>

</xs:schema>


The problem I face with is the array elements returned from the API.  I
worked with another one without array. did not have any problems at all.

BusRouteDocument brDoc = BusRouteDocument.Factory.parse(new StringReader(
sb.toString()));
        BusRoute  busRoute = brDoc.getBusRoute();

//this is returning null.
 System.out.println(busRoute.getBus());

            Seat[] seatArray = busRoute.getSeatArray();

//this is always zero.
            System.out.println(seatArray.length);

                    for(int j=0; j<seatArray.length; j++){

                        System.out.print(seatArray[j].getSn());

                    }

            }




This is the XML Message I am passing it to the API.

        sb.append("<?xml version='1.0' encoding='UTF-8'?>");
        sb.append("<BusRoute xmlns='http://www.w3.org/2001/XMLSchema'>");
        sb.append("<Id>B1001</Id>");
        sb.append
("<bus><Id>1001</Id><Type>SS</Type><Model>1+1</Model></bus>");

        sb.append("<Seat>");
        sb.append("<Sn>1</Sn> <A>Y</A> <Sx>M</Sx> <Q>V</Q> <T>W</T>
<Si>L</Si>");
        sb.append("</Seat>");

        sb.append("<Seat>");
        sb.append("<Sn>2</Sn> <A>Y</A> <Sx>M</Sx> <Q>V</Q> <T>W</T>
<Si>L</Si>");
        sb.append("</Seat>");

        sb.append("</BusRoute>");


Thanks for your help.
Cheenu

Re: Parsing array elements

Posted by Jerome Magnet <je...@nortel.com>.
Two questions/remarks:

1) Why don't you use the XML Beans to create the document (instead of 
StringBuilder)?
It is an advantage to using XML beans if you have the Java classes of your 
schema.

2) Wrong namespace declaration in XML instance
You declare XSD as the default namespace (no prefix) <BusRoute 
xmlns='http://www.w3.org/2001/XMLSchema'> which is wrong for this XML as it is 
your own schema. you should have instead <BusRoute xmlns='http://mySchema'> 
where mySchema if the namespace of the schema you compiled for BusRoute element 
defintion. This XML certainly fails any schema validation.

JM


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: Parsing array elements

Posted by Vlad Mangeym <ma...@yahoo.com>.
Should you have 'b' capitalized?

sb.append("<Bus><Id>1001</Id><Type>SS</Type><Model>1+1</Model></Bus>");
 
(It probably fails to load your document)


cheenu vasan <ch...@gmail.com> wrote: 
 Hi,
 
 Here's my schema. I am able to compile this and this is perfectly alright.
 
 
 ?xml version="1.0" encoding="UTF-8" ?>
 <xs:schema targetNamespace="http://www.w3.org/2001/XMLSchema"
 xmlns:xs="http://www.w3.org/2001/XMLSchema">
 
 <xs:element name="BusRoute">
 <xs:complexType>
   <xs:sequence>
     <xs:element name="Id" type="xs:string"/>
 
     <xs:element name="Bus">
         <xs:complexType>
             <xs:sequence>
                     <xs:element name="Id" type="xs:int"/>
                     <xs:element name="Type" type="xs:string"/>
                     <xs:element name="Model" type="xs:string"/>
                </xs:sequence>
                </xs:complexType>
     </xs:element>
             
     <xs:element name="Seat" maxOccurs="unbounded">
         <xs:complexType>
             <xs:sequence>
                            <xs:element name="Sn" type="xs:int"/>
                             <xs:element name="A" type="xs:string"/>
                             <xs:element name="Sx" type="xs:string"/>
                             <xs:element name="Q" type="xs:string"/>
                             <xs:element name="T" type="xs:string"/>
                             <xs:element name="Si" type="xs:string"/>
                 
                     </xs:sequence>
                     </xs:complexType>
         </xs:element>
 
 
      </xs:sequence>
            </xs:complexType>
 </xs:element>
         
 </xs:schema>    
 
        
 The problem I face with is the array elements returned from the API.  I worked with another one without array. did not have any problems at all.
 
 BusRouteDocument brDoc = BusRouteDocument.Factory.parse(new StringReader(sb.toString()));
         BusRoute  busRoute = brDoc.getBusRoute();
         
 //this is returning null.       
  System.out.println(busRoute.getBus());
         
             Seat[] seatArray = busRoute.getSeatArray();
 
 //this is always zero.
             System.out.println(seatArray.length);
             
                     for(int j=0; j<seatArray.length; j++){
                         
                         System.out.print(seatArray[j].getSn());
                         
                     }
                 
             }
 
 
 
 
 This is the XML Message I am passing it to the API.
 
         sb.append("<?xml version='1.0' encoding='UTF-8'?>");
         sb.append("<BusRoute xmlns='http://www.w3.org/2001/XMLSchema'>");
         sb.append("<Id>B1001</Id>");
         sb.append("<bus><Id>1001</Id><Type>SS</Type><Model>1+1</Model></bus>");
 
         sb.append("<Seat>");
         sb.append("<Sn>1</Sn> <A>Y</A> <Sx>M</Sx> <Q>V</Q> <T>W</T> <Si>L</Si>");
         sb.append("</Seat>");
         
         sb.append("<Seat>");
         sb.append("<Sn>2</Sn> <A>Y</A> <Sx>M</Sx> <Q>V</Q> <T>W</T> <Si>L</Si>");
         sb.append("</Seat>");
         
         sb.append("</BusRoute>");
 
 
 Thanks for your help.
 Cheenu
 

		
---------------------------------
 Yahoo! Autos. Looking for a sweet ride? Get pricing, reviews, & more on new and used cars.