get specific attribute xml java -
i trying read xml file, , interested in item name="pubdate" attribute.
<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 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>
when programs goes through following code
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) { (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); } } }
instead of getting pubdate :2013 mar pubdate :pubdate
probably overlooked...
you using same in if
if (el.hasattribute("name") && el.getattribute("name").equals("pubdate"))
and later same printing:
string pubdate = el.getattribute("name"); system.out.println("pubdate :"+pubdate);
which not want do, want read content, not attribute value...
Comments
Post a Comment