BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 04-16-2008, 02:55 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Feb 2008
Model: 8310
PIN: N/A
Carrier: Informatico
Posts: 56
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default read xml

Please Login to Remove!

Hi

I need help for read an xml that give me an asp .net web service, the xml is:

<?xml version="1.0" encoding="utf-8" ?>
- <DataSetClientes xmlns="http://tempuri.org/">
- <xs:schema id="DataSetClientes" targetNamespace="http://tempuri.org/DataSetClientes.xsd" xmlns:mstns="http://tempuri.org/DataSetClientes.xsd" xmlns="http://tempuri.org/DataSetClientes.xsd" xmlnss="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-comml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified">
- <xs:element name="DataSetClientes" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
- <xs:complexType>
- <xs:choice minOccurs="0" maxOccurs="unbounded">
- <xs:element name="CLIENTES">
- <xs:complexType>
- <xs:sequence>
<xs:element name="CLI_CODIGO" type="xs:string" minOccurs="0" />
<xs:element name="CLI_NOMBRE" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
- <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-comml-msdata" xmlns:diffgr="urn:schemas-microsoft-comml-diffgram-v1">
- <DataSetClientes xmlns="http://tempuri.org/DataSetClientes.xsd">
- <CLIENTES diffgr:id="CLIENTES1" msdata:rowOrder="0">
<CLI_CODIGO>000049</CLI_CODIGO>
<CLI_NOMBRE>BANCO SANTANDER CENTRAL HISPANO, S.A.</CLI_NOMBRE>
</CLIENTES>
- <CLIENTES diffgr:id="CLIENTES2" msdata:rowOrder="1">
<CLI_CODIGO>000063</CLI_CODIGO>
<CLI_NOMBRE>BANCO MAPFRE</CLI_NOMBRE>
</CLIENTES>
- <CLIENTES diffgr:id="CLIENTES3" msdata:rowOrder="2">
<CLI_CODIGO>000065</CLI_CODIGO>
<CLI_NOMBRE>BARCLAYS BANK, S.A.E.</CLI_NOMBRE>
</CLIENTES>

and this is the code that give in string the xml:

try {
HttpTransport transport = null;
SoapObject soap = new SoapObject("http://tempuri.org/","ObtenerClientes");

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
envelope.bodyOut = soap;
envelope.dotNet = true;

transport = new HttpTransport("http://100.1.1.126/WebService/service.asmx");
transport.debug = true;
transport.call("http://tempuri.org/ObtenerClientes", envelope);

soapMesg = envelope.getResult().toString();

//StringItem item = new StringItem("Resultado: ", envelope.getResult().toString());
//formulario.append(item);
} catch (Exception e) {
formulario.append(e.toString());
e.printStackTrace();
}

But how can i work with this xml code?

Thanks, Oscar
Offline  
Old 04-16-2008, 03:16 AM   #2 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

you have to implement a parser.
example given:

('in' is an input stream in this case. Handler is an implementation of DefaultHandler)
Code:
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();			
sp.parse(in, new Handler(app));
hth,
simon
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 04-16-2008, 03:40 AM   #3 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Simon - could contender for an example application, i'll get one written today and post on NorthCubed.
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 04-16-2008, 04:39 AM   #4 (permalink)
Thumbs Must Hurt
 
Join Date: Feb 2008
Model: 8310
PIN: N/A
Carrier: Informatico
Posts: 56
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

in Jonathan H Fisher - Blog there are a lot of articles, what is the correct, i have been trying looking for but I didn't find it. and the other url of cube you need login as admin for see it...
Offline  
Old 04-16-2008, 05:48 AM   #5 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

here you go: BlackBerry Dev Lesson 7 - Parsing XML with SAX

should get you started, might be a better example on the blackberry.com dev site but i'm not going to attempt to find it.
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 04-16-2008, 09:55 AM   #6 (permalink)
Thumbs Must Hurt
 
Join Date: Feb 2008
Model: 8310
PIN: N/A
Carrier: Informatico
Posts: 56
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

but,when I debug the application and watch the variable name, ever give me a number as "#446578688", what is the mean of this number? and why don't obtain the tag's name? please help.
Offline  
Old 04-16-2008, 10:08 AM   #7 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

looking at your code here: reading xml with parse it seems you're trying to read the contents of a node while at the start element, the contents are not read until the parser has reached the end element. having said that i've never coded a parser like you have there so could be wrong, i always use the method as described in the link in my previous post.

see the docs for more info: /docs/api/org/xml/sax/helpers/DefaultHandler.html
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 04-16-2008, 03:39 PM   #8 (permalink)
Thumbs Must Hurt
 
Join Date: Feb 2008
Model: 8310
PIN: N/A
Carrier: Informatico
Posts: 56
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok, have you find the sample on the blackberry.com dev site about the SAX xml? I don't know how can i read the web service xml with SAX xml, because the sample of the link BlackBerry Dev Lesson 7 - Parsing XML with SAX is for read an xml file of only one data, I need a sample code for read more than one and not a file, a web service result...

thank you, Oscar
Offline  
Old 04-16-2008, 06:01 PM   #9 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

a string is a string no matter where it comes from... there's enough info in this thread to figure it out so i'm bowing out at this point.
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 04-17-2008, 02:28 AM   #10 (permalink)
Thumbs Must Hurt
 
Join Date: Feb 2008
Model: 8310
PIN: N/A
Carrier: Informatico
Posts: 56
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have donwloaded the sax library from saxproject, by I don't know how can add this librari, i have tried to add since properties of netbeans and add jar, but when i compile give me an error.
Offline  
Old 04-17-2008, 03:19 AM   #11 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
conn = (HttpConnection) Connector.open(url);
conn.setRequestMethod(HttpConnection.GET);
in = conn.openInputStream();
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();			
sp.parse(in, new Handler(callback));
this would read something from an url and handle it over to the Handler (an extension of DefaultHandler) with no authorization required.
__________________
java developer, Devinto, hamburg/germany
Offline  




Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.