<scxml
xmlns="http://www.w3.org/2005/07/scxml"
version="1.0"
profile="ecmascript"
initial="idle">
<state id="idle">
<transition event="mousedown" target="dragging"/>
</state>
<state id="dragging">
<transition event="mouseup" target="idle"/>
<transition event="mousemove" target="dragging"/>
</state>
</scxml>
I want to parse this xml when i start the application i enter the initial state that is "idle" then when my event completed i want to move the next state "dragging". how can i do this?
I am using NSXmlparser in the following method.
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
if ([elementName isEqualToString:@"scxml"])
{
stateID = [attributeDict objectForKey:@"initital"];
stateInfo = [[StateInfo alloc]initWithStateName:stateID];
return;
}
if ([elementName isEqualToString: @"state"] ){
if ([[attributeDict objectForKey:@"transition"] isEqualToString:@"idle"]) {
}
else {
}
}
// if ([elementName isEqualToString:@"state"]) {
//// stateID = [attributeDict objectForKey:@"id"];
//// stateInfo = [[StateInfo alloc]initWithStateName:stateID];
//// NSLog(@"stateID = %@",stateID);
// return;
// }
if([elementName isEqualToString:@"transition"]){
//aList=[[List alloc]init];
stateID = [attributeDict objectForKey:@"target"];
targetStateInfo = [[StateInfo alloc]initWithStateName:stateID];
[stateInfo registerNextState:targetStateInfo withCondition:[attributeDict objectForKey:@"cond" ]];
return;
}
if ([elementName isEqualToString:@"scxml"])
{
stateID = [attributeDict objectForKey:@"initital"];
stateInfo = [[StateInfo alloc]initWithStateName:stateID];
return;
}
if ([elementName isEqualToString: @"state"] ){
if ([[attributeDict objectForKey:@"Name"] isEqualToString:@"Child2"]) {
// searchDone=YES;
}
else {
// searchDone=NO;
}
}
// if ([elementName isEqualToString:@"state"]) {
//// stateID = [attributeDict objectForKey:@"id"];
//// stateInfo = [[StateInfo alloc]initWithStateName:stateID];
//// NSLog(@"stateID = %@",stateID);
// return;
// }
if([elementName isEqualToString:@"transition"]){
//aList=[[List alloc]init];
stateID = [attributeDict objectForKey:@"target"];
targetStateInfo = [[StateInfo alloc]initWithStateName:stateID];
[stateInfo registerNextState:targetStateInfo withCondition:[attributeDict objectForKey:@"cond" ]];
return;
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if(!currentElementValue){
currentElementValue=[[NSMutableString alloc]init];
}
[currentElementValue appendString:string];
//currentElementValue = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
/* if(!currentElementValue)
currentElementValue = [[NSMutableString alloc] init];
else
[currentElementValue appendString:string];
*/
/* if(self.currentElementValue) { [self.currentElementValue appendString:string]; } */ }
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"scxml"])
return;
if([elementName isEqualToString:@"state"]){
//[aList setTitle:currentElementValue];
//NSLog(@"alist.title = %@",aList.title);
}
currentElementValue = nil;
}