Sandeep Singh
Sandeep Singh

Reputation: 826

XML file Parsing?

I have a xml file in following format.

<Category id="CIBA_VISION" image="Choose_Page\CON_PNG\Ciba_Vision.png">
    <Product id="CON_CIBA_01" image="Buy_Page\Eye_CON_PNG\CIBAVision\List_01.png">
        <Detail image="Buy_Page\Eye_CON_PNG\CIBAVision\Buy_01.png"/>
    </Product>

where images contains image path in specified folder which is in resource folder of project.

My question is: After parsing this xml file, will the image tag pick the values from the folder or it will show only path after parsing.

Thanks in advance.

Upvotes: 1

Views: 226

Answers (4)

Deepak
Deepak

Reputation: 1441

NSString *imaegeString = @"Ciba_Vision.png";
NSArray *pathComponents = [imaegeString componentsSeparatedByString:@"_"];
NSString *imageName=[pathComponents lastObject];
UIImage *img8 = [UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:imageName]];

try this code

Upvotes: 2

ajay
ajay

Reputation: 3345

you ll get only path after parsing it wont do anything with that path.we have use that path and do our work thats it

some sample is

  -(void)parser:(NSXMLParser *)parser 
didStartElement:(NSString *)elementName 
   namespaceURI:(NSString *)namespaceURI 
  qualifiedName:(NSString *)qName 
     attributes:(NSDictionary *)attributeDict
{
    if([elementName isEqualToString: @"Detail"]){
       //get all the attributes of from the dictionary(attributeDict)

    }
}

Upvotes: 0

Gypsa
Gypsa

Reputation: 11314

yes you can get the image by the following code in your imageView You can try this:-

 NSString *imaegeString = @"Choose_Page\CON_PNG\Ciba_Vision.png";
    NSArray *pathComponents = [imaegeString componentsSeparatedByString:@"_"];
    NSString *imageName=[pathComponents lastObject];
    UIImage *img8 = [UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:imageName]];

Hope this might help you...If this work you can do same for another strings in your parsing...

Upvotes: 0

Nick Weaver
Nick Weaver

Reputation: 47241

It will only contain the values you see there, except you add the base to URLs while parsing yourself.

And picking completely depends on your context, how do you like the code to pick?

Upvotes: 0

Related Questions