-
Notifications
You must be signed in to change notification settings - Fork 607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow children to be objects instead of arrays #489
Comments
If you set explicitArray to false it will do that. I recommend against it because it will make your code fragile since the fact whether it is an array or not depends on the specific XML (and not any schema), so code might break when there is suddenly just one child node or when instead of one there are multiple.
|
@Leonidas-from-XIV yep I agree, I am trying to think of a generic solution, but yeah there might not be one. If you don't control the XML that comes to you, or if it could change, then you have to handle the format that it's in. Personally, I consider this a faulty design on the part of XML. |
@Leonidas-from-XIV this is what I am wondering - maybe XML has a newer standard that will fix this. It's crazy. |
There is a standard, it's just in the javascript world everyone seems to forget things called schemas. Proper XML tools in most languages when doing parsing, code gen etc will use and respect a schema. The schema can tell you if a child is a list via the schema properties, minOccurs, maxOccurs, mustOccurs, e.g. if minOccurs and maxOccurs = 1 then its a single element not a list, if it had minOccurs=0 and no maxOccurs then it would be optional list |
I am aware of the existence of schemas. But while sometimes you have a schema and can apply it often you just get some XML so I'm parsing it in the most general way. I am not sure it is even worth implementing support for this given the low amount of XML Schema in the wild. |
@Leonidas-from-XIV do we have an option to add an attribute to all the list when we build the xml from json |
I have only played with this lib for a little while, but it's shame that it seems like every child has to be an array. For example:
so that will get parsed to:
but it would be really cool, if there was a way to standardize the XML, so that if it assumes it's not a list, unless you explicitly tell it, so that the above would get parsed to:
so that if you did this:
it would get parsed to:
The text was updated successfully, but these errors were encountered: