Hi
We have an requirement in our project to browse & upload an XML file and show it on the datagrid, edit the grid and then save the contents to the database. I'm able to see examples that take a XML from a specific folder and show on the datagrid, but not able to see any examples that browse for a XML and then upload it. It would be great if someone can point me to the examples or some sample code. Our XML looks like:
<VisitImportList>
<Visit>
<AuditDetails>
<UpdateUser>ADMIN</UpdateUser>
<UpdateTimestamp>2010-10-22T16:25:26.593Z</UpdateTimestamp>
</AuditDetails>
<VisitId>3</VisitId>
<MeasurementCollectionId>4</MeasurementCollectionId>
<WeightConfirmationCode>5</WeightConfirmationCode>
<PrefilledIndicator>true</PrefilledIndicator>
<VisitDate>2010-10-22T16:25:26.593Z</VisitDate>
</Visit>
<Visit>
<AuditDetails>
<UpdateUser>ADMIN</UpdateUser>
<UpdateTimestamp>2010-10-22T16:25:26.593Z</UpdateTimestamp>
</AuditDetails>
<VisitId>3</VisitId>
<MeasurementCollectionId>3</MeasurementCollectionId>
<BloodPressureConfirmationCode>4</BloodPressureConfirmationCode>
<PrefilledIndicator>true</PrefilledIndicator>
<VisitInvalidCode>1</VisitInvalidCode>
<VisitInvalidReasonText>No Dates</VisitInvalidReasonText>
</Visit>
</VisitImportList>
Ok I have been able to show the data on the grid using FileReference for upload and XML/XMLListCollection. Now the issue is when I try to save to the database. I did not want to create a new thread, so I have added my question to here:
private function saveVisit(event:MouseEvent): void
{
var decoder:SimpleXMLDecoder = new SimpleXMLDecoder();
var data:Object = decoder.decodeXML(xmlDoc);
var array:Array = ArrayUtil.toArray(data.VisitImportList.Visit);
tempCollection = new ArrayCollection(array);
Now I have the data in my arraycollection (tempCollection). But it holds generic objects and I need to convert them to Visit Object. So I want to loop through the ArrayCollection, convert the object in to specific custom Visit Objects and then add them to another Collection (I'm sure this is not the right way to do, but I'm not able to come up with an alternate):
for (var i:int = 0; i < tempCollection.length; ++i)
{
model.visit = new Visit();
model.visit = Visit(tempCollection.getItemAt(i, 0)); // This line gives the error Type Coercion failed: cannot convert Object@1d4e4719 to com.model.Visit.
model.visit = tempCollection.getItemAt(i) as Visit; // This line always has Visit as null eventhough the tempCollection has 2 objects
model.pvList.visits.addItemAt(Visit, i);
}
So can someone help on how to loop through the ArraCollection and convert the AS Object to custom Visit object and then add to another ArrayCollection OR an easier way to do this
Thanks
Harish