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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:39:00+00:00 2026-05-26T07:39:00+00:00

i have following xml : <?xml version=1.0 encoding=UTF-8 standalone=no?> <root> <processid>processid_1111</processid> <suggestion> <geo1>a</geo1> <geo2>b</geo2>

  • 0

i have following xml :

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root> 
<processid>processid_1111</processid>
<suggestion>
       <geo1>a</geo1>
       <geo2>b</geo2>
       <geo3>c</geo3>
       <standarddatasuggestion>account1</standarddatasuggestion>
</suggestion>
<suggestion>
      <geo1>d</geo1>
      <geo2>e</geo2>
      <geo3>f</geo3>
      <geo4>g</geo4>
      <standarddatasuggestion>account2</standarddatasuggestion>
</suggestion>
<taskid>taskid_111</taskid>
</root>

i want to design a method that can take node name and on the basis of node name it return corresponding node and it’s value in map objects.please help me to sort out above problem.

i tried it:

public SortedMap[] getObjectValueFromXML(Object xmlObject) 
  {
    Node item = null;
    SortedMap[] map = null;
    String subchildnodeName = null;
    String subchildnodeValue = null;
    Map subchildmap[] = null;
    try {
        if (xmlObject == null) {
            throw new NullPointerException("XML object found null");
        }

        factory = DocumentBuilderFactory.newInstance();
        builder = factory.newDocumentBuilder();
        doc = builder.parse(new ByteArrayInputStream(xmlObject.toString().getBytes()));
        doc.getDocumentElement().normalize();
        node = doc.getDocumentElement();
        root = node.getNodeName();
        nList = doc.getElementsByTagName(root);

        for (int temp = 0; temp < nList.getLength(); temp++) {
            nNode = nList.item(temp);
            NodeList childNodes = nNode.getChildNodes();
            int length = childNodes.getLength();
            map = new TreeMap[length];

            String nodeValues[][] = new String[length][2];
            for (int i = 0; i < length; i++) {

                item = nNode.getChildNodes().item(i);
                String parentnodeName = item.getNodeName();
                int noderepetationlength = doc.getElementsByTagName(parentnodeName).getLength();
                // System.out.println(noderepetationlength);
                NodeList rootchildNodes = item.getChildNodes();
                String parentnodeValue = rootchildNodes.item(0).getNodeValue();
                map[i] = new TreeMap();
                if (parentnodeName != null && parentnodeValue != null && noderepetationlength <= 1) {
                    map[i].put(parentnodeName, parentnodeValue);
                } else 
                {
                    subchildmap = new HashMap[noderepetationlength];
                    for (int t = 0; t < noderepetationlength; t++) 
                    {

                        NodeList childNodes1 = item.getChildNodes();
                        int length1 = childNodes1.getLength();
                         subchildmap[t] = new HashMap(); 
                        for (int j = 0; j < length1; j++) 
                        {

                            Node item2 = childNodes1.item(j);
                            if (item2.getNodeType() == Node.ELEMENT_NODE) 
                            {
                                subchildnodeName = item2.getNodeName();
                                NodeList childNodes2 = item2.getChildNodes();
                                int length2 = childNodes2.getLength();
                                for (int k = 0; k < length2; k++) 
                                    subchildnodeValue = childNodes2.item(k).getNodeValue();

                            }
                            subchildmap[t].put(subchildnodeName, subchildnodeValue);

                        }
                        map[i].put(parentnodeName, subchildmap[t]);
                    }
                }
            }//else
        } //end of for-loop

    } catch (ParserConfigurationException pce) {
    } catch (NullPointerException nofe) {
    } catch (SAXException saxException) {
    } catch (IOException ioe) {
    }

    return map;
} 

but not able to get expect results.

Thanks

  • 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-05-26T07:39:01+00:00Added an answer on May 26, 2026 at 7:39 am

    Jaxb has served me well in the past, but might be overkill for this situation.

    Information here

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

Sidebar

Related Questions

I have the following XML structure: <?xml version=1.0 encoding=utf-8 standalone=yes?> <Root xmlns:xsi=My Program> <NotRoot
I have the following code. <?xml version=1.0 encoding=UTF-8 standalone=no?> <!DOCTYPE html PUBLIC -//W3C//DTD XHTML
I have used urllib to get the following data: <?xml version=1.0 encoding=UTF-8 standalone=yes?> <videos
I have the following xml file: <?xml version=1.0 encoding=UTF-8 standalone=no ?> <config> <a> <b>
I have the following XML: <?xml version=1.0 encoding=UTF-8 standalone=yes?> <application xmlns=http://research.sun.com/wadl/2006/10> <doc xmlns:jersey=http://jersey.dev.java.net/ jersey:generatedBy=Jersey:
I have following XML schema: <?xml version=1.0 encoding=UTF-8 standalone=no?> <xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema> <xs:element name=content type=contentType/>
i have the following classes which is marshalled as an XML <?xml version=1.0 encoding=UTF-8
I have xml file whose structure is defined with following xsd: <?xml version=1.0 encoding=utf-8?>
I have the following XML document <?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005' xmlns:issues='http://schemas.google.com/projecthosting/issues/2009' gd:etag='W/DEAERH47eCl7ImA9WhZTFEQ.'><id>http://code.google.com/feeds/issues/p/chromium/issues/full/921</id><published>2008-09-03T22:51:22.000Z</published><updated>2011-03-19T01:05:05.000Z</updated><title>Incorrect rendering</title><content
I have a following wsdl from a WCF service. <?xml version=1.0 encoding=utf-8?> <wsdl:definitions name=Service

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.