gpt4 book ai didi

java - 使用 java DocumentBuilder 从 xml feed 获取 rel ="alternate"href 值

转载 作者:行者123 更新时间:2023-12-01 15:53:55 25 4
gpt4 key购买 nike

需要您的帮助..对于经验丰富的 Xmls 开发人员来说,这肯定是一个愚蠢的问题

我正在尝试阅读以下提要:

http://feeds.feedburner.com/Orangette

使用InputStream和Document来解析xml

如:文档 dom = db.parse(in);

这就是条目元素的样子:

<entry>
<id>tag:blogger.com,1999:blog-7793856.post-7139617615025474381</id>
<published>2011-03-21T10:42:00.000-07:00</published>
<updated>2011-03-21T10:44:11.297-07:00</updated>
<title type="text">It's called the Pantry</title>
<summary type="html">Well. World events don’t seem to get any less troubling, so we might as well get back to business. Yes?Last week, I said that I wanted to tell you about a new project, and I still do. It’s a project that grows out of Delancey, but it’s a whole new thing: a business headed up by two of our friends, Brandi Henderson and Olaiya Land. Brandon is technically the third partner, but this baby really &lt;img src="http://feeds.feedburner.com/~r/Orangette/~4/X6Tm2_LpxYI" height="1" width="1"/&gt;</summary>
<link rel="replies" type="application/atom+xml" href="http://orangette.blogspot.com/feeds/7139617615025474381/comments/default" title="Post Comments" />
<link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=7793856&amp;postID=7139617615025474381" title="163 Comments" />
<link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/7793856/posts/default/7139617615025474381" />
<link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/7793856/posts/default/7139617615025474381" />
<link rel="alternate" type="text/html" href="http://orangette.blogspot.com/2011/03/its-called-pantry.html" title="It's called the Pantry" />
<author>
<name>Molly</name>
<uri>http://www.blogger.com/profile/01493708300940204826</uri>
<email>cheeseandchocolate@gmail.com</email>
<gd:extendedProperty xmlns:gd="http://schemas.google.com/g/2005" name="OpenSocialUserId" value="07818414465072164731" />
</author>
<media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-G2usp64xroc/TYaQ0wdcaUI/AAAAAAAAC_o/L4l6deIvm6U/s72-c/5544384475_858400a1f7_z.jpg" height="72" width="72" />
<thr:total>163</thr:total></entry>

除了只获取一个 rel 并采用 href 值外,一切正常

在本例中备用rel是相关的

<link rel="alternate" type="text/html" href="http://orangette.blogspot.com/2011/03/its-called pantry.html" title="It's called the Pantry" />

浪费了很多时间试图让他离开那里..但是nada,会很高兴得到任何线索..

最佳答案

好的,找到了我自己的解决方案,100% 确定有更干净的方法,但是......

因为我的应用程序支持低级别的 Android 平台,所以我无法使用 8 级 (2.2) 支持的 xpath

我的解决方案是:

 public static String getTagValueWithMultiItem(Element eElement){
String returnVal = "" ;
Node eNode ;
int NumOFItem = eElement.getElementsByTagName("link").getLength();
for (int y = 0; y < NumOFItem; y++) {
eNode = eElement.getElementsByTagName("link").item(y);
NamedNodeMap attributes = eNode.getAttributes();
for (int g = 0; g < attributes.getLength(); g++) {
Attr attribute = (Attr)attributes.item(g);
if(attribute.getNodeName().equals("rel")&&attribute.getNodeValue().equals("alternate"))
{
try {
returnVal =eNode.getAttributes().getNamedItem("href").getNodeValue();
}
catch (Exception e) {
returnVal = e.toString();
}
}
}
}
return returnVal;
}

任何改进都会受到祝福

关于java - 使用 java DocumentBuilder 从 xml feed 获取 rel ="alternate"href 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5452501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com