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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:27:31+00:00 2026-06-08T13:27:31+00:00

How do i replace a variable defined in a file (a.xml) after the file

  • 0

How do i replace a variable defined in a file (a.xml) after the file is read into Jmeter ?
eg. a.xml has a content.

<Shipment Action="MODIFY" OrderNo="${vOrderNo}" >

The entire file is read into a string using
str_Input=${__FileToString(/a.xml)}

In the Jmx file, a http Request is made to get output from a webservice as
Using Xpath Extractor the value of OrderNo is read into a Variable vOrderNo.

Now, wanted to use the value of variable vOrderNo in the str_Input.. ? How do i ?

  • 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-08T13:27:33+00:00Added an answer on June 8, 2026 at 1:27 pm

    You can easily achieve this using beanshell (~java) code from any jmeter’s sampler which allows beanshell code execution – BeanShell Sampler e.g..

    The following works:

    
    import java.io.*;
    
    try
    {
        // reading file into buffer
        StringBuilder data = new StringBuilder();
        BufferedReader in = new BufferedReader(new FileReader("d:\\test.xml"));
    
        char[] buf = new char[1024];
        int numRead = 0;
        while ((numRead = in.read(buf)) != -1) {
        data.append(buf, 0, numRead);
        }
        in.close();
    
        // replacing stub with actual value
        String vOrderNo = vars.get("vOrderNo");
        String temp = data.toString().replaceAll("\\$\\{vOrderNo\\}", vOrderNo);
    
        // writing back into file
        Writer out = new BufferedWriter(new FileWriter("d:\\test.xml"));
        out.write(temp);
        out.close();
    }
    catch (Exception ex) {
        IsSuccess = false;
        log.error(ex.getMessage());
        System.err.println(ex.getMessage());
    }
    catch (Throwable thex) {
        System.err.println(thex.getMessage());
    }
    

    This code doesn’t require read file into string via ${__FileToString(…)}.
    As well, you can combine both methods.

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

Sidebar

Related Questions

I have a string stored in a file that is read into a string.
I have a variable defined as: D content 1280A CONST I need to find
I want to replace every ../ and script/uploaded in my string variable to !
I got a variable in a bash script that I need to replace. The
I have a variable myvar = document.getElementById('myid').innerHTML that I would like to replace all
I have a situtaiton where I read the bussiness logic and replace the variables
I try to replace a sub-str by the content of a valiable where its
I have a function that parses a file into a list. I'm trying to
I have a variable defined in script tags within the head of the document:
I got a factory, where Action Script follows an xml and builds DisplayObject hierarchy

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.