Skip to content
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

Cast attribute value to string? #125

Open
jbrooksuk opened this issue Apr 12, 2017 · 7 comments
Open

Cast attribute value to string? #125

jbrooksuk opened this issue Apr 12, 2017 · 7 comments

Comments

@jbrooksuk
Copy link

When passing an attribute that is a non-string value, writeAttribute throws an exception:

TypeError: XMLWriter::writeAttribute() expects parameter 2 to be string, integer given

Would it not be ideal to simply cast the value as a string and avoid the exception? This makes the API way more developer friendly IMHO.

@staabm
Copy link
Member

staabm commented Apr 12, 2017

its the job of the serializer functions to convert whatever type you have to a string.

even if it can be achieved via a simple string cast, it would IMO be better to have this kind of code explicitly written in a serializer instead of doing it implicitly in the framework/lib.

@jbrooksuk
Copy link
Author

What if you're only passing an array of data through to the write method though? There's no chance of serializing at that point.

@staabm
Copy link
Member

staabm commented Apr 12, 2017

casting such a array to a string would also not produce the xml you expect, so this wouldn't help either?

could you show a use case in which your initial assumption makes sense to you?

@evert
Copy link
Member

evert commented Apr 12, 2017

Personally I think we should accept all scalars here... it makes kinda sense to me.

@staabm
Copy link
Member

staabm commented Apr 12, 2017

I agree with supporting scalars but not complex types

@jbrooksuk
Copy link
Author

String is a scalar. Does that mean you're willing to do this?

@staabm
Copy link
Member

staabm commented Apr 13, 2017

To be honest I did not read the initially posted value carefully and assumed the error is about writing a array/object. Writing a scalar like int,string,float makes sende though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants