rss 格式不正确(无效令牌)-ReactJS
rss not well-formed (invalid token) - ReactJS
XML parsing error: <unknown>:16:32: not well-formed (invalid token) [help]
<itunes:category text="Society & Culture">
我不知道如何解决这个错误。你看,我将所有节目都存储在 mongodb 中,类别由 Apple 设定,我们需要属于的类别是社会与文化——因为他们似乎不仅有娱乐类别。
我想知道如何让这行代码在显示 & simple 时不被阻塞。
'\n<itunes:category text="'+show.category+'">';
完整代码
router.get('/shows/:id', (req, res) => {
var url = req.params.id;
/*var obj = {
items: [{
name: url,
_id: 1
}, {
name: 'two',
_id: 2
}, {
name: 'three',
_id: 3
}],
blah: 'http://www.google.com',
when: new Date(),
boolz: true,
nullz: null
};
console.log(serializer.render(obj));*/
var ep ='';
var query = {};
var epi='';
query['url']=url;
console.log(url);
ShowModel.findOne(query).exec(function(err, show) {
if (!err){
var q = {}
q['show_id']=show._id;
EpisodeModel.find(q).sort('-pubDate').exec(function(er, a) {
if (!er){
// console.log(a);
/*{a.map(a => (
ep += '\n<item>'+
'\n<title>'+a.title+'</title>'+
'\n<itunes:summary>'+a.summary+'</itunes:summary>'+
'\n<description>'+a.description+'</description>'+
'\n<link>'+a.link+'</link>'+
'\n<enclosure url="'+a.enclosureurl+'" type="audio/mpeg"></enclosure>'+
'\n<pubDate>Thu, 21 Dec 2016 16:01:07 +0000</pubDate>'+
'\n<itunes:author>Author Name</itunes:author>'+
'\n<itunes:duration>00:32:16</itunes:duration>'+
'\n<itunes:explicit>no</itunes:explicit>'+
'\n<guid>http://example.com/podcast-1</guid>'+
'\n</item>'
))}*/
for(var k in a) {
// console.log(a[k].title);
ep+= '\n<item>'+
'\n<title>'+a[k].title+'</title>'+
'\n<itunes:summary>'+a[k].summary+'</itunes:summary>'+
'\n<description>'+a[k].description+'</description>'+
'\n<link>'+a[k].link+'</link>'+
'\n<enclosure url="https://dts.podtrac.com/redirect.mp3/'+a[k].enclosureurl+'" length="'+a[k].enclosurebyts+'" type="audio/mpeg"></enclosure>'+
'\n<pubDate>'+sdate(a[k].pubDate)+'</pubDate>'+
'\n<itunes:author>'+a[k].author+'</itunes:author>'+
'\n<itunes:episodeType>full</itunes:episodeType>'+
'\n<itunes:season>'+a[k].season+'</itunes:season>';
if(a[k].episode_no) ep+='\n<itunes:episode>'+a[k].episode_no+'</itunes:episode>';
ep+='\n<itunes:duration>'+a[k].duration+'</itunes:duration>'+
'\n<itunes:explicit>'+a[k].explicit+'</itunes:explicit>'+
'\n<guid>'+a[k].link+'</guid>'+
'\n</item>'
}
}else{throw er;}
// console.log(ep);
if(show.subcategory){var subcategory = '<itunes:category text="'+show.subcategory+'"/>';}
var feed = '<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" version="2.0">'+
'\n<channel>'+
'\n<title>'+show.title+'</title>'+
'\n<link>'+show.link+'</link>'+
'\n<language>en-us</language>'+
'\n<itunes:subtitle>'+show.subtitle+'</itunes:subtitle>'+
'\n<itunes:author>Radio Media PTY LTD</itunes:author>'+
'\n<itunes:summary>'+show.summary+'</itunes:summary>'+
'\n<description>'+show.description+'</description>'+
'\n<itunes:owner>'+
'\n<itunes:name>Radio Media PTY LTD</itunes:name>'+
'\n<itunes:email>podcast@radiomedia.com.au</itunes:email>'+
'\n</itunes:owner>'+
'\n<itunes:explicit>'+show.explicit+'</itunes:explicit>'+
'\n<itunes:image href="'+show.icon+'" />'+
'\n<itunes:category text="'+show.category+'">';
if(subcategory) feed += subcategory;
feed +='\n</itunes:category>'+
'\n<atom:link href="http://api.radiomedia.com.au/api-access/shows/'+url+'" rel="self" type="application/rss+xml" />';
feed += ep;
feed += '\n</channel>'+
'\n</rss>';
console.log(ep);
res.header('Content-Type', 'text/xml');
res.send(feed);
//process.exit();
}); } else { throw err; }
});
来自 XML Definition:
The ampersand character (&) and the left angle bracket (<) MUST NOT appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they MUST be escaped.
XML parsing error: <unknown>:16:32: not well-formed (invalid token) [help]
<itunes:category text="Society & Culture">
我不知道如何解决这个错误。你看,我将所有节目都存储在 mongodb 中,类别由 Apple 设定,我们需要属于的类别是社会与文化——因为他们似乎不仅有娱乐类别。
我想知道如何让这行代码在显示 & simple 时不被阻塞。
'\n<itunes:category text="'+show.category+'">';
完整代码
router.get('/shows/:id', (req, res) => {
var url = req.params.id;
/*var obj = {
items: [{
name: url,
_id: 1
}, {
name: 'two',
_id: 2
}, {
name: 'three',
_id: 3
}],
blah: 'http://www.google.com',
when: new Date(),
boolz: true,
nullz: null
};
console.log(serializer.render(obj));*/
var ep ='';
var query = {};
var epi='';
query['url']=url;
console.log(url);
ShowModel.findOne(query).exec(function(err, show) {
if (!err){
var q = {}
q['show_id']=show._id;
EpisodeModel.find(q).sort('-pubDate').exec(function(er, a) {
if (!er){
// console.log(a);
/*{a.map(a => (
ep += '\n<item>'+
'\n<title>'+a.title+'</title>'+
'\n<itunes:summary>'+a.summary+'</itunes:summary>'+
'\n<description>'+a.description+'</description>'+
'\n<link>'+a.link+'</link>'+
'\n<enclosure url="'+a.enclosureurl+'" type="audio/mpeg"></enclosure>'+
'\n<pubDate>Thu, 21 Dec 2016 16:01:07 +0000</pubDate>'+
'\n<itunes:author>Author Name</itunes:author>'+
'\n<itunes:duration>00:32:16</itunes:duration>'+
'\n<itunes:explicit>no</itunes:explicit>'+
'\n<guid>http://example.com/podcast-1</guid>'+
'\n</item>'
))}*/
for(var k in a) {
// console.log(a[k].title);
ep+= '\n<item>'+
'\n<title>'+a[k].title+'</title>'+
'\n<itunes:summary>'+a[k].summary+'</itunes:summary>'+
'\n<description>'+a[k].description+'</description>'+
'\n<link>'+a[k].link+'</link>'+
'\n<enclosure url="https://dts.podtrac.com/redirect.mp3/'+a[k].enclosureurl+'" length="'+a[k].enclosurebyts+'" type="audio/mpeg"></enclosure>'+
'\n<pubDate>'+sdate(a[k].pubDate)+'</pubDate>'+
'\n<itunes:author>'+a[k].author+'</itunes:author>'+
'\n<itunes:episodeType>full</itunes:episodeType>'+
'\n<itunes:season>'+a[k].season+'</itunes:season>';
if(a[k].episode_no) ep+='\n<itunes:episode>'+a[k].episode_no+'</itunes:episode>';
ep+='\n<itunes:duration>'+a[k].duration+'</itunes:duration>'+
'\n<itunes:explicit>'+a[k].explicit+'</itunes:explicit>'+
'\n<guid>'+a[k].link+'</guid>'+
'\n</item>'
}
}else{throw er;}
// console.log(ep);
if(show.subcategory){var subcategory = '<itunes:category text="'+show.subcategory+'"/>';}
var feed = '<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" version="2.0">'+
'\n<channel>'+
'\n<title>'+show.title+'</title>'+
'\n<link>'+show.link+'</link>'+
'\n<language>en-us</language>'+
'\n<itunes:subtitle>'+show.subtitle+'</itunes:subtitle>'+
'\n<itunes:author>Radio Media PTY LTD</itunes:author>'+
'\n<itunes:summary>'+show.summary+'</itunes:summary>'+
'\n<description>'+show.description+'</description>'+
'\n<itunes:owner>'+
'\n<itunes:name>Radio Media PTY LTD</itunes:name>'+
'\n<itunes:email>podcast@radiomedia.com.au</itunes:email>'+
'\n</itunes:owner>'+
'\n<itunes:explicit>'+show.explicit+'</itunes:explicit>'+
'\n<itunes:image href="'+show.icon+'" />'+
'\n<itunes:category text="'+show.category+'">';
if(subcategory) feed += subcategory;
feed +='\n</itunes:category>'+
'\n<atom:link href="http://api.radiomedia.com.au/api-access/shows/'+url+'" rel="self" type="application/rss+xml" />';
feed += ep;
feed += '\n</channel>'+
'\n</rss>';
console.log(ep);
res.header('Content-Type', 'text/xml');
res.send(feed);
//process.exit();
}); } else { throw err; }
});
来自 XML Definition:
The ampersand character (&) and the left angle bracket (<) MUST NOT appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they MUST be escaped.