XML Parsing in python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: XML Parsing in python (/thread-28226.html) |
XML Parsing in python - aarushprathap - Jul-10-2020 HI All, I have an input file sample like below <file="excel.1ew9u4t0tggb9315darmm0nfz2kb" name ="Custom SQL Query" type="text">SELECT [EMP$].[Category] AS [Category],&#13,&#10, [EMP$].[A] AS [A],&#13,&#10, [EMP$].[B] AS [B],&#13,&#10, [EMP$].[C] AS [C],&#13,&#10, [EMP$].[D AS [D,&#13,&#10, [Dept$].[E] AS [E],&#13,&#10, [Dept$].[F] AS [F (Dept)]&#13,&#10,FROM [EMP$]&#13,&#10, INNER JOIN [Dept$] ON [EMP$].[F] = [Dept$].[F] </file>I have to break the SQL and create an output xml like below <records class="column"> <remote-name>A</remote-name> <remotetype>130</remotetype> <local-name>[A]</local-name> <parent-name>[Custom SQL Query]</parent-name> <remote-alias>A</remote-alias> <ordinal>1</ordinal> <local-type>string</local-type> <aggregation>Count</aggregation> <contains-null>true</contains-null> <collation-flag>1</collation-flag> <attributes> <attribute datatype="string" name="DebugRemoteType">WSTR</attribute> </attributes> </records> <records class="column"> <remote-name>B</remote-name> <remotetype>130</remotetype> <local-name>[B]</local-name> <parent-name>[Custom SQL Query]</parent-name> <remote-alias>B</remote-alias> <ordinal>2</ordinal> <local-type>string</local-type> <aggregation>Count</aggregation> <contains-null>true</contains-null> <collation-flag>1</collation-flag> <attributes> <attribute datatype="string" name="DebugRemoteType">WSTR</attribute> </attributes> </records> and so on for c , d etcCan someone help ? As im new to the xml and Im also trying but not able to get the desired answer. Thanks, Aarush RE: XML Parsing in python - j.crater - Jul-11-2020 Hello, it will take an effort on your part and showing your attempt, before anyone of us can help you correct the mistakes or guide you towards your desired solution. Python fortunately has great built in XML modules, which is a good place for you to start exploring: https://docs.python.org/3/library/xml.html RE: XML Parsing in python - j.crater - Jul-11-2020 As well as this overview of XML modules: https://wiki.python.org/moin/PythonXml |