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

Request for a simple sample #51

Closed
rohithmeethal opened this issue Jan 24, 2018 · 2 comments
Closed

Request for a simple sample #51

rohithmeethal opened this issue Jan 24, 2018 · 2 comments

Comments

@rohithmeethal
Copy link

I just managed to convert xsd to classes, but now I am stuck how should I use the classes to convert xml to object. Can you you please add a simple example in docs.

@kernio
Copy link

kernio commented Jan 24, 2018

You can do something like this:

        $serializerBuilder = SerializerBuilder::create();
        $serializerBuilder->addMetadataDir(__DIR__ . '/../library/Xsd/metadata', 'Foo\Bar\Xsd');
        $serializerBuilder->configureHandlers(
            function (HandlerRegistryInterface $handler) use ($serializerBuilder) {
                $serializerBuilder->addDefaultHandlers();
                $handler->registerSubscribingHandler(new BaseTypesHandler()); // XMLSchema List handling
                $handler->registerSubscribingHandler(new XmlSchemaDateHandler()); // XMLSchema date handling
            }
        );

        $barObject = new Bar();
        $barObject->setValue(new Value('test-value));

        $serializer = $serializerBuilder->build();
        $newXml = $serializer->serialize($barObject, 'xml');

@rohithmeethal
Copy link
Author

Thanks, I was expecting somthing like auto parsing of xml to classes, but only today I remembered I just have to map the xml to root class, rest will be taken care by the converter.
I am trying that way now.

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