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 9169519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:53:25+00:00 2026-06-17T15:53:25+00:00

below is my xml code in which i need to display each node’s attributes

  • 0

below is my xml code in which i need to display each node’s attributes i.e name and type.

xml :

<node label="Tree Data">
<node name="View" type="Page">
<node name="Organisational Structure" type="Page"/>
<node name="Experience" type="Page"/>
<node name="Expertise" type="Language">
<node name="Flex" type="Language"/>
<node name="Android" type="Language"/>
<node name="Java" type="Language"/>
</node>
<node name="Project" type="Project">
<node name="Sabre" type="Project"/>
<node name="Android Project" type="Project"/>
<node name="Media Framework" type="Project"/>
<node name="CCD" type="Project"/>
<node name="Redbus" type="Project"/>
<node name="India Today" type="Project"/>
<node name="Money Control" type="Project"/>
</node>
</node>
<node name="Reorganize" type="Action"/>
<node name="Add New Employee" type="Action">
<node name="Dir" type="Page"/>
<node name="P.M" type="Page"/>
<node name="S.E" type="Page"/>
<node name="JUN" type="Page"/>
<node name="EMP" type="Page"/>
</node>
<node name="Add Project Members" type="Action"/>
</node>

i am getting the following output :

output:

01-23 17:13:26.047: I/System.out(3846): name : 
01-23 17:13:26.057: I/System.out(3846): type : 
01-23 17:13:26.057: I/System.out(3846): name : View
01-23 17:13:26.077: I/System.out(3846): type : Page
01-23 17:13:26.077: I/System.out(3846): name : Organisational Structure
01-23 17:13:26.077: I/System.out(3846): type : Page
01-23 17:13:26.097: I/System.out(3846): name : Experience
01-23 17:13:26.097: I/System.out(3846): type : Page
01-23 17:13:26.097: I/System.out(3846): name : Expertise
01-23 17:13:26.097: I/System.out(3846): type : Language
01-23 17:13:26.097: I/System.out(3846): name : Flex
01-23 17:13:26.097: I/System.out(3846): type : Language
01-23 17:13:26.117: I/System.out(3846): name : Android
01-23 17:13:26.117: I/System.out(3846): type : Language
01-23 17:13:26.117: I/System.out(3846): name : Java
01-23 17:13:26.128: I/System.out(3846): type : Language
01-23 17:13:26.128: I/System.out(3846): name : Project
01-23 17:13:26.139: I/System.out(3846): type : Project
01-23 17:13:26.139: I/System.out(3846): name : Sabre
01-23 17:13:26.139: I/System.out(3846): type : Project
01-23 17:13:26.147: I/System.out(3846): name : Android Project
01-23 17:13:26.147: I/System.out(3846): type : Project
01-23 17:13:26.167: I/System.out(3846): name : Media Framework
01-23 17:13:26.167: I/System.out(3846): type : Project
01-23 17:13:26.167: I/System.out(3846): name : CCD
01-23 17:13:26.167: I/System.out(3846): type : Project
01-23 17:13:26.167: I/System.out(3846): name : Redbus
01-23 17:13:26.167: I/System.out(3846): type : Project
01-23 17:13:26.167: I/System.out(3846): name : India Today
01-23 17:13:26.177: I/System.out(3846): type : Project
01-23 17:13:26.187: I/System.out(3846): name : Money Control
01-23 17:13:26.187: I/System.out(3846): type : Project
01-23 17:13:26.187: I/System.out(3846): name : Reorganize
01-23 17:13:26.187: I/System.out(3846): type : Action
01-23 17:13:26.187: I/System.out(3846): name : Add New Employee
01-23 17:13:26.187: I/System.out(3846): type : Action
01-23 17:13:26.197: I/System.out(3846): name : Dir
01-23 17:13:26.197: I/System.out(3846): type : Page
01-23 17:13:26.217: I/System.out(3846): name : P.M
01-23 17:13:26.217: I/System.out(3846): type : Page
01-23 17:13:26.217: I/System.out(3846): name : S.E
01-23 17:13:26.217: I/System.out(3846): type : Page
01-23 17:13:26.217: I/System.out(3846): name : JUN
01-23 17:13:26.217: I/System.out(3846): type : Page
01-23 17:13:26.228: I/System.out(3846): name : EMP
01-23 17:13:26.228: I/System.out(3846): type : Page
01-23 17:13:26.237: I/System.out(3846): name : Add Project Members
01-23 17:13:26.237: I/System.out(3846): type : Action

but i actually need the following output :

desired output :

01-23 17:13:26.057: I/System.out(3846): name : View
01-23 17:13:26.077: I/System.out(3846): type : Page
01-23 17:13:26.077: I/System.out(3846): name : Organisational Structure
01-23 17:13:26.077: I/System.out(3846): type : Page
01-23 17:13:26.097: I/System.out(3846): name : Experience
01-23 17:13:26.097: I/System.out(3846): type : Page
01-23 17:13:26.097: I/System.out(3846): name : Expertise
01-23 17:13:26.097: I/System.out(3846): type : Language
01-23 17:13:26.097: I/System.out(3846): name : Flex
01-23 17:13:26.097: I/System.out(3846): type : Language
01-23 17:13:26.117: I/System.out(3846): name : Android
01-23 17:13:26.117: I/System.out(3846): type : Language
01-23 17:13:26.117: I/System.out(3846): name : Java
01-23 17:13:26.128: I/System.out(3846): type : Language
01-23 17:13:26.128: I/System.out(3846): name : Project
01-23 17:13:26.139: I/System.out(3846): type : Project
01-23 17:13:26.139: I/System.out(3846): name : Sabre
01-23 17:13:26.139: I/System.out(3846): type : Project
01-23 17:13:26.147: I/System.out(3846): name : Android Project
01-23 17:13:26.147: I/System.out(3846): type : Project
01-23 17:13:26.167: I/System.out(3846): name : Media Framework
01-23 17:13:26.167: I/System.out(3846): type : Project
01-23 17:13:26.167: I/System.out(3846): name : CCD
01-23 17:13:26.167: I/System.out(3846): type : Project
01-23 17:13:26.167: I/System.out(3846): name : Redbus
01-23 17:13:26.167: I/System.out(3846): type : Project
01-23 17:13:26.167: I/System.out(3846): name : India Today
01-23 17:13:26.177: I/System.out(3846): type : Project
01-23 17:13:26.187: I/System.out(3846): name : Money Control
01-23 17:13:26.187: I/System.out(3846): type : Project
01-23 17:13:26.187: I/System.out(3846): name : Reorganize
01-23 17:13:26.187: I/System.out(3846): type : Action
01-23 17:13:26.187: I/System.out(3846): name : Add New Employee
01-23 17:13:26.187: I/System.out(3846): type : Action
01-23 17:13:26.197: I/System.out(3846): name : Dir
01-23 17:13:26.197: I/System.out(3846): type : Page
01-23 17:13:26.217: I/System.out(3846): name : P.M
01-23 17:13:26.217: I/System.out(3846): type : Page
01-23 17:13:26.217: I/System.out(3846): name : S.E
01-23 17:13:26.217: I/System.out(3846): type : Page
01-23 17:13:26.217: I/System.out(3846): name : JUN
01-23 17:13:26.217: I/System.out(3846): type : Page
01-23 17:13:26.228: I/System.out(3846): name : EMP
01-23 17:13:26.228: I/System.out(3846): type : Page
01-23 17:13:26.237: I/System.out(3846): name : Add Project Members
01-23 17:13:26.237: I/System.out(3846): type : Action

java code :

package com.example.xmlparsevdatr;

import java.io.IOException;
import java.io.StringWriter;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
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.InputSource;
import org.xml.sax.SAXException;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

    Document dom;

    public MainActivity() {
        MainActivity();

        ArrayList<Element> listGroup = getGroups();

    }

    private ArrayList getGroups() {
        try {
            Element documentElement = (Element) dom.getDocumentElement();
            NodeList childNodes = documentElement.getElementsByTagName("node");

            for (int i = 0; i < childNodes.getLength(); i++) {

                if (childNodes.item(i).getNodeType() == Node.ELEMENT_NODE) {
                    Element element = (Element) childNodes.item(i);
                    String name = element.getAttribute("name");
                    String type = element.getAttribute("type");
                    System.out.println("name : " + name);
                    System.out.println("type : " + type);
                }
            }
        } catch (Exception e) {
        }
        return null;

    }

    private void MainActivity() {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        // System.out.println("Inside xml");

        try {
            String sURL = "http://192.168.2.6/cgi-bin/EmployeeTreeCgi/TreeStrutRet.cgi?Username=admin@ohile.com";
            URL url = new URL(sURL);
            DocumentBuilder db = dbf.newDocumentBuilder();

            dom = db.parse(new InputSource(url.openStream()));

        } catch (ParserConfigurationException pce) {
            pce.printStackTrace();
        } catch (SAXException se) {
            se.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
}
  • 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-17T15:53:26+00:00Added an answer on June 17, 2026 at 3:53 pm

    Your XML does not seem to be good.

    The first <node> element does not have name and type attributes.

    Ideally, while using XML you shouldn’t have the parent and child having same name. For example, the XML should be like :

    <books>
        <book id=1/>
        <book id=2/>
    </books>
    

    Also, please consider properly formatting your XML for better readability.

    EDIT:

    There can be a check before retrieving any attribute as:

    if(childNodes.item(i).hasAttribute("name")) {
        // print the name
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having the below code. import xml.dom.minidom def get_a_document(name): return xml.dom.minidom.parse(name) doc =
I have this below code and it work fine header (content-type: text/xml); $xml =
I have the code below and I need to return SOAP response (correct XML)
I have some simple data in XML format which I need to convert to
In the below code, I am looping through each XML and creating dynamic content.
I am working with layout like in below xml code <?xml version=1.0 encoding=utf-8?> <LinearLayout
I have a standard code like below to validate xml against xsd, but it
I'm trying to update an element in the XML document below: Here's the code:
The code below correctly returns the XML from the soap sever that I'm accessing.
I have code as below: var s : String = hello world var xml

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.