Les comento un poco mi problema, tengo un XML, en el cual tengo una pregunta y varias respuestas a esa pregunta, el caso es que, quiero agregar mas respuestas posibles, por cada pregunta. Lo que he logrado hasta ahora es insertar una pregunta y una respuesta, pero no he logrado insertar mas respuestas por pregunta.
Adjunto mi codigo y mi XML, a ver si me pueden colaborar.
Gracías de antemano, Aleka.
Este es mi código As3
// ActionScript file
import mx.rpc.events.*;
import flash.events.*;
import mx.controls.*;
import mx.rpc.http.HTTPService;
import comp.q;
import mx.binding.utils.*;
import memorphic.xpath.XPathQuery;
[Bindable]
public var lorem:XML
public var result:XMLList
/*Conexion archivo XML*/
public function ServicioHTTP():void
{
var service:HTTPService = new HTTPService();
service.url = 'final_question.xml'
service.resultFormat = 'e4x'
service.addEventListener(ResultEvent.RESULT, construcXML)
service.addEventListener(FaultEvent.FAULT, onFault)
service.send()
}
public function construcXML(event:ResultEvent):void
{
lorem = event.result as XML
var query:XPathQuery = new XPathQuery("//a |//b")
var result:XMLList = query.exec(lorem)
trace(result)
}
public function onFault(event:FaultEvent):void
{
var e:String = 'ERROR';
Alert.show(event.fault.faultString, e+'\n'+event.fault.faultCode.toString());
}
public function addXML():void
{
var newXML:XML = <question>
<q>{comp.q}</q>
<a>{comp.a}</a>
</question>;
var selectedXMLIndex:uint = myData.selectedIndex;
if(myData.selectedIndex == 0)
{
lorem = lorem.prependChild(newXML);
}else{
lorem = lorem.appendChild(newXML);
}
var newSelectedIndex:uint = (myData.selectedIndex == 0) ? selectedXMLIndex +1 : selectedXMLIndex;
myData.selectedIndex = newSelectedIndex;
callLater(changeDataGridIndex);
}
public function delXML():void
{
var myselectedIndex:uint = myData.selectedIndex
delete (lorem.question[myselectedIndex])
}
public function changeDataGridIndex():void
{
var selectedXmlIndex:uint = myData.selectedIndex;
var newSelectedIndex:int = (selectedXmlIndex==0) ? 0 : selectedXmlIndex - 1;
myData.dataProvider = lorem.question;
myData.selectedIndex = newSelectedIndex;
}
Este es mi XML
<?xml version="1.0" ?>
<test_questions>
<question>
<image_source alpha="15">images/frame23_1.jpg</image_source>
<q>Sociological</q>
<!-- For classify section. -->
<a>Criminal behavior is imitated, positively reinforced, or negatively reinforced.</a>
<a>CRIME IS THE illegitimate means to reach the cultural goal</a>
<a>Crime is the illegal way to achieve peer status</a>
<a>Delinquent behavior is due to feeling outside of the group</a>
<a>Crime is normal and needed</a>
<a>Delinquent behavior is due to poor child-rearing that results in low self-control</a>
</question>
<question>
<image_source alpha="15">images/frame23_3.jpg</image_source>
<q>BIOLOGICAL</q>
<!-- For classify section. -->
<a>Criminals are born different than non-criminals</a>
<a>Criminal behavior is inherited</a>
<a>Criminal behavior is due to biochemical imbalances</a>
</question>
</test_questions>
