0

my attempted goal is to parse this xml doc https://api.eveonline.com/eve/SkillTree.xml.aspx and eventually get it into core data.

but the snippet i'm having trouble with is

<rowset name="requiredSkills" key="typeID" columns="typeID,skillLevel">
          <row typeID="13279" skillLevel="3" />
          <row typeID="3402" skillLevel="4" />
        </rowset>

the problem i'm having is trying to figure out how to keep the typeID and skillLevel together to save in an nsdictionary.

So the goal is to put each <row typeID="13279" skillLevel="3" /> into its own object.

the main code i'm using is

-(void)parseXMLFromBundle
{
NSError *error;

NSString *path = [[NSBundle mainBundle] pathForResource:@"SkillTree" ofType:@"xml"];

DDXMLDocument *xmlDoc = [[DDXMLDocument alloc] initWithData:[NSData dataWithContentsOfFile:path] options:0 error:&error];

//main array with everything
NSArray *xmlItems = [xmlDoc nodesForXPath:@"//result" error:&error];
//go through it to extract each thing
for (DDXMLElement *itemElement in xmlItems)
{
self.typeArray = [itemElement nodesForXPath:@"//@typeName" error:&error];

self.requiredIDArray = [itemElement nodesForXPath:@"//row[@typeID]/@typeID" error:&error];
DLog(@"required SkillID: %@",self.requiredIDArray);

}

The typeName works fine, each object I want only has 1 name, but it can have multiple typeIDs so I am trying to group these values into 1 object so i can import it all into core data eventually. I know with the typeIDs are also just being all dumped into an array. I am just lost as to how to get stuff better separated by elemental row.

Thanks.

4

1 に答える 1

0

NSXMLParser を使用すると、はるかに簡単になります。行タグを開くたびに、それを表す新しいオブジェクトを作成します。この時点ですべての属性のディクショナリも取得するので、それを使用して新しい行オブジェクト インスタンスのプロパティを設定します。

于 2012-12-25T09:53:06.673 に答える