【发布时间】:2016-11-03 03:17:16
【问题描述】:
您好,我想将带有嵌套元素的 XML 转换为所有嵌套元素并行出现的平面 XML
输入 XML:
<?xml version='1.0' encoding='UTF-8'?>
<Report_Data>
<Report_Entry>
<Employee_ID>02159</Employee_ID>
<Name>ABC, DEF</Name>
<Citizenship_Countries>United States of America</Citizenship_Countries>
<National_Identifiers>
<National_ID_Country>United States of America</National_ID_Country>
<National_ID_Type_Name>Social Security Number (SSN)</National_ID_Type_Name>
<National_ID_Unformatted>111111111</National_ID_Unformatted>
</National_Identifiers>
<Marital_Status>Married (United States of America)</Marital_Status>
<Dependents>
<Relationship>Child</Relationship>
<Name>Ethan ABC</Name>
<Age>12</Age>
</Dependents>
<Dependents>
<Relationship>Child</Relationship>
<Name>Holly ABC</Name>
<Age>7</Age>
</Dependents>
</Report_Entry>
<Report_Entry>
<Employee_ID>04805</Employee_ID>
<Name>dUMMY, ABC</Name>
<Citizenship_Countries>United States of America</Citizenship_Countries>
<National_Identifiers>
<National_ID_Country>United States of America</National_ID_Country>
<National_ID_Type_Name>Social Security Number (SSN)</National_ID_Type_Name>
<National_ID_Unformatted>111111111</National_ID_Unformatted>
</National_Identifiers>
<Marital_Status>Married (United States of America)</Marital_Status>
<Dependents>
<Relationship>Child</Relationship>
<Name>QWER dUMMY</Name>
<Age>6</Age>
</Dependents>
<Dependents>
<Relationship>Child</Relationship>
<Name>ASDF dUMMY</Name>
<Age>4</Age>
</Dependents>
</Report_Entry>
</Report_Data>
输出 XML:
<?xml version='1.0' encoding='UTF-8'?>
<Report_Data>
<Report_Entry>
<Employee_ID>02159</Employee_ID>
<Name>ABC, DEF</Name>
<Citizenship_Countries>United States of America</Citizenship_Countries>
<National_Identifiers_National_ID_Country>United States of America</National_Identifiers_National_ID_Country>
<National_Identifiers_National_ID_Type_Name>Social Security Number (SSN)</National_Identifiers_National_ID_Type_Name>
<National_Identifiers_National_ID_Unformatted>111111111</National_Identifiers_National_ID_Unformatted>
<Marital_Status>Married (United States of America)</Marital_Status>
<Dependent_Relationship>Child</Dependent_Relationship>
<Dependent_Name>Ethan ABC</Dependent_Name>
<Dependent_Age>12</Dependent_Age>
</Report_Entry>
<Report_Entry>
<Employee_ID>02159</Employee_ID>
<Name>ABC, DEF</Name>
<Citizenship_Countries>United States of America</Citizenship_Countries>
<National_Identifiers_National_ID_Country>United States of America</National_Identifiers_National_ID_Country>
<National_Identifiers_National_ID_Type_Name>Social Security Number (SSN)</National_Identifiers_National_ID_Type_Name>
<National_Identifiers_National_ID_Unformatted>111111111</National_Identifiers_National_ID_Unformatted>
<Marital_Status>Married (United States of America)</Marital_Status>
<Dependent_Relationship>Child</Dependent_Relationship>
<Dependent_Name>Holly ABC</Dependent_Name>
<Dependent_Age>7</Dependent_Age>
</Report_Entry>
<Report_Entry>
<Employee_ID>04805</Employee_ID>
<Name>dUMMY, ABC</Name>
<Citizenship_Countries>United States of America</Citizenship_Countries>
<National_Identifiers_National_ID_Country>United States of America</National_Identifiers_National_ID_Country>
<National_Identifiers_National_ID_Type_Name>Social Security Number (SSN)</National_Identifiers_National_ID_Type_Name>
<National_Identifiers_National_ID_Unformatted>111111111</National_Identifiers_National_ID_Unformatted>
<Marital_Status>Married (United States of America)</Marital_Status>
<Dependent_Relationship>Child</Dependent_Relationship>
<Dependent_Name>QWER dUMMY</Dependent_Name>
<Dependent_Age>6</Dependent_Age>
</Report_Entry>
<Report_Entry>
<Employee_ID>04805</Employee_ID>
<Name>dUMMY, ABC</Name>
<Citizenship_Countries>United States of America</Citizenship_Countries>
<National_Identifiers_National_ID_Country>United States of America</National_Identifiers_National_ID_Country>
<National_Identifiers_National_ID_Type_Name>Social Security Number (SSN)</National_Identifiers_National_ID_Type_Name>
<National_Identifiers_National_ID_Unformatted>111111111</National_Identifiers_National_ID_Unformatted>
<Marital_Status>Married (United States of America)</Marital_Status>
<Dependent_Relationship>Child</Dependent_Relationship>
<Dependent_Name>ASDF dUMMY</Dependent_Name>
<Dependent_Age>4</Dependent_Age>
</Report_Entry>
</Report_Data>
注意:我的子元素与从属元素下的名称为 "Name" 的元素相同。所以我在输出 XML 中想要的是依赖名称的名称是使用不同的元素名称,例如 Dependent_Name
【问题讨论】: