Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Serializer] add type casting to XML decoding #36482

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

Closed
dkarlovi opened this issue Apr 17, 2020 · 13 comments
Closed

[Serializer] add type casting to XML decoding #36482

dkarlovi opened this issue Apr 17, 2020 · 13 comments

Comments

@dkarlovi
Copy link
Contributor

dkarlovi commented Apr 17, 2020

Description

The data coming from XML is always string. Additional support could be added for XML Schema, XML Schema instance type hints, making the decoded information much more correct.

Example

<foo xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <one xsi:type="xs:integer">123</one>
    <two xsi:type="xs:float">123.23</two>
    <three xsi:nil="true"/>
</foo>

could produce:

array
    one: int(123)
    two: float(123.23)
    three: null

but currently produces

array
    one: string "123"
    two: string "123.23"
    three: string ""
@dkarlovi
Copy link
Contributor Author

In theory, this could be done in reverse when encoding the XML also.

@lmasforne
Copy link
Contributor

lmasforne commented Apr 19, 2020

The XmlEncoder use libxml to decode XML, xsi:type is not interpreted by this lib, we must introduce an other php lib to parse this kind of xml like this : https://www.php.net/manual/fr/book.sdo-das-xml.php.
This kind of lib got probably dependencies on extension (here SDO for example), i think it's for that work never begin.
Is this feature planned ?

@dkarlovi
Copy link
Contributor Author

@lmasforne not sure what you mean, the issue is not suggesting introduction of a new dependency nor otherwise.

@lmasforne
Copy link
Contributor

I read how xml is decoded and it use the XmlEncoder class wich use libxml. I dont know if this lib can interpreted 'xsi:type' because when i try to load the xml file upper this lib lauch an error on line 127 here $error = libxml_get_last_error() , i dont see in this library how parse 'xsi:type', you see what i mean ?

@dkarlovi
Copy link
Contributor Author

dkarlovi commented Apr 21, 2020

I have a typo in my XML example, the third tag is not self-closed. 🙈 I've fixed it now.

Even if the lib doesn't support it, it will read the attributes as, well, attributes. They can then get additional interpretation and get casted in a post-processing step.

@lyrixx
Copy link
Member

lyrixx commented Nov 12, 2020

This is also related to: #33850
This PR is not as perfect as the proposition of this issue, but it could solve your issue.

@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@dkarlovi
Copy link
Contributor Author

Yup.

@carsonbot carsonbot removed the Stalled label May 21, 2021
@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@dkarlovi
Copy link
Contributor Author

Yes.

@carsonbot carsonbot removed the Stalled label Nov 22, 2021
@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?

@carsonbot
Copy link

Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3

@carsonbot
Copy link

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

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

5 participants