Questions tagged [celementtree]

The cElementTree module is a C implementation of the Python ElementTree API, optimized for fast parsing and low memory use. The module is deprecated since Python 3.3.

The cElementTree module is a C implementation of the Python ElementTree API, optimized for fast parsing and low memory use.

Since Python 3.3, the module is deprecated and there is no need to explicitly import it. Just use xml.etree.ElementTree (see https://docs.python.org/3/whatsnew/3.3.html#xml-etree-elementtree).

77 questions
1
vote
2 answers

iterparse elements getting cleared before I can capture the data

I'm trying to use Python to parse a large XML file (27GB) using cElementTree and iterparse. I'm able to extract all the tags, but for some reason none of the element text is being retrieved (its always showing 'None'). I've checked the documentation…
1
vote
1 answer

Python: Using namespaces in ElementTree with iter()

I am using xml.etree.ElementTree to parse some complex xml files. Some of the xml files have several repeating tags nested in them.
Pvham
  • 51
  • 7
1
vote
0 answers

How to insert a sub-node for a particular node in XML using cElementTree in python

Below is the requirement to convert a BNF-form grammar into XML. input: define program [repeat statement] end define define statement [includeStatement] | [keysStatement] | [compoundsStatement] | [commentsStatement]…
1
vote
1 answer

Parse large XML file in Python

Need some help with this. We have a large XML files from an API that I need to convert into a SQL Server table. Using pyodbc to load the table into SQL is no problem but I'm struggling to parse the 16mb XML file. The file is well formed - it is…
Daryl Heppner
  • 43
  • 1
  • 8
1
vote
0 answers

Different behaviour with cElementTree and ElementTree

In the below case we do not get same return types. One is with Element and other with xml.etree.ElementTree.Element Why is this difference ? import xml.etree.cElementTree as ET1 import xml.etree.ElementTree as ET2 import multiprocessing tree1 =…
RaviP
  • 49
  • 3
1
vote
1 answer

Parsing XML with cElementTree

I have been tasked with re-writing some old XML parsing code to Python and I stumbled into the joy that is cElementTree and I love it because I can do so much in so few lines. My experience level with xpath is not that extensive and this question…
Jane Wilkie
  • 1,703
  • 3
  • 25
  • 49
1
vote
1 answer

Why won't this check for an element work using python elementtree

I finally decided to learn how to parse xml in python. I'm using elementtree just to get a basic understanding. I'm on CentOS 6.5 using python 2.7.9. I've looked through the following…
user1070061
  • 473
  • 2
  • 5
  • 11
1
vote
1 answer

python 2.7 xml.etree.cElementTree memory use

I created a small tool for my job, it parses xml files to find the text of an element; example code: import xml.etree.cElementTree as Etree def open_xml(): """ Retrieves info from the xml file """ try: tree =…
Simon TheChain
  • 277
  • 1
  • 16
1
vote
0 answers

How to parse XML in python using the cElementTree?

I am trying to parse the xml using the cElementTree library in python.But when i am trying to run the program it gives me error. #!/usr/bin/python import os import xml.etree.ElementTree as etree filename =…
wandermonk
  • 6,856
  • 6
  • 43
  • 93
1
vote
0 answers

Fastest method for SAX parsing in Python

I have an XML document (1.5MB) that needs to be parsed in real-time for a web service that I am developing. I am using the cElementTree Python library which, according to this post, is the preferred way to parse XML in Python, but I'm not sure if…
arimbun
  • 3,885
  • 2
  • 19
  • 16
0
votes
3 answers

Django soaplib error

I'm trying to make a little "Hello World" webservice with Django following a few tutorials, but I'm hitting the same barrier over and over. I've defined a view.py and soaplib_handler.py: view.py: from soaplib_handler import DjangoSoapApp,…
niklassaers
  • 8,480
  • 20
  • 99
  • 146
0
votes
0 answers

How to get the ElementTree.toString method to output a non breaking space (nbsp)?

How can I get the ElementTree.toString method to output   from a node's text attribute? import xml.etree.cElementTree as ET node = ET.Element("node") node.text = "hello there" print(ET.tostring(node, encoding = 'utf8', method = "xml",…
Sam
  • 616
  • 7
  • 19
0
votes
1 answer

Python - XML: Separating siblings per parent

Currently I am struggling to find the proper answer to this, so it would be great if someone could help me solve this. I have a deeper XML which I want to convert into a table. the XML looks like this:
0
votes
1 answer

Python - Request GZ file and Parsing XML

I started learning Python a few days ago in order to build a basic site in order to compile some statistics from BOINC projects eg SETI@home etc. Basically the site does: Download gz files Uncompress gz files into xml files Build xml info into…
Chris
  • 81
  • 12