xml

Convert pandas dataframe to nest XML file in Python

Convert pandas dataframe to nest XML file in Python Question: I have a pandas dataframe looks like the following: df2 = pd.DataFrame(np.array([[‘A’, ‘2023-10-17’, ‘C’, 4, 1, 1, 1.5], [‘A’, ‘2023-10-17’, ‘C’, 5, 1, 5, 2.4], [‘A’, ‘2023-10-17’, ‘D’, 16, 1, 2, 2.3], [‘B’, ‘2023-10-17’, ‘C’, 4, 1, 1, 1.5], [‘B’, ‘2023-10-17’, ‘D’, 5, 1, 5, …

Total answers: 1

XPath SyntaxError: invalid predicate with text()

XPath SyntaxError: invalid predicate with text() Question: What am I doing wrong? When using what I believe to be a valid XPath expression in Python, I get a "SyntaxError: invalid predicate" result. My code is: import xml.etree.ElementTree as ET data = ”'<root> <child> <p>aaa</p> <p>bbb</p> </child> </root>”’ root = ET.fromstring(data) p_element = root.findall(".//p[text()=’aaa’]") print(p_element[0].text) Running …

Total answers: 1

XML and probably LXML issue

XML and probably LXML issue Question: I have many XML files that look like this <?xml version="1.0" encoding="utf-8" standalone="no"?> <reiXmlPrenos> <Qfl>1808</Qfl> <fOVE>13.7</fOVE> <NetoVolumen>613</NetoVolumen> <Hv>104.2</Hv> <energenti> <energent> <sifra>energy_e</sifra> <naziv>EE [kWh]</naziv> <vrednost>238981</vrednost> </energent> <energent> <sifra>energy_to</sifra> <naziv>Do</naziv> <vrednost>16359</vrednost> </energent> <energent> <sifra>energy_en</sifra> <naziv>En</naziv> <vrednost>0</vrednost> </energent> </energenti> <rei> <zavetrovanost>2</zavetrovanost> <cone> <cona> <cona_id>1</cona_id> <cc_si_cona>1110000</cc_si_cona> <visina_cone>2.7</visina_cone> <dolzina_cone>14</dolzina_cone> </cona> <cona> <cona_id>2</cona_id> <cc_si_cona>120000</cc_si_cona> </cona> …

Total answers: 2

How to make changes in XML file in Python

How to make changes in XML file in Python Question: I have a xml file MC.xml contents of which are <?xml version="1.0" encoding="UTF-8"?> <MCOO type="list"> <AAA> <Active value="True" li="True" mv="True"/> <Plot value="True" li="False" mv="False"/> <Color value="#990000"/> </AAA> <BBB> <Active value="True" li="True" mvl="True"/> <Plot value="True" li="False" mvl="False"/> <Color value="#990000"/> </BBB> <CCC> <Active value="True" li="False" mv="True"/> <Plot …

Total answers: 1

How do I delete particular pages from a DOCX file?

How do I delete particular pages from a DOCX file? Question: I have quite a large collection of DOCX documents, and I need to delete all but the first page in all of them. From what I have read, docx-python does not support this since it has no notion of pages. One option I have …

Total answers: 1

Failing at inserting a new line in existing xml file

Failing at inserting a new line in existing xml file Question: I am currently writing a python code to manage an existing xml file. I have this existing xml structure in a model file : <MYPROJECT> <VERSION>2</VERSION> <LANGUAGE>english</LANGUAGE> <FILE> <FILENAME>Z</FILENAME> </FILE> <PANEL1> <SOURCE> <LAYER>MISSING</LAYER> <NAME>MISSING</NAME> <ID>MISSING</ID> </SOURCE> </PANEL1> </MYPROJECT> I need to be able to …

Total answers: 2

How to print text and certain specified tags of XML file using BeautifulSoup

How to print text and certain specified tags of XML file using BeautifulSoup Question: I’m parsing the XML of a Microsoft Word .docx file with BeautifulSoup. I’d like to be able to extract the text of the XML file while still printing certain tags that I choose. I can get the text of the file …

Total answers: 1

Extracting contents from an XML file with BeautifulSoup on Python

Extracting contents from an XML file with BeautifulSoup on Python Question: I have an XML structure like this: <Trainers> <Trainer name="VisitorID" value=" NPRoiuKL213kiolkm2231"/> <Trainer name="VisitorNumber" value="BR-76594823-009922"/> <Trainer name="ServerIndex" value="213122"/> <Trainer name="VisitorPolicyID" value="ETR1234123"/> </Trainers> I want to extract the values based on the Trainer names. So basically something like this: NPRoiuKL213kiolkm2231 from the VisitorID , BR-76594823-009922 …

Total answers: 1

How to take only the field which have Maximum fields

How to take only the field which have Maximum fields Question: logger.info("Audit Report capture process start") for clientid in clients: files = xmlgenops.loadFileslist(clientid, os.path.join(filepath, clientid , ‘Outgoing’), ‘xml’) totalFiles[clientid] = len(files) total_files += len(files) logger.info ("Processing for client ‘{}’".format(clientid)) files_with_issues = 0 file_header_print = True for filename in files: filename = filename[1] fullfilename = os.path.join(filepath, …

Total answers: 1