私はnodejsでcheerioを使用して、いくつかのRSSフィードを解析しています。すべてのアイテムを取得して配列に入れています。私は 3 つのテスト フィードを使用しています。それらのすべてに、「item」要素ごとに「description」子要素があります。フィードの 1 つで、「説明」全体が CDATA としてラップされており、その値を取得できません。短縮されたコード スニペットを次に示します。
//Open the xml document with cheerio
$ = cheerio.load(arrXmlDocs[i],{ ignoreWhitespace : true, xmlMode : true});
//Loop through every item
$('item').each(function(i, xmlItem){
//array to hold each item being converted into an array
var tempArray = [];
//Loop through each child of <item>
$(xmlItem).children().each(function(i, xmlItem){
//Get the name
tempArray[$(this)[0].name] = $(this).text();
}
}
予想どおり、CDATA を持たない 2 つの RSS フィードは、このような配列を与えてくれます
[
[
name: 'name of episode',
description:'description of episode',
pubdate: 'published date'
],
[
name: 'name of episode',
description:'description of episode',
pubdate: 'published date'
]
]
CDATA の説明を含むフィードは次のようになります
[
name: 'name of episode',
pubdate: 'published date'
],
だから私の質問は:なぜcheerioはCDATAにラップされた値を返さないのですか/どうすればそれらの値を返すことができますか.