Representing arrays of values in an XML file.
-
I work primarily with C++ and trying to get a handle on XML. Consider the following class of data: classA { CString name; int widgits[3]; } Lets assume the data for the items in the class is: name = "Bob" widgits = {1,6,9} If I was to create an XML file to hold data such as that above, how would the array of widgits be represented? Would it look something like this? Bob 1 2 3 It doesnt seem that having 3 child elements named "widgit" under the parent named "data" would be correct. Afteral how would it get read back in correctly? Any help or keyword that I could use for a search would be appreciated. Even a good book on the subject ! Thank you for your help ! Jack
-
I work primarily with C++ and trying to get a handle on XML. Consider the following class of data: classA { CString name; int widgits[3]; } Lets assume the data for the items in the class is: name = "Bob" widgits = {1,6,9} If I was to create an XML file to hold data such as that above, how would the array of widgits be represented? Would it look something like this? Bob 1 2 3 It doesnt seem that having 3 child elements named "widgit" under the parent named "data" would be correct. Afteral how would it get read back in correctly? Any help or keyword that I could use for a search would be appreciated. Even a good book on the subject ! Thank you for your help ! Jack
It would be more like:
<data> <name>Bob</name> <widgits> <widgit>1</widgit> <widgit>2</widgit> <widgit>3</widgit> </widgits> </data>
since the widgets element would serve as a container (array) of widgets.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
I work primarily with C++ and trying to get a handle on XML. Consider the following class of data: classA { CString name; int widgits[3]; } Lets assume the data for the items in the class is: name = "Bob" widgits = {1,6,9} If I was to create an XML file to hold data such as that above, how would the array of widgits be represented? Would it look something like this? Bob 1 2 3 It doesnt seem that having 3 child elements named "widgit" under the parent named "data" would be correct. Afteral how would it get read back in correctly? Any help or keyword that I could use for a search would be appreciated. Even a good book on the subject ! Thank you for your help ! Jack
Jack 2927 wrote:
It doesnt seem that having 3 child elements named "widgit" under the parent named "data" would be correct.
Yes basically it is. Sometimes people or systems prefer a more verbose representation but the same basic principle applies: <data> <name>Bob</name> <widgetList> <widgit>1</widgit> <widgit>2</widgit> <widgit>3</widgit> </widgetList> </data>
led mike
-
It would be more like:
<data> <name>Bob</name> <widgits> <widgit>1</widgit> <widgit>2</widgit> <widgit>3</widgit> </widgits> </data>
since the widgets element would serve as a container (array) of widgets.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
Well, at least we are on the same page for once!
"We make a living by what we get, we make a life by what we give." --Winston Churchill