views:

239

answers:

2

Hi all, I need to parse the xml listed below in the iphone. can anyone help me in this. please...!

Thanks in advance...

<Assignments>
<Course>
 <CourseName>Foundation of English</CourseName>
 <CourseGradePercentage>89</CourseGradePercentage>
 <AssignmentList>
  <Assignment>
   <AssignmentName>Foundations of English I</AssignmentName>
   <Week>Week 1</Week>
   <AssignmentGrade>2</AssignmentGrade>
   <AssignmentGradePercentage>20</AssignmentGradePercentage>
  </Assignment>
  <Assignment>
   <AssignmentName>Foundations of Maths I</AssignmentName>
   <Week>Week 1</Week>
   <AssignmentGrade>2</AssignmentGrade>
   <AssignmentGradePercentage>20</AssignmentGradePercentage>
  </Assignment>
 </AssignmentList>
</Course>
<Course>
 <CourseName>Foundation of Maths</CourseName>
 <CourseGradePercentage>92</CourseGradePercentage>
 <AssignmentList>
  <Assignment>
   <AssignmentName>Foundations of English I</AssignmentName>
   <Week>Week 1</Week>
   <AssignmentGrade>4</AssignmentGrade>
   <AssignmentGradePercentage>40</AssignmentGradePercentage>
  </Assignment>
  <Assignment>
   <AssignmentName>Foundations of Maths I</AssignmentName>
   <Week>Week 1</Week>
   <AssignmentGrade>4</AssignmentGrade>
   <AssignmentGradePercentage>40</AssignmentGradePercentage>
  </Assignment>
 </AssignmentList>
</Course>

What i need to get is this..

Foundation of English1 99.99%

Week1 Assignment 10 (100%) Week2 Assignment 8 (80%) Week3 Assignment 10 (100%)

Foundation of Mathematics1 100%

Week1 Assignment 10 (100%)

This is just a sample data.. this is the format which i need to display on the iphone table view.. Please Help me..

Thanks, Shibin [email protected]

+4  A: 

Consider using libxml2 with an Objective-C front provided by this useful set of wrapper functions.

You issue an XPath query to your XML document object and get back Foundation class objects: NSArray, NSString, and NSDictionary, e.g.:

//
// Generate NSData* object called _xmlData which is the XML data
// 

// ...

//
// Query this data for course names
//

NSArray *_queriedCourseNames = PerformXMLXPathQuery(_xmlData, @"//*[local-name()='Course']/*[local-name()='CourseName']");
Alex Reynolds
ok thanks, but i cant understand this one. also i am using the NSXMLParser rather than libxml2
Shibin Moideen
A: 

Instead of 'Course,' why do you want to use local-name?

//Course/CourseName

should just work, right?

vtd-xml-author