Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
encoding/xml: lacks support for decoding arrays #20709
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
Given it is possible to encode arrays, I would expect it should be possible to decode arrays.
However, if the package supported decoding arrays these scenarios aren't completely obvious:
More XML elements than the array's length
Should it error, or ignore the remaining?
I would probably expect it to error since the data being decoded would not be of the same type, where the type is an array of specific length and the data won't fit into an array of that length.
Counter to that though, what if an application didn't care about additional elements?
Less XML elements than the array's length
Should it error, or leave the extra elements in the array as zero values?
I would probably expect it to leave the extra elements in the array as zero values, given that when fields in a struct are missing in data being decoded they remain as their zero value.
Counter to that though, what if an application needed to distinguish between zero values and an incomplete list?
I think that if we add support for decoding arrays, it should return an error if the number of elements is not exactly the length of the array. If you aren't sure of how exactly many elements you are getting, you should be using a slice, not an array.