如何使用批处理文件从xml文件中读取数据 [英] How to read data from xml file using batch file

查看:153
本文介绍了如何使用批处理文件从xml文件中读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想通过从xml文件中读取标签来为批处理文件中的变量赋值。我的xml文件结构类似于< tag>值。有人能告诉我怎样才能实现这个目标?

解决方案





使用配置文件批处理。

通过从xml文件获取数据来更新配置文件。



示例XML文件:

 <?  xml     version   =  1.0    编码  = < span class =code-keyword> utf-8    >  
< 员工 >

< Emp >
< ID > 101 < / Id >
< 名称 > Rajesh < / Name >
< / Emp >


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


< Emp >
< ID > 103 < / Id >
< 名称 > Venky < /姓名 >
< / Emp >

< / Employees >





从XML文件中读取值的示例代码:

  public   string  GetValue()
{
DataSet ds = new DataSet();
ds.ReadXml( @ C:\ MyFile.xml);
string myValue = ds.Tables [ 0 ]。行[ 0 ] [ 1 ]。ToString();
return myValue;
}





现在XML文件中所需的值已准备就绪,使用特定值更新配置文件。


据我所知,您可以使用重定向运算符 [ ^ ]以输入命令,但没有简单的方法来解析XML文件。您可能需要编写一些代码来实现此目的。


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?

解决方案

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.


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.


这篇关于如何使用批处理文件从xml文件中读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆