N
N
Ninazu2016-02-19 18:52:12
PHP
Ninazu, 2016-02-19 18:52:12

How to output XML with JMSSerializer without header?

Actually, the body itself is needed, without
<?xml version="1.0" encoding="UTF-8"?>
I do initialization like this.

$namingStrategy = new \JMS\Serializer\Naming\IdenticalPropertyNamingStrategy();
$annotationStrategy = new \JMS\Serializer\Naming\SerializedNameAnnotationStrategy($namingStrategy);
$serializer = \JMS\Serializer\SerializerBuilder::create()
  ->setPropertyNamingStrategy($annotationStrategy)
  ->build();

AnnotationRegistry::registerAutoloadNamespace('JMS\Serializer\Annotation', __DIR__ . '/../vendor/jms/serializer/src');

$serializedContent = \JMS\Serializer\SerializationContext::create();
$xml = $serializer->serialize($object, 'xml', $serializedContent);

Related questions.
  • How to change the encoding and version in the header?
  • Is it possible to return the result as an object instead of a string?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question