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

  • Home
  • SEARCH
  • 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 8173067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:59:57+00:00 2026-06-06T21:59:57+00:00

I am trying to print the attributes values for following xml file: <data/> <request/>

  • 0

I am trying to print the attributes values for following xml file:

<data/>
       <request/>
              <type>City</type>
              <query>Jaipur, India</query>
          </request>
       <current_condition/>
              <observation_time>06:37 AM</observation_time>
              <temp_C>40</temp_C>
              <temp_F>104</temp_F>
              <weatherCode>113</weatherCode>
              <weatherIconUrl/>
              <weatherDesc/>
              <windspeedMiles>8</windspeedMiles>
              <windspeedKmph>13</windspeedKmph>
              <winddirDegree>280</winddirDegree>
              <winddir16Point>W</winddir16Point>
              <precipMM>0.0</precipMM>
              <humidity>34</humidity>
              <visibility>4</visibility>
              <pressure>997</pressure>
              <cloudcover>25</cloudcover>
          </current_condition>
       <weather/>
              <date>2012-07-03</date>
              <tempMaxC>46</tempMaxC>
              <tempMaxF>115</tempMaxF>
              <tempMinC>36</tempMinC>
              <tempMinF>97</tempMinF>
              <windspeedMiles>6</windspeedMiles>
              <windspeedKmph>9</windspeedKmph>
              <winddirection>N</winddirection>
              <winddir16Point>N</winddir16Point>
              <winddirDegree>7</winddirDegree>
              <weatherCode>113</weatherCode>
              <weatherIconUrl/>
              <weatherDesc/>
              <precipMM>0.0</precipMM>
          </weather>
       <weather/>
              <date>2012-07-04</date>
              <tempMaxC>46</tempMaxC>
              <tempMaxF>114</tempMaxF>
              <tempMinC>34</tempMinC>
              <tempMinF>94</tempMinF>
              <windspeedMiles>12</windspeedMiles>
              <windspeedKmph>20</windspeedKmph>
              <winddirection>NW</winddirection>
              <winddir16Point>NW</winddir16Point>
              <winddirDegree>319</winddirDegree>
              <weatherCode>113</weatherCode>
              <weatherIconUrl/>
              <weatherDesc/>
              <precipMM>0.0</precipMM>
          </weather>
   </data>

Following is the java code which I am using to print the attribute values:

    public class WorldWeatherOnline {
        public static void main (String[] args) throws IOException, ParserConfigurationException, SAXException, TransformerException {
            URL url = new URL("http://free.worldweatheronline.com/feed/weather.ashx?q=jaipur,india&format=xml&num_of_days=2&key=c5774216f9120304120207");
            URLConnection conn = url.openConnection();

            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document doc = builder.parse(conn.getInputStream());
            printElementAttributes(doc);
    }
static void printElementAttributes(Document doc)
    {
       NodeList nl = doc.getElementsByTagName("*");
       Element e;
       Node n;
       NamedNodeMap nnm;

       String attrname;
       String attrval;
       int i, len;

       len = nl.getLength();
       for (int j=0; j < len; j++)
       {
          e = (Element)nl.item(j);
          System.out.println(e.getTagName() + ":");
          System.out.println("check-1");

          nnm = e.getAttributes();
          if (nnm != null)
          {
             for (i=0; i<nnm.getLength(); i++)
             {
                System.out.println("check");
                n = nnm.item(i);
                attrname = n.getNodeName();
                attrval = n.getNodeValue();
                System.out.print(" " + attrname + " = " + attrval);
             }
          }
          System.out.println();
       }
    }

Basically my NamedNodeMap nnm is null, so it isn’t going inside the loop. I have used these imports:

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
  • 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-06T22:00:01+00:00Added an answer on June 6, 2026 at 10:00 pm

    Your XML doesn’t have any attributes. It just has elements with text contents. An element with an attribute looks like this:

    <element attributeName="attribute value" />
    

    If you want to use your current XML, you’ll need to get the text values of the elements instead, and presumably store those against the element name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying print Excel file data on a page. To do it i used
I'm trying to use the following snippet inside my tag file: <%@ attribute name=content
I'm trying to open/load an XML file specified in an Excel worksheet in the
I am trying to read attributes from an XML stream. Here is an example
I'm trying to print out an attribute value with the following code: ArrayList arrayList=new
I am trying to import a XML file via API into my php script
Im trying to print the realtime output based on user input for a search.
I'm trying to print a number of '+' characters followed by a number of
I'm trying to print a large string to alivepdf. I'm splitting the string by
I'm trying to print out a list of products on a page. This is

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.