<DataGrid>
<DataRow>
<RowID>1</RowID>
<Date>26/10/2014</Date>
<Owner>ABC Company</Owner>
<Make>Mitsubishi</Make>
<Model_Family>Lancer</Model_Family>
<Submodel>Lancer 2.0 GSR Hatch CVT</Submodel>
<Origin/>
<CC_Rating>1997</CC_Rating>
<Weight>2000</Weight>
</DataRow>
<DataRow>
<RowID>2</RowID>
<Date>26/10/2014</Date>
<Owner>ABC Company</Owner>
<Make>Mazda</Make>
<Model_Family>Axela</Model_Family>
<Submodel/>
<Origin>Japan</Origin>
<CC_Rating>1497</CC_Rating>
<Weight/>
</DataRow>
<DataRow>
<RowID>3</RowID>
<Date>26/10/2014</Date>
<Owner>Test Company</Owner>
<Make>Kia</Make>
<Model_Family>Sorento</Model_Family>
<Submodel/>
<Origin>Korea</Origin>
<CC_Rating>2200</CC_Rating>
<Weight>2500<Weight>
</DataRow>
<DataRow>
<RowID>4</RowID>
<Date>26/10/2014</Date>
<Owner>Test Company</Owner>
<Make>Nissan</Make>
<Model_Family>Pathfinder</Model_Family>
<Submodel>SUV<Submodel>
<Origin>Japan</Origin>
<CC_Rating>2000</CC_Rating>
<Weight>2000<Weight>
</DataRow>
以上格式中可能有一个或多个文件,我的要求是读取所有这些文件并按所有者对它们进行分组,并将这些对象转换为JSON后调用一个REST Web服务。所需的JSON格式如下。
{
"batches": [
{
"Owner": "ABC Company",
"Date": "2014-10-26",
"Vehicles": [
{
"Make": "Mitsubishi",
"ModelFamily": "Lancer",
"SubModel": "Lancer 2.0 GSR Hatch CVT",
"Origin": null
"CcRating": "1997",
"Weight": "2000"
},
{
"Make": "Mazda",
"ModelFamily": "Axela",
"SubModel": null,
"Origin": "Japan",
"CcRating": "1497",
"Weight": null
}
]
},
{
"Owner": "Test Company",
"Date": "2014-10-26",
"Vehicles": [
{
"Make": "Kia",
"ModelFamily": "Sorento",
"SubModel": null,
"Origin": "Korea",
"CcRating": "2200",
"Weight": "2500"
},
{
"Make": "Nissan",
"ModelFamily": "Pathfinder",
"SubModel": "SUV",
"Origin": "Japan",
"CcRating": "2000",
"Weight": "2000"
}
]
}
]
这需要使用Windows PowerShell来完成,我是一个Java程序员,不知道如何使用PowerShell除了调用远程FTP服务器并读取所有XML文件。 非常感谢,如果有人能帮助我。
Import-CliXml
是Export-CliXml
的对应命令。CLIXML 是 PowerShell 用于序列化和反序列化对象的特定格式。文档页面最好地解释了它:“此 cmdlet 类似于 Export-Clixml,不同之处在于 Export-Clixml 将生成的 XML 存储在可作为对象重新导入的公共语言基础结构 (CLI) XML 文件中,而 Import-Clixml 则将其导入。ConvertTo-Xml 返回 XML 文档的内存表示形式,因此您可以继续在 PowerShell 中处理它。ConvertTo-Xml 没有将对象转换为 CLI XML 的选项。` - briantist