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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:05:51+00:00 2026-05-14T04:05:51+00:00

I have a form in a .html files where input/select box looks like this

  • 0

I have a form in a .html files where input/select box looks like this

<input type="text" id="txtName" name="txtName" value="##myName##" />

<select id="cbGender"  name="cbGender">
 <option>Select</option>
 <option selected="selected">Male</option>
 <option>Female</option>
</select>

I would need to remove ‘##’ value textbox and also update them with different values if needed be in the textbox/checkbox/ selectbox. I would know the id of the input types. The code is to be written in groovy. Any ideas?

  • 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-14T04:05:52+00:00Added an answer on May 14, 2026 at 4:05 am

    This seems to work for me (took a bit of trial and error)

    @Grab(group='org.ccil.cowan.tagsoup', module='tagsoup', version='1.2')
    import org.ccil.cowan.tagsoup.*
    import groovy.xml.*
    
    String htmlTxt = """<html>
      <body>
        <input type="text" id="txtName" name="txtName" value="##myName##" />
        <select id="cbGender"  name="cbGender">
           <option>Select</option>
           <option selected="selected">Male</option>
           <option>Female</option>
        </select>
      </body>
    </html>"""
    
    // Define our TagSoup backed parser
    def slurper = new XmlSlurper( new Parser() )
    
    // Parse our html
    def h = slurper.parseText( htmlTxt )
    
    // Find the input with the id 'txtName'
    def i = h.body.input.list().find { it.@id == 'txtName' }
    
    // Change it's value
    i.@value = 'new value'
    
    // Write it out (into a StringWriter for now)
    def w = new StringWriter()
    w << new StreamingMarkupBuilder().bind {
      // Required to avoid the html: namespace on every node
      mkp.declareNamespace '':'http://www.w3.org/1999/xhtml'
      mkp.yield h
    }
    // XmlUtil.serialize neatens up our resultant xml -- but adds an xml declaration :-(
    println new XmlUtil().serialize( w.toString() )
    

    [edit]

    That gives this result:

    <?xml version="1.0" encoding="UTF-8"?>
    <html xmlns="http://www.w3.org/1999/xhtml">
      <body>
        <input id="txtName" name="txtName" value="new value" type="text"/>
        <select id="cbGender" name="cbGender">
          <option>Select</option>
          <option selected="selected">Male</option>
          <option>Female</option>
        </select>
      </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.