0
我的嘗試目標是解析此xml文檔https://api.eveonline.com/eve/SkillTree.xml.aspx,並最終將其轉化爲核心數據。XML解析 - 使用KissXML和XPath將屬性分組到nsdictionary中
但我遇到問題的片段是
<rowset name="requiredSkills" key="typeID" columns="typeID,skillLevel">
<row typeID="13279" skillLevel="3" />
<row typeID="3402" skillLevel="4" />
</rowset>
我遇到正在試圖找出如何保持TYPEID和skillLevel在一起,在一個NSDictionary保存的問題。
因此,我們的目標是將每個<row typeID="13279" skillLevel="3" />
放到它自己的對象中。
我使用的主要代碼
-(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);
}
類型名工作得很好,每個對象我想只有1名,但它可以有多個typeIDs所以我想組這些值轉換爲1個對象,因此我可以最終將它們全部導入到核心數據中。 我知道typeIDs也只是被轉儲到一個數組中。我只是失去了如何更好地分隔元素行。
謝謝。
這就是我想的,我只是在用這個錯誤的工具敲打這個東西,謝謝 – BigB