Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array definition in XML?

Tags:

arrays

xml

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> 
like image 277
Nick Avatar asked May 23 '11 14:05

Nick


People also ask

What defines array?

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.

What is arrays and example?

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];

Is array supported by XML?

XML provides the capability to display data because it is a markup language. JSON supports array. XML doesn't support array.


2 Answers

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.

like image 70
carlosfigueira Avatar answered Sep 28 '22 17:09

carlosfigueira


No, there is no simpler way. You only can lose the type=array.

<numbers>     <value>3</value>     <value>2</value>     <value>1</value> </numbers> 
like image 39
Lars Avatar answered Sep 28 '22 17:09

Lars