xml-parsing

Parse XML to CSV when XML tag has child attributes

Parse XML to CSV when XML tag has child attributes Question: I’ve written a small python app to print some XML tags and select child attributes. The XML are for electronic invoicing here in Mexico, here is an example of the XML: <?xml version="1.0" encoding="UTF-8"?><cfdi:Comprobante >import pandas as pd import xml.dom.minidom import xml.etree.ElementTree as Xet …

Total answers: 1

Python XML parsing missing element: 'None' vs None

Python XML parsing missing element: 'None' vs None Question: I am parsing an XML file and trying to find some XML tags. I’m looking for the tag personalDataRelated and when running it depending on XML file, I either get one of the two values below : <Element ‘personalDataRelated’ at 0x0000020417C86AC0> None What I do next …

Total answers: 1

python: exception inside try doesn't jump to except

python: exception inside try doesn't jump to except Question: I am trying to search within the EU parliment votes’ description. They are standard xml files. So far I noticed 2 versions of the votes’ result: where the description is text and where it is an url. Fails at this file: https://www.europarl.europa.eu/doceo/document/PV-9-2022-09-12-RCV_FR.xml Works fine on the …

Total answers: 1

Import data from XML using lxml

Import data from XML using lxml Question: I’m trying to extract data from several 1,000 XML files and compose a single df from it. The code I have so far is for a single XML extraction. from lxml import etree import pandas as pd serial = ["S1.xml"] content = serial.encode(‘utf-8’) doc = etree.XML(content) targets = …

Total answers: 3

Python XML Parsing without root v2

Python XML Parsing without root v2 Question: I have 100,000 XML files that look like this <?xml version="1.0" encoding="utf-8" standalone="no"?> <reiXml> <program>BB</program> <nazivStavbe>Test build</nazivStavbe> <X>101000</X> <Y>462000</Y> <QNH>24788</QNH> <QNC>9698</QNC> <Qf>255340</Qf> <Qp>597451</Qp> <CO2>126660</CO2> <An>1010.7</An> <Vc>3980</Vc> <A>2362.8</A> <Ht>0.336</Ht> <f0>0.59</f0> … </reiXml> I want to extract around 10 numbers from each, e.g. An, Vc… but i have a problem …

Total answers: 3

How to read from all XML files in directory and then combine the info into data frame?

How to read from all XML files in directory and then combine the info into data frame? Question: I wonder how can I do this code, but with multiply files coming from one directory: import xml.etree.ElementTree as ET import pandas as pd import numpy as np import os import xml.etree.ElementTree as ET tree = ET.parse(‘C:/Users/STJ2TW/Desktop/Pliki …

Total answers: 2

Parse XML with namespaces in python

Parse XML with namespaces in python Question: I hope you are doing well. I really need your help on this one, I´ve been working with XML lately but I came across this XML with Namespaces that I don´t understand. I want to extract the values of the response but I don´t know how to do …

Total answers: 2

Parsing XML with python ElementTree: ParseError: mismatched tag

Parsing XML with python ElementTree: ParseError: mismatched tag Question: I have several XML files I have to parse through with python ElemetTree (they are legacy from another developer). I’ve corrected those files a bit and parsed a good chunk so far but at some moment I got this parsing error, and I can’t get around …

Total answers: 3

How to convert a .txt to .xml in python

How to convert a .txt to .xml in python Question: So the current problem I’m facing would be in converting a text file into a xml file. The text file would be in this format. Serial Number: Operator ID: test Time: 00:03:47 Test Step 2 TP1: 17.25 TP2: 2.46 Serial Number: Operator ID: test Time: …

Total answers: 2