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
Contributor
Posts: 43
Registered: ‎07-21-2011
My Device: BB 9800
My Carrier: Developer
Accepted Solution

how to cut image path within the tag in blackberry

Hii,

I have one tag called a which contains some description and one image URL.hear is my Description tag.

<description><![CDATA[<img width="100" src="http://MYURL/img/news/111/octo/one1.jpg" align="right" alt="name"/></description>


i want to cut this img path to display on simulator.i am using SAX parser for parsing. need your help.

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

Re: how to cut image path within the tag in blackberry

http://www.blackberry.com/developers/docs/7.0.0api/org/xml/sax/helpers/DefaultHandler.html#startElem... java.lang.String, java.lang.String, org.xml.sax.Attributes)

and handle the Attributes
----------------------------------------------------------
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
Contributor
Posts: 43
Registered: ‎07-21-2011
My Device: BB 9800
My Carrier: Developer

Re: how to cut image path within the tag in blackberry

if(element.equals("description")){

locationObj.setDescription(value);
System.out.println("description from the location obj" +locationObj.getDescription().toString());
}
I have defined the description tag like this.but not able to understand how to handle the data within the <description >tag.
Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: how to cut image path within the tag in blackberry

the tag you need to extract the adress is img.

<img width="100" src="http://MYURL/img/news/111/octo/one1.jpg" align="right" alt="name"/>

as you can see it as 4 attributes, the second attribute is the one you want.
----------------------------------------------------------
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
Contributor
Posts: 43
Registered: ‎07-21-2011
My Device: BB 9800
My Carrier: Developer

Re: how to cut image path within the tag in blackberry

I have done somthing like this to get the attribute values.

int length = attributes.getLength();
for(int i=0;i<length;i++){
String name = attributes.getQName(i);
String value = attributes.getValue(i);
String nsURi = attributes.getURI(i);
String lName = attributes.getLocalName(i);
}
is it right???
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to cut image path within the tag in blackberry

Looks OK to me.  What did you get?

Contributor
Posts: 43
Registered: ‎07-21-2011
My Device: BB 9800
My Carrier: Developer

Re: how to cut image path within the tag in blackberry

nothing i have just wrote this lines not understanding how to implement in my parser...
Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: how to cut image path within the tag in blackberry

write them into the startElement method
----------------------------------------------------------
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
Contributor
Posts: 43
Registered: ‎07-21-2011
My Device: BB 9800
My Carrier: Developer

Re: how to cut image path within the tag in blackberry

wrote. then?
Contributor
Posts: 43
Registered: ‎07-21-2011
My Device: BB 9800
My Carrier: Developer

Re: how to cut image path within the tag in blackberry

public class ResponseHandler_Review extends DefaultHandler{
     
	 CommonFeedBean locationObj = null;
     boolean flag = false;
     String element;
     StringBuffer sb;
     String value;
     
//     DataDownLoadThread datadownload;
     public static Vector vectorLocaiton1 = new Vector();
//    private Bitmap image;
      String str;
     public void startElement(String uri, String localName, String qName, Attributes attributes)
     {
//         System.out.println("##########################"+localName.toString());   
    	 int length = attributes.getLength();
    	 for(int i=0;i<length;i++){
    	 String name = attributes.getQName(i);
    	 String value = attributes.getValue(i);
    	 String nsURi = attributes.getURI(i);
    	 String lName = attributes.getLocalName(i);
    	 }
    	 element = localName;
    	 if(element.equals("item"))//this is your parent node
            	 
             {
            	 
                     System.out.println("Start Element called"+ element.toString());
                     locationObj = new CommonFeedBean();
                     flag = true;
             }
            
             System.out.println("outside the start-element method");
     }
     
     public void characters(char[] ch, int start, int length)
     {
              value = new String( ch, start, length );
             System.out.println("+++++++++++++"+ element.toString());
             if(flag==true){
                     System.out.println("Char method called");
                     if(element.equalsIgnoreCase("title")){
                             locationObj.setTitle(value);
                             System.out.println("location obj get title = "+ locationObj.getTitle().toString());
                     }
                     if(element.equalsIgnoreCase("link")){
                             locationObj.setLink(value);
                             System.out.println("link from locatio obj =  "+ locationObj.getLink().toString());
                            // MyScreen.listField.add(locationObj.getsubTitle());
                     }
                     if(element.equals("description")){

                    	     locationObj.setDescription(value);
                    	     
                             System.out.println("description from the location obj" +locationObj.getDescription().toString());
                             
                        }
                     if(element.equals("author")){
                             locationObj.setAuthor(value);
                             System.out.println("Get Author from location obj = "+locationObj.getAuthor().toString());
                     }
                     if(element.equals("pubate")){
                           locationObj.setpubdate(value);
                           System.out.println("get pubdate from location obj =" +locationObj.getPubdate().toString());
                     }
             }
            
             System.out.println("Character method ends");
     }
     
     public void endElement(String uri, String localName, String qName)
     {
           element = localName;
           if(element.equalsIgnoreCase("item")){
                 System.out.println("End Method called");
                 vectorLocaiton1.addElement(locationObj);
                 flag = false;
                 
           }  
          
     }

 this is my parser.