Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9216465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:25:23+00:00 2026-06-18T02:25:23+00:00

First item <item> <title>…</title> <link>…</link> <guid>…</guid> <description>…</description> <pubDate>Thu, 31 Jan 2013 13:46:24 +0530</pubDate> </item>

  • 0

First item

<item>
<title>...</title>
<link>...</link>
<guid>...</guid>
<description>...</description>
<pubDate>Thu, 31 Jan 2013 13:46:24 +0530</pubDate>
</item>

Second item

<item>
<title>...</title>
<link>...</link>
<guid>...</guid>
<description>...</description>
<enclosure url="http://entertainment.oneindia.in/img/2013/01/31-race-2-6-day-collection.jpg" type="image/jpeg" length="202500"/>
<pubDate>Thu, 31 Jan 2013 10:36:35 +0530</pubDate>
</item>

“item” are the elements in a xml. First item don’t have “enclosure” tag, while in second item, it is available. My DOMParser throws NPE, because the tag “enclosure” for which, it is searching is not available in first “item”. How can I skip when preferred tag is not available?

My code with NPE is

objItem.setImage(getAttributeVal("enclosure", eElement));



public String getAttributeVal(String tag,Element eElement)
    {

        String imgUrl=eElement.getElementsByTagName(tag).item(0).getAttributes().getNamedItem("url").getNodeValue();
        return imgUrl;

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:25:25+00:00Added an answer on June 18, 2026 at 2:25 am

    You current code does not allow for missing instances. It always assumes that it is present.

    Modify your function to check if it exists.

    public String getAttributeVal(String tag,Element eElement)
    {
        if (eElement.GetElementsByTagName(tag).Length > 0) // Or .Count > 0
        {
           String imgUrl=eElement.getElementsByTagName(tag).item(0).getAttributes().getNamedItem("url").getNodeValue();
           return imgUrl;
        }
    
        return ""; // Or null
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I passed string from controllerA (second item in tab bar) to controllerB (first item
With this LaTeX code: \begin{list} \item my first item title my first item content
Instead of: {foreach $rows as $row} <li class=item{if $row@first} item-first{elseif $row@last} item-last{/if}>{$row.title}</li> {/foreach} Is
How to put the first item on the DropDownList in blank ? In VB
I can select the first item in the div using $('.class:first') Now since I
When I click on the first item in the spinner, or the default one,
I want to find the first item in a sorted vector that has a
Say I want to take the first item of the lists '(4 3 1)
I would like to get the first item from a list matching a condition.
How to find out if site is the first item in history? This doesn't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.