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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:55:59+00:00 2026-06-14T03:55:59+00:00

I have parsed my HTML/JSP into DOM at compile time using JAVA. Now I

  • 0

I have parsed my HTML/JSP into DOM at compile time using JAVA. Now I have the w3c.dom.Document object with me, let’s say for the below HTML

.....
  ....
<input type="text" name="EnterName"/>
<select name="SelectOptions">
<option>First</option>
<option>Second</option>
</select>
 ......
.......

I know the attributes values of the elements. Here “EnterName” is the “name” attributes value of the node “input”.

Suppose I have attributes values of all nodes available in DOM (like “EnterName”, “SelectOptions” of above HTML), how do I can get a node in which a particular attribute is available with the given value. Thanks

EDIT :

I will never know whats the HTML contents. My program should run on
given list of HTML/JSP files and I have with me some element names.
Here the element name refers to the label/name of the fields available
in the HTML/JSP. So I need to traverse through all the files get the
node where it has the same label/name and get the node.

  • 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-14T03:56:01+00:00Added an answer on June 14, 2026 at 3:56 am

    Try something like this:

        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse("yourDocumentName");
        doc.getDocumentElement().normalize();
        NodeList nlList = doc.getElementsByTagName("input");
        for (int indx= 0; indx < nList.getLength(); indx++) {
           Element eElement = (Element) nList.item(indx);
           if(eElement.getAttribute("name").equals("EnterName")){
                  System.out.println("EnterName: " + eElement.getNodeValue());
           }
        }
    
        NodeList nlList1 = doc.getElementsByTagName("select");
        for (int indx= 0; indx < nList1.getLength(); indx++) {
           Element eElement = (Element) nList1.item(indx);
           if(eElement.getAttribute("name").equals("SelectOptions")){
                  System.out.println("SelectOptions: " + eElement.getNodeValue());
           }
        }
    

    If you could add the “id” to your elements then its much easier:

     <input type="text" name="EnterName" id="name"/>
     <select name="SelectOptions" id="options">
      ...
    
    
      Element nameElement = doc.getElementbyId("name");
      System.out.println("EnterName: " + nameElement.getNodeValue());
      Element selectElement = doc.getElementbyId("name");
      System.out.println("SelectOptions: " + selectElement.getNodeValue());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using a product which displays parsed XML files as HTML. It
I have parsed a html document in python and i am storing the contents
I have order confirmation html emails being parsed by a PHP script. The script
Is there a way to parse html content using javascript? I have a requirement
I have been using HTML Parser to scrapping data from websites and stripping html
Possible Duplicate: How to parse and process HTML with PHP? I have HTML document
I have an HTML file and i would like to parse through it using
I have this tag into my html file: {{block:my_test_block}} {{news:my_test_block2}} I need to parse
I have a JSP page that renders a block of HTML. In normal usage,
I am using jsp for scripting. I have a page where I collect data

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.