goetas-webservices / xsd2php

Convert XSD into PHP classes and JMS serializer definitions
MIT License
234 stars 88 forks source link

Possible to prefix the root element while serializing? #5

Open fredericomartini opened 7 years ago

fredericomartini commented 7 years ago

While generating metadata files is possible to set namespace prefix to the root element? e.g:

myXmlElement: xml_root_name: "ds1:foobar" xml_root_namespace: "http://www.example"

will turn serialized:

<?xml version="1.0" encoding="UTF-8"?> <ds1:foobar xmlns:ds1="http://www.example"> </ds1:foobar>

goetas commented 7 years ago

Hi, this is not possible at the moment. I have solved it adding the prefix in the root name.

But it will be an interesting feature for the jms serializer, PR are welcome

On 12 Nov 2016 1:57 pm, "Frederico Martini" notifications@github.com wrote:

While generating metadata files is possible to set namespace prefix to the root element? e.g: myXmlElement: xml_root_name: "ds1:foobar" xml_root_namespace: "http://www.example"

will turn serialized: <?xml version="1.0" encoding="UTF-8"?>

/ds1:foobar — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/goetas-webservices/xsd2php/issues/5, or mute the thread https://github.com/notifications/unsubscribe-auth/AAvaJ3SyrZ2H_SdfWWFb8hu0nTklxNCrks5q9beggaJpZM4KwaVM .
goetas commented 7 years ago

Reading better your message, do not understand the problem. What you have suggested in your code snippet is exactly how is implemented now

fredericomartini commented 7 years ago

I can only set prefix name to xml_root_name in .yml files already generated, not based on config.yml e.g. I have the xsd above: https://gist.github.com/fredericomartini/481a4fd7774cde6e93b85cdb042604c8 When generate my metadata I would like my namespace seems like: xmlns:tipos="http://www.ginfes.com.br/tipos_v03.xsd" How as wrote on the 1th. And what is generated is: https://gist.github.com/fredericomartini/c2a25073750766c65ecb5bd99f3f9329

Default namespace generate is: xmlns:ns-13a1074f="http://www.ginfes.com.br/tipos_v03.xsd"

Better to understand now?

Thanks @goetas

goetas commented 7 years ago

ah, i see. this is a know limitation of the jms serializer, but https://github.com/schmittjoh/serializer/pull/644 is a fix for it.

planned to be resolved in 1.5 or 1.6 version of jms serializer

steve-rhodes commented 6 years ago

I have the same problem. I still don't know how to set the root_name. And I don't know how schmittjoh/serializer#644 is solving this?

All I get is a random generated string. For example: xml_root_name: 'ns-0a7b0155:ManifestMessage' Where is ns-0a7b0155: coming from? How can I set it myself?

thanks

goetas commented 6 years ago

any reason to have a specific prefix? for xml-sematics prefix should be almost irrelevant

steve-rhodes commented 6 years ago

Unfortunately our delivery house for Spotify rejected our xml's and said the root_name wasn't set as they need.

I understand that a quick fix would be to change the .yml manually, right?

I also need this added xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance” How can I do this?

The .yml looks like this:

App\Ci\NewReleaseMessage:
    xml_root_name: 'ns-61e1d5b4:NewReleaseMessage'
    xml_root_namespace: 'http://ddex.net/xml/2010/ern-main/32'

generating this:

<?xml version="1.0" encoding="UTF-8"?>
<ns-0a7b0155:ManifestMessage xmlns:ns-0a7b0155="http://ddex.net/xml/2011/echo/11" MessageVersionId="2010/ern-main/312">

But I need:

<echo:ManifestMessage xmlns:echo="http://ddex.net/xml/2011/echo/11"
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xsi:schemaLocation="http://ddex.net/xml/2011/echo/11 http://ddex.net/xml/2011/echo/11/echo.xsd"
                      MessageVersionId="2010/ern-main/312">

Any idea? Thanks again!

goetas commented 6 years ago

https://github.com/goetas-webservices/xsd2php/blob/d7e40e370cd930916fd58e798a55265ac132444c/src/Jms/YamlConverter.php#L150 is the part of code to edit! PR are welcome!

pribeirojtm commented 4 years ago

Hello, is this issue still occuring? I'm having the same problem as reported in this post. Do we still have to hack xsd2php/src/Jms/YamlConverter.php:150 ?

$data["xml_root_name"] = "ns-" . substr(sha1($data["xml_root_namespace"]), 0, 8) . ":" . $data["xml_root_name"];

Or do we have now something to give what we want?

Thanks ?

goetas commented 4 years ago

This the part of code to edit! PR are welcome!