Powershell XML XSL解析没有属性DISA stig

时间:2018-03-07 14:01:10

标签: xml powershell xslt

我正在使用DISA STIG xml文件,并遇到一些问题。他们使用XSL样式表文件,所以当我对它进行get-content时,我得到的是三个属性(Benchmark,xml,xml-stylesheet),零子节点。我现在一直在寻找DAYS如何实际解析/搜索原始XML文件中的实际节点,例如查找等等。

似乎

$STIG = [xml]$XmlDocument = Get-Content -Path "$Path\U_IIS_8-5_Server_STIG_V1R2_Manual-xccdf.xml"

只有

xml                            xml-stylesheet                          Benchmark
---                            --------------                          ---------
version="1.0" encoding="utf-8" type='text/xsl' href='STIG_unclass.xsl' Benchmark

我无法弄清楚如何将这个XML变成我可以实际搜索,解析等的XML。

1 个答案:

答案 0 :(得分:0)

PowerShell将[xml]文档转换为深层/复杂对象。我下载了STIG文档并像这样加载

PS> $xml = [xml](Get-Content .\U_A10_Networks_ADC_ALG_STIG_V1R1_Manual-xccdf.xml)

现在,您可以评估对象

PS> $xml

xml                            xml-stylesheet                          Benchmark
---                            --------------                          ---------
version="1.0" encoding="utf-8" type='text/xsl' href='STIG_unclass.xsl' Benchmark

或遍历其属性。

PS> $xml.Benchmark


dsig           : http://www.w3.org/2000/09/xmldsig#
xsi            : http://www.w3.org/2001/XMLSchema-instance
cpe            : http://cpe.mitre.org/language/2.0
xhtml          : http://www.w3.org/1999/xhtml
dc             : http://purl.org/dc/elements/1.1/
id             : A10_Networks_ADC_ALG_STIG
lang           : en
schemaLocation : http://checklists.nist.gov/xccdf/1.1 http://nvd.nist.gov/schema/xccdf-1.1.4.xsd
                 http://cpe.mitre.org/dictionary/2.0 http://cpe.mitre.org/files/cpe-dictionary_2.1.xsd
xmlns          : http://checklists.nist.gov/xccdf/1.1
status         : status
title          : A10 Networks ADC ALG Security Technical Implementation Guide
description    : This Security Technical Implementation Guide is published as a tool to improve the security of
                 Department of Defense (DoD) information systems. The requirements are derived from the National
                 Institute of Standards and Technology (NIST) 800-53 and related documents. Comments or proposed
                 revisions to this document should be sent via e-mail to the following address: disa.stig_spt@mail.mil.
notice         : notice
reference      : reference
plain-text     : plain-text
version        : 1
Profile        : {Profile, Profile, Profile, Profile...}
Group          : {Group, Group, Group, Group...}

大多数信息似乎都在以下路径上:

$xml.Benchmark.Group.Rule