Hi Cheenu

 

I think there’s a few different bugs here. First of all (as mentioned in another reply to this mail) in your schema you have the attribute:

 

targetNamespace="http://www.w3.org/2001/XMLSchema"

 

The targetNamespace attribute is the namespace by which you want the elements you define in this schema to be known. You have chosen the namespace of XML Schema itself which is probably not what you intended (I think trying to extend Schema itself in this way is not to be recommended – it may even be illegal – I’m not sure). So start by changing this to something of your own e.g.

 

targetNamespace="http://myNamespace.org/myTest"

 

You will, of course, have to change the default namespace attribute you use in the instance doc to match this – so your 2nd append should look like this:

 

        sb.append("<BusRoute xmlns='http://myNamespace.org/myTest'>");

 

Secondly I would add in the attribute:

 

elementFormDefault=”qualified”

 

into the <xs:schema> element. There are alternatives to this, but seems to map to what most people (and you in particular) expect the instance doc to look like – so for instance it will then be correct to refer to _all_ your elements using their namespaces (if you do not do this then only the global elements should use the namespace – the local elements such as Id, Bus and Seat would need to be referred to without their namespace –in your instance doc you have declared a default namespace attribute which affects _all_ descendants so for you this is important).

 

Thirdly, as Vlad pointed out below, XML is case-sensitive – your instance document <bus> element will not match your schema <Bus> element.

 

After that it should all work.

 

Cheers,

 

Lawrence

 


From: Vlad Mangeym [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 20, 2006 8:33 AM
To: [email protected]
Subject: Re: Parsing array elements

 

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 <[EMAIL PROTECTED]> 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>   

    &nbs p;
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.

_______________________________________________________________________
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.

Reply via email to