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
9
votes
3 answers

How to retrieve the parent node using cElementTree?

for the xml data1 data2 I need the list containing tuples of parent,data for each parent in xml. Is there a way to do it USING…
Mohit Ranka
  • 4,193
  • 12
  • 41
  • 41
7
votes
1 answer

Modify a XML using ElementTree

Sam/Astronaut I want to modify the above XML by adding another child tag inside parent tag. I'm doing something like this.. tree =…
nick01
  • 333
  • 1
  • 8
  • 19
5
votes
1 answer

Iterparse object has no attribute next

I am parsing a 700mb file, I have the following code with works fine on my test file without the line context.iter(context) and event, elem = context.next(). form xml.etree import cElementTree as ET source = ("AAT.xml") context =…
ADWALSH
  • 75
  • 1
  • 4
4
votes
1 answer

ElementTree / cElementTree difference?

I have a small xml-parsing python snippet that works with ElementTree, but not with cElementTree. Why is that? #!/usr/bin/python3 import sys import xml.etree.cElementTree as ET tree = ET.parse(sys.stdin) this raises the…
Fabian Henze
  • 980
  • 1
  • 10
  • 27
4
votes
2 answers

add element in a existing xml file python

I have a existing xml file as following:
Condo_programmer
  • 226
  • 1
  • 4
  • 12
4
votes
1 answer

How to get all text children of an element in cElementTree?

I'm using the cElementTree module in Python to get the text child of an XML tree, using the text property. But it seems to work only for the immediate text children (see below). $ python ... >>> import xml.etree.cElementTree as ET >>> root =…
Sumit
  • 2,242
  • 1
  • 24
  • 37
4
votes
3 answers

Which Python XML library should I use?

I am going to handle XML files for a project. I had earlier decided to use lxml but after reading the requirements, I think ElemenTree would be better for my purpose. The XML files that have to be processed are: Small in size. Typically < 10 KB.…
user225312
  • 126,773
  • 69
  • 172
  • 181
3
votes
6 answers

How to obtain the root of a tree without parsing the entire file?

I'm making an xml parser to parse xml reports from different tools, and each tool generates different reports with different tags. For example: Arachni generates an xml report with as tree root tag. nmap generates…
matta
  • 205
  • 2
  • 9
3
votes
1 answer

Python 2.7.11 in Visual Studio Throws Exception in cElementTree.py

I'm coding Python in Visual Studio 2015 which has worked great for the past few days, however this morning I decided to move the solution and directory to a GitHub-monitored directory on my Windows machine. Ever since I moved the solution and run it…
3
votes
1 answer

Using cElementTree in python 3

cElementTree is the fast, C implementation of the XML API ElementTree. In python 2 you would load it explicitly (aliasing it to ElementTree), but in the Python 3 docs I read this: Changed in version 3.3: This module will use a fast implementation…
alexis
  • 48,685
  • 16
  • 101
  • 161
3
votes
1 answer

Working with namespace while parsing XML using ElementTree

This is follow on question for Modify a XML using ElementTree I am now having namespaces in my XML and tried understanding the answer at Parsing XML with namespace in Python via 'ElementTree' and have the following. XML file.
nick01
  • 333
  • 1
  • 8
  • 19
3
votes
0 answers

Adding processing instruction to xml before root element with cElementTree

I am using cElementTree library to produce xml files. Now I want to write .xsl file for better readability. That's why I need to add before first tag. Unfortunately I was able to put desired line…
arbulgazar
  • 1,931
  • 1
  • 19
  • 24
3
votes
1 answer

How long should ElementTree iterparse take?

In answering another question, someone showed me the following tutorial, in which the author claims to have used iterparse to parse a ~100 MB XML file in under 3…
russell
  • 350
  • 1
  • 13
2
votes
2 answers

How can I know the parent of an element when using iterparse methode of cElementTree?

I want to loop trough the elements of an xml file and yield every element, unless the parent is a feature. So in pseudocode for event, element in cElementTree.iterparse('../test.xml'): if parentOf_element != 'feature': yield…
Niek de Klein
  • 8,524
  • 20
  • 72
  • 143
2
votes
1 answer

Type Element from xml.etree.cElementTree is not recognized in if statement

I'm using cElementTree to parse an xml file. Using the .getroot() function gives an element type as result. I want to use this type in an if statement if type(elementVariable) == 'Element': do stuff However, the type is not recognized when I…
Niek de Klein
  • 8,524
  • 20
  • 72
  • 143
1
2 3 4 5 6