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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:04:44+00:00 2026-06-10T08:04:44+00:00

Please help me to put element and text nodes into an array of String

  • 0

Please help me to put element and text nodes into an array of Strings.

For example an .xml file has:

<soap:Envelope>
  <soap:Body>
    <ser:getTitle>
      <!--Optional:-->
      <ser:title>Meeting</ser:title>
    </ser:getTitle>
    <ser:getDiscription>
      <!--Optional:-->
      <ser:discription>this is the meeting</ser:discription>
    </ser:getDiscription>
    ...
  </soap:Body>
</soap:Envelop>

Now I want to place the values into the String[] key, value as follows:

key[0] = "title";
value[0] = "meeting";
key[1] = "discription";
value[1] = "this is the meeting";

… and so on.

Many thanks in advance!

  • 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-10T08:04:46+00:00Added an answer on June 10, 2026 at 8:04 am

    You can use DOM to parse your input XML and use something like:

    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import java.io.File;
    
    public dumpXMLTags(...) {
      String[] keys; // you would need that with appropriate size initialized
      String[] values;  
    
      // Parse your XML file and construct DOM tree
      File fXmlFile = new File(PATH_TO_YOUR_XML_FILE);
      DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      Document doc = dBuilder.parse(fXmlFile);
      doc.getDocumentElement().normalize();
    
      // Traverse DOM tree (make sure is not empty first, etc)
      NodeIterator iterator = traversal.createNodeIterator(
          doc.getDocumentElement(), NodeFilter.SHOW_ELEMENT, null, true);
    
      int i = 0;  // index to you key/value Array
    
      for (Node n = iterator.nextNode(); n != null; n = iterator.nextNode()) {
         keys[i] = ((Element) n).getTagName();
         values[i] = ((Element)n).getNodeValue();
         i++;
      }
    }
    

    Alternatively you could use XPATH with the

    //@* | //*[not(*)]
    

    expression, as described here: Question 7199897

    public static void main(String[] args) throws Exception {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(new InputSource(new StringReader(xml)));
    
        XPathFactory xpf = XPathFactory.newInstance();
        XPath xp = xpf.newXPath();
        NodeList nodes = (NodeList)xp.evaluate("//@* | //*[not(*)]", doc, XPathConstants.NODESET);
    
        System.out.println(nodes.getLength());
    
        for (int i=0, len=nodes.getLength(); i<len; i++) {
            Node item = nodes.item(i);
            System.out.println(item.getNodeName() + " : " + item.getTextContent());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help me somebody to convert unicodestring into string This is how i am
Would you please help me getting back the typename of the original object put
Can somebody please help me, I want to put the OK symbol throw HTML
This is my 3rd SO question. Please help again... I want to put up
Please, help me in: how to put a double command in the cmd ,
please help me to parse the xml with attributes from the given xml.. <tarifs>
I need to read an xml element which has attribute xmlns=http://www.w3.org/2000/09/xmldsig#. XPathSelectElement is giving
Could you help me with this question, please? I only need to put a
I need to convert specific XML attribute into XML element. The input XML: <?xml
I need to split the following string and put each new line into a

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.