5

如何为 @XmlList 元素定义 cdata 和命名空间?

例如,如果我需要从示例http://jmsyst.com/libs/serializer/master/reference/annotations#xmlnamespace修改 BlogPost以拥有多个作者:

use JMS\Serializer\Annotation as JMS;

/**
 * @JMS\XmlNamespace(uri="http://example.com/namespace")
 * @JMS\XmlNamespace(uri="http://www.w3.org/2005/Atom", prefix="atom")
 * @JMS\XmlRoot("blog-post")
 */
class BlogPost
{
    /**
     * @JMS\Type("ArrayCollection<JMS\Serializer\Tests\Fixtures\Author>")
     * @JMS\XmlList(inline = true, entry="author")
     *
     * replaced XmlElement(namespace="http://www.w3.org/2005/Atom") with XmlList
     */
    private $author;
}

与序列化的 xml 类似:

<?xml version="1.0" encoding="UTF-8"?>
<blog-post xmlns="http://example.com/namespace" xmlns:atom="http://www.w3.org/2005/Atom">
    <atom:author>
        <full_name>Foo Bar></full_name>
    </atom:author>
    <atom:author>
        <full_name>Baz Qux></full_name>
    </atom:author>
</blog>

对于单个@XmlElement,cdata 和命名空间都可以正常工作,但@XmlList@XmlCollection没有这样的东西。

任何线索我应该在哪里为列表中的元素添加注释?

4

0 回答 0