Click here to Skip to main content
14,641,865 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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 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:
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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

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.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100