0

i have a customised wordpress post that looks like this when view source.

How can i read parse it as XML ?

<title>A sample quiz</title>    
    <content>Hello.</content>
        <updatedDate>18/01/12</updatedDate>
    <updatedTime>16:11</updatedTime>
  <question>How many days are there in a week?</question>
  <hint>No hint</hint>

  <direction>Left</direction>
  <answer1>4</answer1>
  <answer2>5</answer2>
  <answer3>6</answer3>
  <answer4>7</answer4>
  <correctAnswer>4</correctAnswer>
  <score>20</score>
Desmond
  • 5,001
  • 14
  • 56
  • 115
  • 1
    Just take a look at this: http://www.raywenderlich.com/725/how-to-read-and-write-xml-documents-with-gdataxml – andrei Feb 02 '12 at 08:17
  • 1
    Possible duplicate? http://stackoverflow.com/questions/405749/parsing-html-on-the-iphone – The dude Feb 02 '12 at 08:18

1 Answers1

1

remember to set in your h file. NSXMLParserDelegate and set

- (void)didload
{

    NSString *site = [NSString   stringWithFormat:@"http://www.mysite.it/mydirectory/myxml"];
    NSURL *xmlURL = [NSURL URLWithString:site];

    myParser =  [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
    [myParser setDelegate:self];  
    [myParser parse];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 
    attributes:(NSDictionary *)attributeDict {

    if ([elementName isEqualToString:@"title"]) {
        NSLog(@"element %@",attributeDict);
        //do something
    }
    else if ([elementName isEqualToString:@"content"]){
        NSLog(@"element %@",attributeDict);
        //do something
    }
    //ecc
}

this is very simplified method. for more detail http://www.xcode-tutorials.com/parsing-xml-files/

Simone Pistecchia
  • 2,746
  • 3
  • 18
  • 30