Apr-11-2018, 09:51 PM
Hello All -
I am trying to parse some xml files that are saturated with Namespaces. I have been able to parse XML files without namespaces. I have found several articles online on parsing with Namespaces, but the namespaces in my file don't seem like most of the examples I have found online.
Below is an example of the XML. I am trying to get to the ConnectionString property.
I have tried using findall with the full hierarchy like
My next move is to probably strip out the namespace prefixes and then parse the file, but figured i'd check with others to see if someone knows a way to resolve.
Thanks for any help
The XML looks like this:
I am trying to parse some xml files that are saturated with Namespaces. I have been able to parse XML files without namespaces. I have found several articles online on parsing with Namespaces, but the namespaces in my file don't seem like most of the examples I have found online.
Below is an example of the XML. I am trying to get to the ConnectionString property.
I have tried using findall with the full hierarchy like
conn_mgrs = root.findall('ConnectionManagers/ConnectionManager/ObjectData/ConnectionManager')And, also using the namespace argument like:
ns = {'XYZ': 'www.example.com/myExample/Xyz'} conn_mgrs = root.findall('ConnectionManagers/ConnectionManager/ObjectData/ConnectionManager', ns)Both just return a null element.
My next move is to probably strip out the namespace prefixes and then parse the file, but figured i'd check with others to see if someone knows a way to resolve.
Thanks for any help
The XML looks like this:
<XYZ:Executable xmlns:XYZ="www.example.com/myExample/Xyz" XYZ:Id="Package" XYZ:CreationDate="2/21/2018 11:11:48 AM" XYZ:XYZID="{FB8BE06B-76B6-44DA-B2C7-043BD0989CBF}" XYZ:ObjectName="MyTestProject" XYZ:VersionGUID="{8D9F7CDA-590E-44C3-8896-786D27167F7D}"> <XYZ:Property XYZ:Name="PackageFormatVersion">6</XYZ:Property> <XYZ:ConnectionManagers> <XYZ:ConnectionManager XYZ:refId="Package.ConnectionManagers[RTG093939BB.AdminDB]" XYZ:CreationName="OLEDB" XYZ:XYZID="{C67B6283-781F-4B0E-A9A7-376A157B6F16}" XYZ:ObjectName="RTG093939BB.AdminDB"> <XYZ:ObjectData> <XYZ:ConnectionManager XYZ:ConnectionString="Data Source=RTG093939BB;Initial Catalog=AdminDB;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;" /> </XYZ:ObjectData> </XYZ:ConnectionManager> <XYZ:ConnectionManager XYZ:refId="Package.ConnectionManagers[RTG093955XT.Stage]" XYZ:CreationName="OLEDB" XYZ:XYZID="{8B4F57EA-03EA-49FA-B4BD-828A89FE5A32}" XYZ:ObjectName="RTG093955XT.Stage"> <XYZ:ObjectData> <XYZ:ConnectionManager XYZ:ConnectionString="Data Source=RTG093955XT;Initial Catalog=Stage;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;" /> </XYZ:ObjectData> </XYZ:ConnectionManager> </XYZ:ConnectionManagers> </XYZ:Executable>