Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 95
Registered: ‎07-24-2013
My Device: 9380
My Carrier: Airtel
Accepted Solution

Parsing xml

Hi all,

 

     I am calling a dot net webservice from my blackberry 7 java native application. In the response i am getting an xml like one in attached file. I want to parse each and everything from it. How should i start? I am using ksoap2-j2me-core-prev-2.1.2.jar

 

Pleae have a look at the attached file...

 

Thanks and Regards.

 




Developer
Posts: 95
Registered: ‎07-24-2013
My Device: 9380
My Carrier: Airtel

Re: Parsing xml

Hello,

 

  I think no one is trying to have a look at the attached file. So i am attaching the sample here itself...

 

<SeatLayout>
	<objArea colRows="Bigtree.colRows" intSeatsOrdered="0" strAreaCode="0000000003" strAreaDesc="Platinum" strAreaNum="2">
		<colRows colSeats="Bigtree.colSeats" intGridRowID="1" strRowPhyID="A" Key="R1" GetHashCode="41267877">
			<colSeats Key="S1" strGridSeatNum="1" strSeatStatus="0" strSeatXPos="39" strSeatYPos="2"/>
			<colSeats Key="S2" strGridSeatNum="2" strSeatStatus="0" strSeatXPos="38" strSeatYPos="2"/>
		</colRows>
	</objArea>
	<objArea colRows="Bigtree.colRows" intSeatsOrdered="0" strAreaCode="0000000002" strAreaDesc="Classic" strAreaNum="1">
		<colRows colSeats="Bigtree.colSeats" intGridRowID="1" strRowPhyID="P" Key="R1" GetHashCode="50516464">
			<colSeats Key="S1" strGridSeatNum="1" strSeatStatus="4" strSeatXPos="39" strSeatYPos="17"/>
			<colSeats Key="S2" strGridSeatNum="2" strSeatStatus="4" strSeatXPos="38" strSeatYPos="17"/>
		</colRows>
		<colRows colSeats="Bigtree.colSeats" intGridRowID="2" strRowPhyID="O" Key="R2" GetHashCode="57169866">
			<colSeats Key="S1" strGridSeatNum="1" strSeatStatus="0" strSeatXPos="39" strSeatYPos="16"/>
			<colSeats Key="S2" strGridSeatNum="2" strSeatStatus="0" strSeatXPos="38" strSeatYPos="16"/>
		</colRows>
	</objArea>
</SeatLayout>

 

Please help...

 

 

Thanks and Regards.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Parsing xml

There are a number of samples of parsing XML on the board.  Have you had a look at any of these.

 

The confusing part for me is that I am not aware of how using SOAP affects this.  I thought SOAP wouuld remove the need to parse XML?

Developer
Posts: 95
Registered: ‎07-24-2013
My Device: 9380
My Carrier: Airtel

Re: Parsing xml

Thanks a lot for replying, Peter. I have parsed previously SOAP messages(xml). They were simpler. Ok, I m gonna try again...will let you know...

 

Warm Regards.

Developer
Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Parsing xml

if you use ksoap you write a mapping for a class, ksoap parses the SOAP xml for you and returns an instance of that class.

If you want to parse the xml manually there are lots of threads about that, and several examples.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 95
Registered: ‎07-24-2013
My Device: 9380
My Carrier: Airtel

Re: Parsing xml

Hi all,

 

    At least can anybody tell me please that how to read the values of a tag's attribute values ? In the below sample, i want to read the attribute values of objArea, colRows etc...like colRows in objArea and so on... Please help me out I have raed somewhere taht  getAttribute would help me but it didn't.... if yes then how can i?

 

<SeatLayout>
	<objArea colRows="Bigtree.colRows" intSeatsOrdered="0" strAreaCode="0000000003" strAreaDesc="Platinum" strAreaNum="2">
		<colRows colSeats="Bigtree.colSeats" intGridRowID="1" strRowPhyID="A" Key="R1" GetHashCode="41267877">
			<colSeats Key="S1" strGridSeatNum="1" strSeatStatus="0" strSeatXPos="39" strSeatYPos="2"/>
			<colSeats Key="S2" strGridSeatNum="2" strSeatStatus="0" strSeatXPos="38" strSeatYPos="2"/>
		</colRows>
	</objArea>
.
.
.
.
.
.
.
.
.
Developer
Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Parsing xml

if you use a sax parser you get the attributes in the startElement method:
http://www.blackberry.com/developers/docs/7.1.0api/org/xml/sax/helpers/DefaultHandler.html#startElem...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 95
Registered: ‎07-24-2013
My Device: 9380
My Carrier: Airtel

Re: Parsing xml

Hi all,

 

   I am getting (i think) the right response here...

 

SoapObject blnGetSeatLayoutResult = (SoapObject) bodyInObj.getProperty("blnGetSeatLayoutResult");
SoapObject seatLayoutNewDataSet = (SoapObject) blnGetSeatLayoutResult.getProperty("SeatLayout");
	final int totalSeatLayout = seatLayoutNewDataSet.getPropertyCount();//Here i am getting right count..upto here it is OK

	for(int i=0;i<totalSeatLayout;i++){
		SoapObject objArea = (SoapObject) seatLayoutNewDataSet.getProperty(i);
		.
		.
		.

 but when debugging, i am getting the value of objArea like below..

 

anyType{colRows=anyType{colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; colSeats=anyType{}; }; }

 

why it is so? Please help me out of this.. I am stuck here...

 

Warm Regards.

Developer
Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Parsing xml

if i remember correctly ksoap does not support attributes. there is a patched version somewhere on android.

but if you do all the serialization manually there is no need to use ksoap anyhow.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 95
Registered: ‎07-24-2013
My Device: 9380
My Carrier: Airtel

Re: Parsing xml

Simon, First of all Thanks for the quick reply.

 

     Can you please point me to some document or link from where i can get help?  How can i serialize? Should i change my approach fully or what? Please...

 

Warm Regards.