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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:35:39+00:00 2026-06-17T16:35:39+00:00

The below is my xml format.In that i need to extract data under Group

  • 0

The below is my xml format.In that i need to extract data under Group tag,this group tag is under common tag.Inside this common tag we have 4 groups are there,i need that 4 group data alone.But in my xml some other group tag is also there ,so that data is also extracting.But i need that group data within the common tag.

My xml:

<root>
<Budget>100000.0</Budget>
<Procost>
<Costid>1</Costid>
<Costname>Fixed Cost</Costname>
<Amount>70666.66</Amount>
</Procost>
<Procostcount>1</Procostcount>
<Totalcost>70666.66</Totalcost>
<Common>
<Group>
<Empid>370</Empid>
<Reportid>-1</Reportid>
<Empcost>0</Empcost>
<Isanyreporting>Y</Isanyreporting>
<Reportcount>9</Reportcount>
<Reportname>NA</Reportname>
<Name>Shalini</Name>
<Desigid>0</Desigid>
<Gender>female</Gender>
<Yearexperience>11</Yearexperience>
<Monthexperience>0</Monthexperience>
<Phone>974113524</Phone>
<Emailid>shalini@ohile.com</Emailid>
<Projectid>1</Projectid>
<Projectname>Sabre</Projectname>
<Displaylevel>0</Displaylevel>
<Photo>None</Photo>
</Group>
<Group>
<Empid>381</Empid>
<Reportid>370</Reportid>
<Empcost>0</Empcost>
<Reportcount>0</Reportcount>
<Isanyreporting>No</Isanyreporting>
<Reportname>Shalini</Reportname>
<Name>Arun</Name>
<Desigid>1</Desigid>
<Gender>male</Gender>
<Yearexperience>8</Yearexperience>
<Monthexperience>0</Monthexperience>
<Phone>2147483647</Phone>
<Emailid>arun@ohile.com</Emailid>
<Projectid>1</Projectid>
<Projectname>Sabre</Projectname>
<Displaylevel>0</Displaylevel>
<Photo>None</Photo>
</Group>
<Group>
<Empid>382</Empid>
<Reportid>370</Reportid>
<Empcost>0</Empcost>
<Reportcount>0</Reportcount>
<Isanyreporting>No</Isanyreporting>
<Reportname>Shalini</Reportname>
<Name>Manu</Name>
<Desigid>1</Desigid>
<Gender>male</Gender>
<Yearexperience>8</Yearexperience>
<Monthexperience>0</Monthexperience>
<Phone>123487509</Phone>
<Emailid>manu@ohile.com</Emailid>
<Projectid>1</Projectid>
<Projectname>Sabre</Projectname>
<Displaylevel>0</Displaylevel>
<Photo>None</Photo>
</Group>
<Group>
<Empid>383</Empid>
<Reportid>370</Reportid>
<Empcost>0</Empcost>
<Reportcount>0</Reportcount>
<Isanyreporting>No</Isanyreporting>
<Reportname>Shalini</Reportname>
<Name>Ramakrishnan Nair</Name>
<Desigid>1</Desigid>
<Gender>male</Gender>
<Yearexperience>8</Yearexperience>
<Monthexperience>0</Monthexperience>
<Phone>467983245</Phone>
<Emailid>ramakrishnan@ohile.com</Emailid>
<Projectid>1</Projectid>
<Projectname>Sabre</Projectname>
<Displaylevel>0</Displaylevel>
<Photo>None</Photo>
</Group>
</Common>
<Project>
<Empid>371</Empid>
<Reportid>370</Reportid>
<Displaylevel>2</Displaylevel>
<Empcost>35333.3</Empcost>
<Name>Remya</Name>
<Desigid>5</Desigid>
<Gender>female</Gender>
<Yearexperience>2</Yearexperience>
<Monthexperience>0</Monthexperience>
<Phone>975443452</Phone>
<Emailid>remya@ohile.com</Emailid>
<Projectid>1</Projectid>
<Projectname>Sabre</Projectname>
<Photo>None</Photo>
<Reportcount>0</Reportcount>
<Isanyreporting>No</Isanyreporting>
<Reportname>Shalini</Reportname>
</Project>
<Project>
<Empid>374</Empid>
<Reportid>370</Reportid>
<Displaylevel>2</Displaylevel>
<Empcost>35333.3</Empcost>
<Name>Nijo Susan Thomas</Name>
<Desigid>5</Desigid>
<Gender>female</Gender>
<Yearexperience>1</Yearexperience>
<Monthexperience>1</Monthexperience>
<Phone>2147483647</Phone>
<Emailid>nijo@ohile.com</Emailid>
<Projectid>1</Projectid>
<Projectname>Sabre</Projectname>
<Photo>None</Photo>
<Reportcount>0</Reportcount>
<Isanyreporting>No</Isanyreporting>
<Reportname>Shalini</Reportname>
</Project>
<Count>6</Count>
<Procount>2</Procount>
<Fieldnames>
<Fieldnamecount>16</Fieldnamecount>
<Group>
<Fieldname>Name</Fieldname>
</Group>
<Group>
<Fieldname>Empid</Fieldname>
</Group>
<Group>
<Fieldname>Desigid</Fieldname>
</Group>
<Group>
<Fieldname>Gender</Fieldname>
</Group>
<Group>
<Fieldname>Yearexperience</Fieldname>
</Group>
<Group>
<Fieldname>Monthexperience</Fieldname>
</Group>
<Group>
<Fieldname>Phone</Fieldname>
</Group>
<Group>
<Fieldname>Emailid</Fieldname>
</Group>
<Group>
<Fieldname>Projectid</Fieldname>
</Group>
<Group>
<Fieldname>Reportid</Fieldname>
</Group>
<Group>
<Fieldname>Isanyreporting</Fieldname>
</Group>
<Group>
<Fieldname>Reportcount</Fieldname>
</Group>
<Group>
<Fieldname>Reportname</Fieldname>
</Group>
<Group>
<Fieldname>Photo</Fieldname>
</Group>
<Group>
<Fieldname>Displaylevel</Fieldname>
</Group>
<Group>
<Fieldname>Empcost</Fieldname>
</Group>
</Fieldnames>
</root>

My code:

public class XMLParsingDomExample extends Activity {
    List myEmpls;
    Document dom;

    public XMLParsingDomExample() {


        myEmpls = new ArrayList();
        parseXmlFile();

        parseDocument();

        printData();


    }

    /*public void runExample() {

    }*/

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

        try {
            URL url = new URL(
                    "http://fhkghkkl.guio");
            // "http://totheriver.com/learn/xml/code/employees.xml");

            DocumentBuilder db = dbf.newDocumentBuilder();

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

            dom.getDocumentElement().normalize();
            System.out.println("after xml");

        } catch (ParserConfigurationException pce) {
            pce.printStackTrace();
        } catch (SAXException se) {
            se.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }


    private void parseDocument() {
        Element docEle = dom.getDocumentElement();
        NodeList nl = docEle.getElementsByTagName("Group");
        // NodeList nl = docEle.getElementsByTagName("Common");
        // NodeList nl = dom.getDocumentElement().getChildNodes();

        System.out.println("nodelist is :" + nl);
        if (nl != null && nl.getLength() > 0) {
            for (int i = 0; i < nl.getLength(); i++) {

                Element el = (Element) nl.item(i);

                System.out.println("b4 getemployee");
                Employee e = getEmployee(el);

                myEmpls.add(e);
                System.out.println("employee size is =" + myEmpls.size());
            }
        }
    }

    private Employee getEmployee(Element empE1) {

        String empId = getTextValue(empE1, "Empid");

        String name = getTextValue(empE1, "Name");
        String repCount = getTextValue(empE1, "Reportcount");
        String desid = getTextValue(empE1, "Desigid");
        String projectid = getTextValue(empE1, "Projectid");
        String projectname = getTextValue(empE1, "Projectname");
        // String gender =
        // getTextValue(empE1, "Gender");
        // int yrEx = getIntValue(empE1,
        // "Yearexperience");
        // int mnthEx = getIntValue(empE1, "Monthexperience");
        // int prcId = getIntValue(empE1, "ProjectId"); String prcname =
        // getTextValue(empE1,
        // "Projectname");
        // int dislev = getIntValue(empE1, "Displaylevel"); String photo
        // = getTextValue(empE1, "Photo");
        // int phone = getIntValue(empE1, "Phone");
        // String emailid = getTextValue(empE1, "Emailid");

        Employee e = new Employee(empId, name, repCount, desid, projectid,
                projectname);
        return e;
    }

    // }

    private String getTextValue(Element ele, String tagName) {
        String textVal = null;
        NodeList nl = ele.getElementsByTagName(tagName);
        if (nl != null && nl.getLength() > 0) {
            Element el = (Element) nl.item(0);
            textVal = el.getFirstChild().getNodeValue();
        }

        return textVal;
    }

    private int getIntValue(Element ele, String tagName) {
        // in production application you would catch the exception
        return Integer.parseInt(getTextValue(ele, tagName));
    }

    private void printData() {

        System.out.println("No of Employees '" + myEmpls.size() + "'.");

        Iterator it = myEmpls.iterator();
        while (it.hasNext()) {
            System.out.println(it.next().toString());
        }
    }
}
    /*public static void main(String[] args) {

        XMLParsingDomExample dpe = new XMLParsingDomExample();

        dpe.runExample();
    }
}*/

My logcat:

I need this alone:

01-22 13:10:44.519: I/System.out(1606): Employee Details - EmployeeId:370.Empname :Shalini, DesignId:9, ReportCount:0, ProjectId:1, ProjectName:Sabre, 
01-22 13:10:44.537: I/System.out(1606): Employee Details - EmployeeId:381.Empname :Arun, DesignId:0, ReportCount:1, ProjectId:1, ProjectName:Sabre, 
01-22 13:10:44.537: I/System.out(1606): Employee Details - EmployeeId:382.Empname :Manu, DesignId:0, ReportCount:1, ProjectId:1, ProjectName:Sabre, 
01-22 13:10:44.547: I/System.out(1606): Employee Details - EmployeeId:383.Empname :Ramakrishnan Nair, DesignId:0, ReportCount:1, ProjectId:1, ProjectName:Sabre, 
01-22 13:10:44.547: I/System.out(1606): 

But this is also coming:

Employee Details - EmployeeId:null.Empname :null, DesignId:null, ReportCount:null, ProjectId:null, ProjectName:null, 
    01-22 13:10:44.578: I/System.out(1606): Employee Details - EmployeeId:null.Empname :null, DesignId:null, ReportCount:null, ProjectId:null, ProjectName:null, 
    01-22 13:10:44.578: I/System.out(1606): Employee Details - EmployeeId:null.Empname :null, DesignId:null, ReportCount:null, ProjectId:null, ProjectName:null, 
    01-22 13:10:44.597: I/System.out(1606): Employee Details - EmployeeId:null.Empname :null, DesignId:null, ReportCount:null, ProjectId:null, ProjectName:null, 
    01-22 13:10:44.597: I/System.out(1606): Employee Details - EmployeeId:null.Empname :null, DesignId:null, ReportCount:null, ProjectId:null, ProjectName:null, 
    01-22 13:10:44.617: I/System.out(1606): Employee Details - EmployeeId:null.Empname :null, DesignId:null, ReportCount:null, ProjectId:null, ProjectName:null, 
    01-22 13:10:44.617: I/System.out(1606): Employee Details - EmployeeId:null.Empname :null, DesignId:null, ReportCount:null, ProjectId:null, ProjectName:null, 
    01-22 13:10:44.637: I/System.out(1606): Employee Details - EmployeeId:null.Empname :null, DesignId:null, ReportCount:null, ProjectId:null, ProjectName:null, 
    01-22 13:10:44.637: I/System.out(1606): Employee Details - EmployeeId:null.Empname :null, DesignId:null, ReportCount:null, ProjectId:null, ProjectName:null, 
    01-22 13:10:44.657: I/System.out(1606): Employee Details - EmployeeId:null.Empname :null, DesignId:null, ReportCount:null, ProjectId:null, ProjectName:null, 
    01-22 13:10:44.657: I/System.out(1606): Employee Details - EmployeeId:null.Empname :null, DesignId:null, ReportCount:null, ProjectId:null, ProjectName:null, 
    01-22 13:10:44.667: I/System.out(1606): Employee Details - EmployeeId:null.Empname :null, DesignId:null, ReportCount:null, ProjectId:null, ProjectName:null, 
    01-22 13:10:44.677: I/System.out(1606): Employee Details - EmployeeId:null.Empname :null, DesignId:null, ReportCount:null, ProjectId:null, ProjectName:null, 
    01-22 13:10:44.677: I/System.out(1606): Employee Details - EmployeeId:null.Empname :null, DesignId:null, ReportCount:null, ProjectId:null, ProjectName:null, 
    01-22 13:10:44.687: I/System.out(1606): Employee Details - EmployeeId:null.Empname :null, DesignId:null, ReportCount:null, ProjectId:null, ProjectName:null, 
    01-22 13:10:44.698: I/System.out(1606): Employee Details - EmployeeId:null.Empname :null, DesignId:null, ReportCount:null, ProjectId:null, ProjectName:null,
  • 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-17T16:35:40+00:00Added an answer on June 17, 2026 at 4:35 pm

    If you are sure, that there is only one Common element, and all its childs are Groups, than

    NodeList common = docEle.getElementsByTagName("Common");
    NodeList nl = common.item(0).getChildNodes();
    

    If not, use the more general solution with xpath:

    XPathFactory xpathFactory = XPathFactory.newInstance();
    XPath xpath = xpathFactory.newXPath();
    NodeList nl = (NodeList) xpath.evaluate("Common/Group", docEle, XPathConstants.NODESET);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

need to convert an xml file having a tag(dynamicVariable) that has an attribute(name).This xml
I have some simple data in XML format which I need to convert to
I have an xml message that I need to parse (No control of format)
I have to generate XML in the below format <objects> <items> <item =delete> <searchfields>
Given the XML below, I need to group by InputItem and sum the costs
I want to create a XML file in csharp like the below format pls
How do I add CDATA to the ViolationInfo in this below XML <Violations ViolationNo=1
I have two documents that I need to merge, that happen in a way
I have around 50 xml files that are newly generated everytime I run a
I have the following XML I need to parse. Much of my issue seems

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.