【发布时间】:2021-01-31 03:30:15
【问题描述】:
我加载了一个包含大量数据的复杂 XML 文件,其中包含复杂级别的嵌套元素。 DataSet.ReadXml() 加载得很好,我可以遍历所有节点。
基本上每个节点都被选为 DataTable,属性作为列名。
现在我可以像这样以线性方式遍历所有这些元素/数据表:
foreach( DataTable curDT in DS.Tables)
{
Console.WriteLine("Table name: {0}",curDT.TableName);
Console.WriteLine("Columns Count: {0}", curDT.Columns.Count);
Console.WriteLine("Rows Count: {0}", curDT.Rows.Count);
Console.WriteLine("Container: {0}", curDT.Container);
Console.WriteLine("columns =>");
foreach(DataColumn dataColumn in curDT.Columns)
{
Console.WriteLine(dataColumn.ColumnName);
}
Console.WriteLine();
}
但是这些数据表或元素之间存在复杂的嵌套关系(一个在另一个内部)。
当我使用 WriteXml() 提供新文件名时,它会正确地重新创建文件。
我的确切问题是DataSet.Tables 列表之间没有明显的关系,所以它如何能够将所有累积的 DataTables 放在一个线性列表中,但它们又能正确地重现 xml 文件。另外我想检查一下某某的父母是不是这个!
更新
我正在解析 15000 长的 STIG xml 文件,该文件可在线获取,但如果有帮助,我将开始使用它。
<Benchmark xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cpe="http://cpe.mitre.org/language/2.0" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:dc="http://purl.org/dc/elements/1.1/" id="Windows_10_STIG" xml:lang="en" xsi: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 date="2020-06-15">accepted</status>
<title>Windows 10 Security Technical Implementation Guide</title>
<description>The Windows 10 Security Technical Implementation Guide (STIG) is published as a tool to improve the security of Department of Defense (DoD) information systems. Comments or proposed revisions to this document should be sent via e-mail to the following address: disa.stig_spt@mail.mil.</description>
<notice id="terms-of-use" xml:lang="en">Developed_by_DISA_for_the_DoD</notice>
<reference href="https://cyber.mil/">
<dc:publisher>DISA</dc:publisher>
<dc:source>STIG.DOD.MIL</dc:source>
</reference>
<plain-text id="release-info">Release: 23 Benchmark Date: 17 Jun 2020</plain-text>
<version>1</version>
<Profile id="MAC-1_Classified">
<title>I - Mission Critical Classified</title>
<description><ProfileDescription></ProfileDescription></description>
<select idref="V-63319" selected="true" />
<select idref="V-63321" selected="true" />
<select idref="V-63323" selected="true" />
<select idref="V-63325" selected="true" />
</Profile>
<Group id="V-63319">
<title>WN10-00-000005</title>
<description><GroupDescription></GroupDescription></description>
<Rule id="SV-77809r3_rule" severity="medium" weight="10.0">
<version>WN10-00-000005</version>
<title>Domain-joined systems must use Windows 10 Enterprise Edition 64-bit version.</title>
<description><VulnDiscussion>Features such as Credential Guard use virtualization based security to protect information that could be used in credential theft attacks if compromised. There are a number of system requirements that must be met in order for Credential Guard to be configured and enabled properly. Virtualization based security and Credential Guard are only available with Windows 10 Enterprise 64-bit version.</VulnDiscussion><FalsePositives></FalsePositives><FalseNegatives></FalseNegatives><Documentable>false</Documentable><Mitigations></Mitigations><SeverityOverrideGuidance></SeverityOverrideGuidance><PotentialImpacts></PotentialImpacts><ThirdPartyTools></ThirdPartyTools><MitigationControl></MitigationControl><Responsibility></Responsibility><IAControls></IAControls></description>
<reference>
<dc:title>DPMS Target Windows 10</dc:title>
<dc:publisher>DISA</dc:publisher>
<dc:type>DPMS Target</dc:type>
<dc:subject>Windows 10</dc:subject>
<dc:identifier>2885</dc:identifier>
</reference>
<ident system="http://iase.disa.mil/cci">CCI-000366</ident>
<fixtext fixref="F-69237r2_fix">Use Windows 10 Enterprise 64-bit version for domain-joined systems.</fixtext>
<fix id="F-69237r2_fix" />
<check system="C-64053r3_chk">
<check-content-ref name="M" href="DPMS_XCCDF_Benchmark_Windows_10_STIG.xml" />
<check-content>
Verify domain-joined systems are using Windows 10 Enterprise Edition 64-bit version.
For standalone systems, this is NA.
Open "Settings".
Select "System", then "About".
If "Edition" is not "Windows 10 Enterprise", this is a finding.
If "System type" is not "64-bit operating system…", this is a finding.
</check-content>
</check>
</Rule>
</Group>
文件一直在继续。我以它代表复杂性的方式提供了文件的开头。
【问题讨论】:
-
为了回答,最好有一个您正在解析的 XML 数据的示例,无论是假数据还是重新创建的数据,这将有助于您获得答案。
-
@Jimithus 我正在解析 stigs XML 文件,这是 zip 文件夹中在线提供的 15000 行文件,但如果有帮助,我会发布它的开头。
-
即使你只有 2 个元素来显示复杂性,它也会有所帮助。
-
使用 excel 工作簿来设计你的数据集。工作簿的每张表都是不同的数据表。标题行将是数据表的列。对于每个文件,您需要通过一个公共键(如 xml 文件中的文件名或属性)来链接工作表(数据表)。我会试一试。