将xml文件中的日期更改为今天的日期

时间:2019-06-13 17:43:55

标签: xml powershell

我正在通过通过Web服务导入和导出数据来使我们的流程之一自动化。 Web服务调用将读取我在XML文件中具有的参数。数据导出必须每天执行。因此,我试图创建一个脚本,将XML文件中的开始日期和结束日期部分修改为今天的日期。 有人可以推荐任何有效的方法来做到这一点吗?

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:vertexinc:oseries:taxdata:datamanagement:8:0">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:RunTaxDataExportRequest>
         <urn:ExportFileName>taxdataexport.txt</urn:ExportFileName>
     <urn:StartDate>2019-06-06</urn:StartDate>
     <urn:EndDate>2019-06-07</urn:EndDate>
         <FieldDelimiter>TILDE</FieldDelimiter>
         <urn:RecordType>CERTIFICATE</urn:RecordType>
         <urn:Login>
            <urn:UserName>yyyy</urn:UserName>
            <urn:Password>xxx</urn:Password>
         </urn:Login>
      </urn:RunTaxDataExportRequest>
   </soapenv:Body>
</soapenv:Envelope>

1 个答案:

答案 0 :(得分:0)

为了使用xml,您需要首先将其转换为xml对象。那么应该很容易将其弄乱。

以下内容应该可以完成您想要做的事情。

示例:

#XML example
$xmlExample = '<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:vertexinc:oseries:taxdata:datamanagement:8:0">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:RunTaxDataExportRequest>
         <urn:ExportFileName>taxdataexport.txt</urn:ExportFileName>
     <urn:StartDate>2019-06-06</urn:StartDate>
     <urn:EndDate>2019-06-07</urn:EndDate>
         <FieldDelimiter>TILDE</FieldDelimiter>
         <urn:RecordType>CERTIFICATE</urn:RecordType>
         <urn:Login>
            <urn:UserName>yyyy</urn:UserName>
            <urn:Password>xxx</urn:Password>
         </urn:Login>
      </urn:RunTaxDataExportRequest>
   </soapenv:Body>
</soapenv:Envelope>'

#convert example to xml object
[xml]$xml = $xmlExample

#Change Start / End to today
$xml.Envelope.Body.RunTaxDataExportRequest.StartDate = (Get-Date).ToString("yyyy-MM-dd")
$xml.Envelope.Body.RunTaxDataExportRequest.EndDate = (Get-Date).ToString("yyyy-MM-dd")

#Display Results --- or do whatever with it
$xml.Envelope.Body.RunTaxDataExportRequest