This is my input file
<datasource formatted-name='federated.1819qwi0hys5391dzxhl70o95li4' inline='true' source-platform='win' version='18.1' xmlns:user='http://www.tableausoftware.com/xml/user'>
<connection class='federated'>
<named-connections>
<named-connection caption='Sample - Superstore' name='excel.1ew9u4t0tggb9315darmm0nfz2kb'>
<connection class='excel' driver='' filename='C:/Users/XXXX/Downloads/Sample - Superstore.xls' header='yes' imex='1' password='' server='' />
</named-connection>
</named-connections>
<relation connection='excel.1ew9u4t0tggb9315darmm0nfz2kb' name='Custom SQL Query' type='text'>SELECT [Orders$].[Category] AS [Category], [Orders$].[City] AS [City], [Orders$].[Country] AS [Country], [Orders$].[Customer ID] AS [Customer ID], [Orders$].[Customer Name] AS [Customer Name], [Orders$].[Discount] AS [Discount], [Orders$].[Profit] AS [Profit], [Orders$].[Quantity] AS [Quantity], [Orders$].[Region] AS [Region], [Orders$].[State] AS [State], [People$].[Person] AS [Person], [People$].[Region] AS [Region (People)] FROM [Orders$] INNER JOIN [People$] ON [Orders$].[Region] = [People$].[Region]</relation>
<metadata-records>
<metadata-record class='column'>
<remote-name>Category</remote-name>
<remote-type>130</remote-type>
<local-name>[Category]</local-name>
<parent-name>[Custom SQL Query]</parent-name>
<remote-alias>Category</remote-alias>
<ordinal>1</ordinal>
<local-type>string</local-type>
<aggregation>Count</aggregation>
<contains-null>true</contains-null>
<collation>LEN_RUS_S2_WO</collation>
<attributes>
<attribute datatype='string' name='DebugRemoteType'>"WSTR"</attribute>
</attributes>
</metadata-record>
I want to get the attribute tag . I Have tried
for x in xmlRoot.findall('./metadata-record'):
sqlString=x.find('attribute').text
but im getting only space as result. I have changed all the possible combinations in findall , still not able to get the result . I want to read that attribute tag dynamically and write in the output file as same . I have retrived the other tags from metadata-record but this alone not working. Can some one help ??
My expected output is
<metadata-records>
<metadata-record class='column'>
<remote-name>Category</remote-name>
<remote-type>130</remote-type>
<local-name>[Category]</local-name>
<parent-name>[Custom SQL Query]</parent-name>
<remote-alias>Category</remote-alias>
<ordinal>1</ordinal>
<local-type>string</local-type>
<aggregation>Count</aggregation>
<contains-null>true</contains-null>
<collation>LEN_RUS_S2_WO</collation>
<attributes>
<attribute datatype='string' name='DebugRemoteType'>"WSTR"</attribute>
</attributes>
</metadata-record>
I have retrieved till collation tag but do not know how to get the attributes tag. Can someone help??
Thanks, Aarush