Parsing XML data with same tags at different depths
for a OSX-Application i need to parse XML-Data. My problem is that there
are used the same tags in different depths and all of them contain
different data.
The XML I need to parse is taken from the API of EVE Online:
<?xml version='1.0' encoding='UTF-8'?>
<eveapi version="2">
<currentTime>2010-12-21 14:33:30</currentTime>
<result>
<rowset columns="groupName,groupID" key="groupID" name="skillGroups">
<row groupID="266" groupName="Corporation Management">
<rowset columns="typeName,groupID,typeID,published" key="typeID"
name="skills">
<row groupID="266" published="1" typeID="11584"
typeName="Anchoring">
<description>...</description>
<rank>3</rank>
<rowset columns="typeID,skillLevel" key="typeID"
name="requiredSkills"/>
<requiredAttributes>
<secondaryAttribute>...</secondaryAttribute>
<primaryAttribute>...</primaryAttribute>
</requiredAttributes>
<rowset columns="bonusType,bonusValue" key="bonusType"
name="skillBonusCollection">
<row bonusType="canNotBeTrainedOnTrial" bonusValue="1"/>
</rowset>
</row>
<row groupID="266" published="0" typeID="3369" typeName="CFO
Training">
<description>...</description>
<rank>3</rank>
<rowset columns="typeID,skillLevel" key="typeID"
name="requiredSkills">
<row skillLevel="2" typeID="3363"/>
<row skillLevel="3" typeID="3444"/>
</rowset>
<requiredAttributes>
<secondaryAttribute>...</secondaryAttribute>
<primaryAttribute>...</primaryAttribute>
</requiredAttributes>
<rowset columns="bonusType,bonusValue" key="bonusType"
name="skillBonusCollection"/>
</row>
</rowset>
</row>
</rowset>
</result>
<cachedUntil>2007-12-23 21:51:40</cachedUntil>
</eveapi>
I want to create a new GroupItem with the contents of the line:
<row groupID="266" groupName="Corporation Management">
In this group I want to add as many SkillItems as rows are listed in the
second rowset:
<rowset columns="typeName,groupID,typeID,published" key="typeID"
name="skills">
Here I have (in this example) two Skills listed, which themselves contain
various data, which are partly again stored in a rowset.
My problems are:
How do I differentiate the multiple rowsets, which contain different data
I need to add to different objects?
How do I recognize the end of a skill-row, group-row and the other rowsets
including rows as the tags are used for multiple, different objects?
The problem is not to extract the single attributes and contents of the
objects!
I am using NSXMLParser at the moment. For smaller and less complex
XML-Data I managed to seperate the rows correctly. However, here, I don't
know how to solve this, because of the repetitive use of the same tags in
the data.
As there is no written code yet (due to lack of ideas how to solve this),
I can't add any attempted implementation...
For my working attempt of the small XML (which only contains one rowset
with one row) I used only the following code:
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString
*)elementName namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:@"row"] && [[attributeDict allKeys]
containsObject:@"characterID"]) {
//Code to extract needed attributes
}
}
How can get I rid of this problem?
No comments:
Post a Comment