java - 使用 RSS 项的 getValue获取标签中的字符串- Android
问题描述
如何<image>
使用 getValue 获取标签中的字符串?<image>https://i2.cnnturk.com/i/cnnturk/75/720x490/5e6f7a9a70380e0cc8f49313</image>
我需要https://i2.cnnturk.com/i/cnnturk/75/720x490/5e6f7a9a70380e0cc8f49313
作为价值。
我可以显示图像,如果它<media:content url=""/>
<media:thumbnail url=""/>
<enclosure url=""/>
也需要显示的话<image>
。
还有什么方法可以将 RSS 发布日期 GMT 格式化为 GMT+3?我需要显示为不同的时区。
RSS 项目:
<item>
<guid isPermaLink="true">5e6f79fe70380e0cc8f49311</guid>
<link>https://www.cnnturk.com/turkiye/istanbul-barosundan-koronaviruse-karsi-avukatlara-acil-mesaj</link>
<title>
<![CDATA[ İstanbul Barosu'ndan koronavirüs'e karşı avukatlara 'acil' mesaj ]]>
</title>
<description>
<![CDATA[ İstanbul Barosu Başkanlığı Koronavirüs nedeniyle "Acil" başlığıyla üye avukatlara mesaj attı. Mesajda duruşmaların 14 Nisan 2020 tarihinden sonra görüleceği, avukatlara bu süreçte dava açılmaması önerildi. ]]>
</description>
<pubDate>Mon, 16 Mar 2020 16:09:49 GMT</pubDate>
<atom:link href="https://www.cnnturk.com/turkiye/istanbul-barosundan-koronaviruse-karsi-avukatlara-acil-mesaj"/>
<image>https://i2.cnnturk.com/i/cnnturk/75/720x490/5e6f7a9a70380e0cc8f49313</image>
</item>
这是安卓代码:
需要帮助
else if (qName.equalsIgnoreCase("image")) { //NEW ADDITION
currentState = State.media;
String attrValue = attributes.getValue("WHAT");
item.setThumburl(attrValue);
_完整代码
@Override
public void startElement(final String uri, final String localName,
final String qName, final Attributes attributes)
throws SAXException {
currentState = State.unknown;
tagContent = new StringBuilder();
if (localName.equalsIgnoreCase("item") || localName.equalsIgnoreCase("entry")) {
itemFound = true;
item = new RSSItem();
currentState = State.unknown;
} else if (qName.equalsIgnoreCase("title")) {
currentState = State.title;
} else if (qName.equalsIgnoreCase("description") || qName.equalsIgnoreCase("content:encoded") || qName.equalsIgnoreCase("content")) {
currentState = State.description;
} else if (qName.equalsIgnoreCase("link") || qName.equalsIgnoreCase("origLink")) {
currentState = State.link;
} else if (qName.equalsIgnoreCase("pubdate") || qName.equalsIgnoreCase("published")) {
currentState = State.pubdate;
} else if (qName.equalsIgnoreCase("image")) { //NEW ADDITION
currentState = State.media;
String attrValue = attributes.getValue("WHAT");
item.setThumburl(attrValue);
} else if (qName.equalsIgnoreCase("media:thumbnail")) {
currentState = State.media;
String attrValue = attributes.getValue("url");
item.setThumburl(attrValue);
} else if (qName.equalsIgnoreCase("media:content")){
currentState = State.media;
String attrValue = attributes.getValue("url");
if (attributes.getValue("type") == null || attributes == null){
return;
} else if (attributes.getValue("type").startsWith("image")){
item.setThumburl(attrValue);
} else if (attributes.getValue("type").startsWith("video")){
item.setVideourl(attrValue);
} else if (attributes.getValue("type").startsWith("audio")){
item.setAudiourl(attrValue);
}
} else if (qName.equalsIgnoreCase("enclosure")){
currentState = State.media;
String attrValue = attributes.getValue("url");
if (attributes == null || attributes.getValue("type") == null) {
return;
} else if (attributes.getValue("type").startsWith("image")){
item.setThumburl(attrValue);
} else if (attributes.getValue("type").startsWith("video")){
item.setVideourl(attrValue);
} else if (attributes.getValue("type").startsWith("audio")){
item.setAudiourl(attrValue);
}
}
}
解决方案
String sete = "<image>https://x.com/a.jpg</image>";
String sete2 = sete.replace("<image>", "");
推荐阅读
- linux - 在从 windows 服务器到 linux 服务器进行 sftp 时,文件中出现了像“��”这样的垃圾字符。如何预防或消除这些?
- c++ - 从不断更新的向量中读取
- java - Java中如何将字符串的第一个字符放在字符串的最后一个位置?
- powershell - 使用应用程序 ID 自动化无缝 SSO kerberos 解密密钥翻转
- javascript - Java servlet 不适用于 AWS Java SDK
- mit-scheme - 在 mit-scheme + scmutils 中创建 X11 框架
- javascript - AngularJs与兄弟组件通信不起作用
- mongodb - 带有嵌套对象的猫鼬聚合 $group
- python - 在 Python 中,如何将变量的值分配给字典,其中变量将不断获取每次迭代的值
- javascript - 如何用我的反应导航解决依赖问题