首页 > 解决方案 > JMS 序列化程序在根元素中设置自定义命名空间名称

问题描述

想象一下,我想xsi:schemaLocation在根目录中有命名空间和属性:

<root xsi:schemaLocation="url">...</root>

如何在 Symfony 4 的 JMS/Serializer 中做到这一点?

我有这个类,我希望在序列化时在其根元素上具有此属性,请参阅类片段:

/**
 * @XmlRoot("partner")
 * @XmlNamespace(uri="http://www.w3.org/2001/XMLSchema-instance", prefix="xsi")
 */
class PartnerInfo implements RequestDtoInterface
{

仅供参考,我成功地@XmlNamespace在类上使用注释来创建xmlns:xsi属性。问题是使用@XmlNamespace命名空间属性名称总是以xmlns. 但我只想要xsi:schemaLocation.

将它传递给序列化程序时,也许可以使用SerializationContext对象和类来完成它?Metadata但是我尝试使用它时没有成功...

标签: phpxmlsymfony4jmsserializerbundlejms-serializer

解决方案


推荐阅读