将XML解析为表

时间:2014-04-02 13:44:36

标签: xml powershell-v3.0

我有这个XML,我需要将它解析为PowerShell中的一个表。我需要几行代码才能把它放到表格中

<RowTypes>
    <RowType Id="70430" Label="JACS Principal Subject (2012/13 onwards)" />
    <RowType Id="70431" Label="Cost Centre (2012/13 onwards)" />
    <RowType Id="3297" Label="Institution" />
    <RowType Id="3298" Label="HESACode Principal Subject" />
    <RowType Id="3299" Label="Cost Centre (2003/04 &amp; before)" />
    <RowType Id="3300" Label="JACS Principal Subject (2006/07 &amp; before)" />
    <RowType Id="3301" Label="Cost Centre (2004/05 to 2011/12)" />
    <RowType Id="3302" Label="JACS Principal Subject (2007/08 to 2011/12)" />
    <RowType Id="3303" Label="Unit of assessment" />
    <RowType Id="3304" Label="UCAS JACS Subject Line (2011/12 &amp; before)" />
    <RowType Id="68689" Label="UCAS JACS Subject Line (2012/13 onwards)" />
</RowTypes>

1 个答案:

答案 0 :(得分:0)

读取文件的内容并将结果转换为xml:

PS>[xml]$x=gc c:\temp\xml.xml 

PS>$x.rowtypes.rowtype | %{ echo "ID=  $($_.Id) LABEL= $($_.Label))"}   
ID=  70430 LABEL= JACS Principal Subject (2012/13 onwards))             
ID=  70431 LABEL= Cost Centre (2012/13 onwards))                        
ID=  3297 LABEL= Institution)                        
相关问题