Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i want to assign value of a variable in a batch file by reading a tag from xml file.My xml file structure is like <tag>value. Can someone tell me how can i achieve this?
Posted

Hi,

Use a Configuration file for the Batch process.
Update the config file by getting the data from the xml file.

Sample XML File:
XML
<?xml version="1.0" encoding="utf-8" ?>
<Employees>

  <Emp>
    <Id>101</Id>
    <Name>Rajesh</Name>
  </Emp>


  <Emp>
    <Id>102</Id>
    <Name>Anand</Name>
  </Emp>


  <Emp>
    <Id>103</Id>
    <Name>Venky</Name>
  </Emp>

</Employees>


Sample Code to read a Value from XML File:
C#
public string GetValue()
{
    DataSet ds = new DataSet();
    ds.ReadXml(@"C:\MyFile.xml");
    string myValue = ds.Tables[0].Rows[0][1].ToString();
    return myValue;
}


Now the required value from XML file is ready, update the config file with the specific value.
 
Share this answer
 
As far as I know you can use the redirection operators[^] to feed into commands, but there is no simple way to parse an XML file. You would probably need to write some code to achieve this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900