kortovos
27 Sep 2010, 3:37 AM
I am working with complex data (in the form of XML) and I have a question.
How do you work with a variable number of fields inside a model. For instance, below is the data about 2 persons and their cars. But the number of cars is not set/constant. How do you define this in a model, and how do you access the data from the different cars?
<carlist>
<person>
<name>james</name>
<cars>
<car>
<model>Model1</model>
<type>Type1</type>
<licenseplate>AAA-001</licenseplate>
</car>
<car>
<model>Model2</model>
<type>Type2</type>
<licenseplate>BBB-001</licenseplate>
</car>
</cars>
</person>
<person>
<name>Ellen</name>
<cars>
<car>
<model>Model1</model>
<type>Type2</type>
<licenseplate>CCC-001</licenseplate>
</car>
</cars>
</person>
</carlist>
How do you work with a variable number of fields inside a model. For instance, below is the data about 2 persons and their cars. But the number of cars is not set/constant. How do you define this in a model, and how do you access the data from the different cars?
<carlist>
<person>
<name>james</name>
<cars>
<car>
<model>Model1</model>
<type>Type1</type>
<licenseplate>AAA-001</licenseplate>
</car>
<car>
<model>Model2</model>
<type>Type2</type>
<licenseplate>BBB-001</licenseplate>
</car>
</cars>
</person>
<person>
<name>Ellen</name>
<cars>
<car>
<model>Model1</model>
<type>Type2</type>
<licenseplate>CCC-001</licenseplate>
</car>
</cars>
</person>
</carlist>