In XML, how do I declare array of integers?
I can declare it as the following:
<numbers type="array"> <value>3</value> <value>2</value> <value>1</value> </numbers>
but may be there's simpler way like this?
<numbers [3,2,1]></numbers>
An array is a data structure, which can store a fixed-size collection of elements of the same data type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.
An array is a collection of similar types of data. For example, if we want to store the names of 100 people then we can create an array of the string type that can store 100 names. String[] array = new String[100];
XML provides the capability to display data because it is a markup language. JSON supports array. XML doesn't support array.
The second way isn't valid XML; did you mean <numbers>[3,2,1]</numbers>
?
If so, then the first one is preferred because all you need to get the array elements is some XML manipulation. On the second one you first need to get the value of the <numbers> element via XML manipulation, then somehow parse the [3,2,1]
text using something else.
Or if you really want some compact format, you can consider using JSON (which "natively" supports arrays). But that depends on your application requirements.
No, there is no simpler way. You only can lose the type=array
.
<numbers> <value>3</value> <value>2</value> <value>1</value> </numbers>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With