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