简体   繁体   中英

Add XML prefix for the root element with Symfony XML serializer

I'm using symfony serializer in order to encode a class in XML:

        $serialized = $this->serializer->serialize(
        $content,
        'xml',
        [
            XmlEncoder::ROOT_NODE_NAME => 'dummy',
            XmlEncoder::REMOVE_EMPTY_TAGS => true,
            XmlEncoder::FORMAT_OUTPUT => true,
        ],
    );

This code generates a normal XML, but I want to add a prefix to the root element only. How can I do that?

I figured it out. I modified this line:

XmlEncoder::ROOT_NODE_NAME => 'p:dummy',

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM