我想讀這個xml文件,我只對Item Name =「PubDate」屬性感興趣。得到特定的屬性xml java
<eSummaryResult>
<DocSum>
<Id>23373820</Id>
<Item Name="PubDate" Type="Date">2013 Mar</Item>
<Item Name="EPubDate" Type="Date">2013 Feb 1</Item>
<Item Name="Source" Type="String">Expert Opin Emerg Drugs</Item>
<Item Name="AuthorList" Type="List">...</Item>
<Item Name="LastAuthor" Type="String">Rascol O</Item>
<Item Name="Title" Type="String">...</Item>
<Item Name="Volume" Type="String">18</Item>
<Item Name="Issue" Type="String">1</Item>
<Item Name="Pages" Type="String">39-53</Item>
<Item Name="LangList" Type="List">...</Item>
<Item Name="NlmUniqueID" Type="String">101135662</Item>
<Item Name="ISSN" Type="String">1472-8214</Item>
<Item Name="ESSN" Type="String">1744-7623</Item>
<Item Name="PubTypeList" Type="List">...</Item>
<Item Name="RecordStatus" Type="String">PubMed - indexed for MEDLINE</Item>
<Item Name="PubStatus" Type="String">ppublish+epublish</Item>
<Item Name="ArticleIds" Type="List">...</Item>
<Item Name="DOI" Type="String">10.1517/14728214.2013.766168</Item>
<Item Name="History" Type="List">...</Item>
<Item Name="References" Type="List"/>
<Item Name="HasAbstract" Type="Integer">1</Item>
<Item Name="PmcRefCount" Type="Integer">2</Item>
<Item Name="FullJournalName" Type="String">Expert opinion on emerging drugs</Item>
<Item Name="ELocationID" Type="String">doi: 10.1517/14728214.2013.766168</Item>
<Item Name="SO" Type="String">2013 Mar;18(1):39-53</Item>
</DocSum>
</eSummaryResult>
當我的程序經過下面的代碼
DocumentBuilderFactory dbPub = DocumentBuilderFactory.newInstance();
DocumentBuilder db2 = dbPub.newDocumentBuilder();
url1 = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id=23373820";
Document docPmid = db2.parse(new URL(url1).openStream());
NodeList nl = docPmid.getElementsByTagName("Item");
if(nl !=null && nl.getLength() > 0)
{
for (int y = 0; y < nl.getLength(); y++)
{
Element el = (org.w3c.dom.Element) nl.item(y);
if (el.hasAttribute("Name") && el.getAttribute("Name").equals("PubDate"))
{
String pubDate = el.getAttribute("Name");
System.out.println("PubDate :"+pubDate);
}
}
}
越來越pubdate的相反的:2013三月 我得到發佈時間:pubdate的
請[編輯您的文章](https://stackoverflow.com/posts/35261456/edit)幷包括整個XML文件。 – RAnders00
你想要什麼'String pubDate = el.getAttribute(「Name」);'會做什麼?你想要別的我想說的;-) – Betlista
你需要閱讀那個元素的內容,而不是它的一個屬性。 – Matthew