输出RSS源报错,Namespace prefix content on encoded is not defined

报错信息:Namespace prefix content on encoded is not defined

解决办法:定义命名空间在<rss>标签里添加属性“xmlns:content”

<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
package com.xxxx.model.dto.ad;

import com.xxxx.model.constant.RssConstants;
import lombok.Data;

import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.List;

/**
 * @author maomo
 * @version 3.5.0
 * @email [email protected]
 * @date 2022-05-18
 **/
@Data
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "rss")
public class RssDto {

    @XmlAttribute
    private String version = "2.0";

    @XmlElement(namespace="http://purl.org/rss/1.0/modules/content/")
    private String content ;

    @XmlElement(name = "channel")
    private List<Channel> channelList;

    @Data
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class Channel {

        private String title = "title";

        private String description = "description";

        private String link = "link";

        private String language = "en-us";

        private String lastBuildDate ;

        @XmlElement(name = "item")
        private List<Item> itemList;
    }

    @Data
    @XmlAccessorType(XmlAccessType.FIELD)
    public static class Item {

        private String title;

        private String link;

        private String guid;

        private String pubDate;

        private String author;

        private String description;

        @XmlJavaTypeAdapter(value = CdataAdapter.class)
        @XmlElement(name = "content:encoded")
        private String contentEncoded;
    }

}

猜你喜欢

转载自blog.csdn.net/qq_37928038/article/details/124922123
今日推荐