2
votes
<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;
 }
1
show us d code, were u can fix it.. as u get to start event for state, u can make a check whether it is 'idle' or 'dragging' right?vishy
Better if you can show you code, or similar code it will help us to understand your exact requirement.Kamleshwar
are you using any xml parser ?AppleDelegate
@AppleDelegate yes I am Using NsXmlparseruser1208852
@vishy I am update my questionuser1208852

1 Answers

0
votes

This code you have commented seems to be fine:

if ([elementName isEqualToString:@"state"]) {
        stateID = [attributeDict objectForKey:@"id"];
        stateInfo = [[StateInfo alloc]initWithStateName:stateID];
        NSLog(@"stateID = %@",stateID);
}

stateID will show idle the first time and dragging the second time.

The xml is read from the top to the bottom

for <state> or similar tags you have to use if ([elementName isEqualToString:@"state"])

for attributes inside the tags like target="", event="" or id="" you have to use [attributeDict objectForKey:@"target"];

You don't have to do anything special, when the parser finish the first </state> it will continue with the next <state>.