Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取rel=";候补;使用java DocumentBuilder从xml提要获取href值_Java_Android_Xml - Fatal编程技术网

获取rel=";候补;使用java DocumentBuilder从xml提要获取href值

获取rel=";候补;使用java DocumentBuilder从xml提要获取href值,java,android,xml,Java,Android,Xml,需要您的帮助。请确保这对于体验Xmls的开发人员来说是一个愚蠢的问题 我正在尝试阅读以下提要: 使用InputStream和Document解析xml like:documentdom=db.parse(in) 以下是入口元素的外观: <entry> <id>tag:blogger.com,1999:blog-7793856.post-7139617615025474381</id> <published>2011-03-21T10:42:00.

需要您的帮助。请确保这对于体验Xmls的开发人员来说是一个愚蠢的问题

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

使用InputStream和Document解析xml

like:documentdom=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>

标签:blogger.com,1999:blog-7793856.post-7139617615025474381
2011-03-21T10:42:00.000-07:00
2011-03-21T10:44:11.297-07:00
它叫食品储藏室
好。世界大事似乎并没有减少麻烦,所以我们还是回到正题上来吧。是吗?上周,我说我想告诉你一个新项目,现在我仍然想告诉你。这是一个从德兰西发展而来的项目,但它是一个全新的东西:一个由我们的两个朋友布兰迪·亨德森和奥莱娅·兰德领导的企业。从技术上讲,布兰登是第三位合伙人,但这个婴儿真的是img src=”http://feeds.feedburner.com/~r/Orangette/~4/X6Tm2_LpxYI“height=“1”width=“1”/
莫莉
http://www.blogger.com/profile/01493708300940204826
cheeseandchocolate@gmail.com
163
除了只得到一个rel和take是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" />


浪费很多时间想把他弄出来。但是娜达,会很高兴得到任何线索的。

好的,找到我自己的解决方案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;    
             }
公共静态字符串getTagValueWithMultiItem(元素eElement){
字符串returnVal=“”;
节点烯醇化物;
int NumOFItem=eElement.getElementsByTagName(“链接”).getLength();
对于(int y=0;y
任何进步都将得到祝福