Java 获取字符串<;图像>;带有RSS项getValue的标记-Android
如何使用getValue获取Java 获取字符串<;图像>;带有RSS项getValue的标记-Android,java,android,rss,Java,Android,Rss,如何使用getValue获取标记中的字符串?https://i2.cnnturk.com/i/cnnturk/75/720x490/5e6f7a9a70380e0cc8f49313 我需要https://i2.cnnturk.com/i/cnnturk/75/720x490/5e6f7a9a70380e0cc8f49313作为值 我能够显示图像,如果它是,并且需要显示 还有没有办法将RSS发布日期GMT格式化为GMT+3?我需要显示为不同的时区 RSS项目: <item> <g
标记中的字符串?https://i2.cnnturk.com/i/cnnturk/75/720x490/5e6f7a9a70380e0cc8f49313
我需要https://i2.cnnturk.com/i/cnnturk/75/720x490/5e6f7a9a70380e0cc8f49313
作为值
我能够显示图像,如果它是
,并且需要显示
还有没有办法将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>
_完整代码
@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);
}
}
}
您可以尝试使用正则表达式\(.*)\
匹配相应的字符。它可以匹配所有图像标签的内容
public static void main(String[] args){
String s="<image>https://x.com/image.jpg</image>"
+ "<image>https://x.com/image1.jpg</image>"
+ "<image>https://x.com/image2.jpg</image>";
Pattern p = Pattern.compile("\\<(\\Qimage\\E)\\>(.*?)\\<\\/\\1\\>");
Matcher m = p.matcher(s);
while(m.find()){
System.out.println(m.group(2));
}
}
publicstaticvoidmain(字符串[]args){
字符串s=”https://x.com/image.jpg"
+ "https://x.com/image1.jpg"
+ "https://x.com/image2.jpg";
Pattern p=Pattern.compile(“\\(.*?\”);
匹配器m=匹配器p;
while(m.find()){
系统输出println(m.group(2));
}
}
更新:我刚刚更新了代码。对不起,我以前写错了
如果不想使用正则表达式
int record = 0;
while(record!=-1){
int a = qName.indexOf("<image>",record);
if(a==-1){
break;
}
int b = qName.indexOf("</image>",a);
String url=qName.substring(a+7,b+8);
System.out.println(url);
int记录=0;
while(记录!=-1){
inta=qName.indexOf(“,记录);
如果(a==-1){
打破
}
intb=qName.indexOf(“,a);
字符串url=qName.substring(a+7,b+8);
System.out.println(url);
}字符串集=”https://x.com/a.jpg";
字符串sete2=sete.replace(“,”);
这不合适。它还需要两个图书馆。我只需要无限rss回收视图循环中的1个标记的内部。来源:https://x.com/image.jpg
需要:https://x.com/image.jpg
@tosunkaya我刚刚更新了代码。请再试一次:代替这些。当我使用替换方法时,我得到了空白图像。也许我必须把
,/
改成unicode或者别的什么?我太接近了。qName是我的完整字符串<代码>qName.replace(“,”)代码>qName.replace(“,”)
@tosunkaya如果不想使用正则表达式,可以使用indexof方法。定位和,然后计算它们之间的距离,然后使用String.substring(index,index)方法剪切字符串。@tosunkaya我刚刚更新了不使用正则表达式的代码,我在手机上写的,可能有书写错误,请更正。
int record = 0;
while(record!=-1){
int a = qName.indexOf("<image>",record);
if(a==-1){
break;
}
int b = qName.indexOf("</image>",a);
String url=qName.substring(a+7,b+8);
System.out.println(url);
String sete = "<image>https://x.com/a.jpg</image>";
String sete2 = sete.replace("<image>", "");