Questions tagged [xmltodict]

Python module that makes working with XML feel like you are working with JSON.

xmltodict is a Python module that makes working with XML feel like you are working with JSON

Check it on Pypi here.

120 questions
0
votes
1 answer

Why I can't loop xmltodict?

Ive'been trying to transform all my logs in a dict through xmltodict.parse function The thing is, when I try to convert a single row to a variable it works fine a = xmltodict.parse(df['CONFIG'][0]) Same to parsed[1] =…
0
votes
0 answers

How to resolve- xml.parsers.expat.ExpatError: junk after document element- even after having single root element

my xml structure has one single root element. but xmltodict.parse(request) is giving me this error- xml.parsers.expat.ExpatError: junk after document element. Although it does run successfully sometimes, and sometimes throws the error. The XML file…
0
votes
3 answers

Json to XML with attributes rather than elements

I need to parse an Json like: { "operacion": "ingresarOrdenBilateral", "agente" : "0062", "comitente" : 7211, "fechaOrigen" : "2021-09-23T16:51:27.873-03:00", "tipo" : "V", "instrumento" : "GD30", "tipoVenc" : "24", "precio" :…
Methizul
  • 23
  • 5
0
votes
1 answer

Python requests xml: xml.parsers.expat.ExpatError: not well-formed (invalid token):

I have a problem with parsing a XML with xmltodict. This method works on other XML-files online, but now I'm getting this error: "xml.parsers.expat.ExpatError: not well-formed (invalid token):" What is going wrong here, and how can I fix/work around…
Johs
  • 73
  • 1
  • 7
0
votes
0 answers

Python convert any XML to CSV

I tried about about 15 answers from Stackoverflow, but nothing help me. I want convert any(!) nested XML file to CSV. I dont want write in programm direct elements of XML. On web exist many online services, there I can upload any xml and I can…
0
votes
1 answer

How to fetch POST request body in XML format as a dictionary in Flask hit through Postman?

I am new to Flask. How can I fetch POST request body sent in XML format (mimetype="application/xml") through Postman as a dictionary in Flask API? curl --location --request POST 'http://127.0.0.1:5000/test/' \ --header 'Content-Type:…
0
votes
1 answer

Conversion of Atom or OData XML file to OData Json file using Python

I have been trying to convert the PowerShell script to Python code to download the list files from Sharepoint. Most of the coding part is completed and well executed as of now. However, when I download the file from Sharepoint to local drive with…
0
votes
1 answer

Convert XML to JSON with python, attributes of the father after the child nodes in the JSON

I need convert one file XML to JSON with python, but I need put the attributes of the father after the child nodes in the JSON My current code is like that. def generate_json(self, event=None): # opening the xml file with open(self.fn ,"r")…
0
votes
1 answer

xmltodict parse/unparse produces does not produce the same xml file

I am using the following code snippet to read in the sample xmlTest1.xml file shown below. with open("xmlTest1.xml") as xml_file: xml_dict = xmltodict.parse(xml_file.read(), force_list={'team'}, attr_prefix="") xml_file.close() …
A O
  • 1
  • 1
0
votes
1 answer

xmltodict: unparsing raises ValueError('Document must have exactly one root.') - Python 3

Objective is to convert JSON to XML The code reads the JSON.txt, converts it into XML and writes it on to JSON_to_xml.txt. The below code returns a value error while unparsing giving an error that the file has multiple roots even though it has a…
Ramsey
  • 1
  • 3
0
votes
1 answer

XML to JSON

ends up as list

I have many xml files that I will convert to JSON and then load it into openRefine or pandas dataframe for analysis. The xml file look like
0
votes
0 answers

unable to convert back to xml from output of xmltodict

I'm importing xml file into dict and further converting that dict into Json. data_dict = xmltodict.parse(xmlstr,dict_constructor=dict) json_data = json.dumps(data_dict) I've an application to make changes to the JSON file and import that json file…
0
votes
1 answer

Xml to dict how to ignore some characters when I convert my xml file to json file

I wouldlike to remove some character when I try to convert my xml to dict : data = xmltodict.parse(open('test.xml').read()) with open('test2.json', "wt", encoding='utf-8', errors='ignore') as f: json.dump(data, f, indent=4,…
martin
  • 143
  • 1
  • 3
  • 9
0
votes
0 answers

Read json file get error json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I try to read data from my json file. First I convert my xml file to json and I get in output this json file for example : [ { "ABC": { "idObjet": "AffleurantEnveloppePCRS.0", "nature": "03", …
martin
  • 143
  • 1
  • 3
  • 9
0
votes
0 answers

Sometimes a list, sometimes a dictionary

I'm using xmltodict in Python 3.7.6 and am running into an issue where sometimes my data is a list and sometimes my data is an Ordered Dictionary. Here's a code exert: import xmltodict myData = list() myData.append…
SydV
  • 3
  • 3