Я пытаюсь преобразовать приведенный ниже XML в CSV, используя groovy XmlSlurper().parseText()
, но при перемещении на внутренний узел ничего не печатается.
XML-файл:
string input = """<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<executeQueryInSpaceResponse>
<executeQueryInSpaceResult>
<rows>
<ArrayOfString>
<string>ABCDEF</string>
<string>ABC</string>
<string>DEF</string>
<string>Shilo</string>
<string/>
<string>August</string>
<string>Georgia</string>
<string/>
<string>34566</string>
<string>Studies </string>
<string>August</string>
<string/>
<string/>
<string>Clerk</string>
<string/>
<string>2016-01-05 00:00:00.000</string>
<string/>
<string/>
<string/>
<string/>
<string/>
<string>Not Qualified</string>
<string>Unintended Request</string>
<string>512544989</string>
<string>marketing</string>
<string>Interactive</string>
<string/>
<string>0</string>
</ArrayOfString>
<ArrayOfString>
<string>ABCDEF</string>
<string>ABC</string>
<string>DEF</string>
<string>Shilo</string>
<string/>
<string>August</string>
<string>Georgia</string>
<string/>
<string>34566</string>
<string>Studies </string>
<string>August</string>
<string/>
<string/>
<string>Clerk</string>
<string/>
<string>2016-01-05 00:00:00.000</string>
<string/>
<string/>
<string/>
<string/>
<string/>
<string>Not Qualified</string>
<string>Unintended Request</string>
<string>512544989</string>
<string>marketing</string>
<string>Interactive</string>
<string/>
<string>0</string>
</ArrayOfString>
</rows>
<columnNames>
<string>Name</string>
<string>First Name</string>
<string>Last Name</string>
<string>Address Line 1</string>
<string>Address Line 2</string>
<string>City</string>
<string>State</string>
<string>Country</string>
<string>Postal Code</string>
<string>Program</string>
<string>Campus Name</string>
<string>Date ASP</string>
<string>Date LEGACY</string>
<string>Success 1</string>
<string>Success 2</string>
<string>Received Date</string>
<string>Submitted Date</string>
<string>Complete Date</string>
<string>Decision Date</string>
<string>Registration Date</string>
<string>FDOC</string>
<string>Status</string>
<string>Step</string>
<string>LeadId</string>
<string>Source</string>
<string>Vendor</string>
<string>Client</string>
<string>SAVEDEXPRESSION</string>
</columnNames>
<displayNames>
<string>Name</string>
<string>First Name</string>
<string>Last Name</string>
<string>Address Line 1</string>
<string>Address Line 2</string>
<string>City</string>
<string>State</string>
<string>Country</string>
<string>Postal Code</string>
<string>Program</string>
<string>Campus Name</string>
<string>Date ASP</string>
<string>Date LEGACY</string>
<string>Success 1</string>
<string>Success 2</string>
<string>Received Date</string>
<string>Submitted Date</string>
<string>Complete Date</string>
<string>Decision Date</string>
<string>Registration Date</string>
<string>FDOC Date</string>
<string>Status</string>
<string>Step</string>
<string>LeadId</string>
<string>Source</string>
<string>Vendor</string>
<string>Client</string>
<string>SAVEDEXPRESSION</string>
</displayNames>
<dataTypes>
<int>12</int>
<int>12</int>
<int>12</int>
<int>12</int>
<int>12</int>
<int>12</int>
<int>12</int>
<int>12</int>
<int>12</int>
<int>12</int>
<int>12</int>
<int>93</int>
<int>93</int>
<int>12</int>
<int>12</int>
<int>93</int>
<int>93</int>
<int>93</int>
<int>93</int>
<int>93</int>
<int>93</int>
<int>12</int>
<int>12</int>
<int>12</int>
<int>12</int>
<int>12</int>
<int>12</int>
<int>-5</int>
</dataTypes>
<numRowsReturned>10</numRowsReturned>
<hasMoreRows>false</hasMoreRows>
</executeQueryInSpaceResult>
</executeQueryInSpaceResponse>"""
Groovy Code:
content = new XmlSlurper().parseText(input)
println content
println content.executeQueryInSpaceResponse.executeQueryInSpaceResult
Это ничего не печатает.Ожидаемый результат будет выглядеть следующим образом:
Ожидаемый выходной файл CSV:
Заголовок файла csv должен быть:
Name,First Name,Last Name,Address Line 1,Address Line 2,City,State,Country,Postal Code,Program,Campus Name,Date ASP,Date LEGACY,Success 1,Success 2,Received Date,Submitted Date,Complete Date,Decision Date,Registration Date,FDOC Date,Status,Step,LeadId,Source,Vendor,Client,SAVEDEXPRESSION
И строки должны быть
ABCDEF,ABC,DEF,Shilo,,August,Georgia,,34566,Studies,August,,,Clerk,,2016-01-05 00:00:00.000,,,,,,Not Qualified,Unintended Request,512544989,marketing,Interactive,,0
ABCDEF,ABC,DEF,Shilo,,August,Georgia,,34566,Studies,August,,,Clerk,,2016-01-05 00:00:00.000,,,,,,Not Qualified,Unintended Request,512544989,marketing,Interactive,,0