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
New Developer
Posts: 17
Registered: ‎07-16-2012
My Device: None
My Carrier: None

Looping through an object

Hi All,

 

In Java how would I go about looping the object MeterNumberInfo?

 

Stephen

 

Code:

 

Electricity elec = new Electricity();
SoapObject object = elec.Connect(elec.GetMeterList(store.get(TOKEN_ID).toString()), webserviceurl, soapAction);
Object MeterNumberInfo = object.getProperty("MeterNumberInfo");

 

   XML:

  

<c:MeterNumberInfo>
                  <c:Description>Cape Town</c:Description>
                  <c:LocalAuthorityCode>CPT</c:LocalAuthorityCode>
                  <c:MeterNumber>01003032073</c:MeterNumber>
                  <c:Municipality>Cape Town</c:Municipality>
               </c:MeterNumberInfo>
               <c:MeterNumberInfo>
                  <c:Description>Test Account</c:Description>
                  <c:LocalAuthorityCode>EDB</c:LocalAuthorityCode>
                  <c:MeterNumber>04092246224</c:MeterNumber>
                  <c:Municipality>Edumbe</c:Municipality>
               </c:MeterNumberInfo>

 

 

  

Developer
Posts: 713
Registered: ‎05-31-2010
My Device: 8520
My Carrier: Movistar

Re: Looping through an object

[ Edited ]

Convert to String and use any XML parser you know. kXML2 is easy (http://kxml.sourceforge.net/kxml2/)

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

Re: Looping through an object

if you want to do that manually you have to use SoapObject, not Object.
(as you do one line above)

see
http://ksoap.objectweb.org/software/documentation/api/org/ksoap/SoapObject.html

you can use getPropertyCount to see how many properties are there, and getProperty(x) to retrieve a certain one.

Usually ksoap is used with mappings for complex data types that do this work for you.
----------------------------------------------------------
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