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

Set encoding for toXml #4

Open
EgorGruzdev opened this issue Oct 26, 2017 · 3 comments
Open

Set encoding for toXml #4

EgorGruzdev opened this issue Oct 26, 2017 · 3 comments

Comments

@EgorGruzdev
Copy link

Example:

$model->toXml('utf-8');

Result:

<?xml version="1.0" encoding="utf-8"?><trains id="123"><train id="1"><name>Сапасан</name><departure>Москва</departure></train></trains>

Сurrently the result:

$model->toXml();
<?xml version="1.0"?><trains id="123"><train id="1"><name>&#x421;&#x430;&#x43F;&#x430;&#x441;&#x430;&#x43D;</name><departure>&#x41C;&#x43E;&#x441;&#x43A;&#x432;&#x430;</departure></train></trains>

I would have done it myself, but I can not find where to "dig."

@EgorGruzdev
Copy link
Author

Found:
/src/Mapper/XmlModelMapper.php (version 2.2.16)
line 270

$elementXml = '<'.$elementName.'></'.$elementName.'>';

replace

$elementXml = '<?xml version="1.0" encoding="utf-8"?><'.$elementName.'></'.$elementName.'>';

but how to pass the encoding if you do not need utf-8

@EgorGruzdev
Copy link
Author

EgorGruzdev commented Oct 26, 2017

Or:

    /**
     * @return string
     */
    public function toXml() {
        $mapper = new XmlModelMapper();
        return $mapper->unmap($this);
    }

replace

    /**
     * @return string
     */
    public function toXml() {
        $mapper = new XmlModelMapper();
        return mb_convert_encoding($mapper->unmap($this), 'UTF-8', 'HTML-ENTITIES');
    }

@runz0rd
Copy link
Owner

runz0rd commented Oct 26, 2017

I may have a solution for this, let me check and get back to you.

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

No branches or pull requests

2 participants