Questions tagged [elementtree]

ElementTree is a Python library for creating and parsing XML.

ElementTree is a Python library for creating and parsing XML.

from xml.etree import ElementTree

An alternative implementation on top of libxml and libxslt, with an expanded API is lxml, see the tag.

2858 questions
0
votes
2 answers

How To conserve XML declaration from read file using xml.etree.ElementTree

I am reading an xml file, adding some tags and writing it. The file i read have my output only has I use the following Code import os from xml.dom import minidom import…
Marc
  • 199
  • 8
0
votes
3 answers

Parsing xml file with Python using root.iter does not list text

I am trying to use Python to parse an xml file. I would like to identify text which occurs between specified xml tags. The code I am running is import xml.etree.ElementTree as ET tree = ET.parse('020012_doctored.xml') root = tree.getroot() for w in…
Nick Riches
  • 317
  • 2
  • 13
0
votes
0 answers

How to duplicate a node in xml.etree?

I'm using xml.etree module to parse an xml file. While handling the Element Tree, I need to operate on a node in it, without changing the data stored in the tree. Hence I want to duplicate the node. To be more specific, let's say there is a node a,…
OrthoPole
  • 3
  • 1
0
votes
0 answers

Python etree failed to parse html text (return NoneType)

Why is the output "None"? It was supposed to be like "" or something else. Notice : Only on my Mac it has something wrong. I have tried use pyenv to create a virtualenv with python3.9.6, it also does not work. Here's…
xzajyjs
  • 13
  • 3
0
votes
0 answers

Python ElementTree if elif else statement different child elements and values

For extracting data out of a HTML-file (CAMT-format), I have the following code: def create_entry(filename): root = parse_getroot(filename)[0] ns = create_namespace(filename) for child in root: for layer in child.findall(ns +…
0
votes
0 answers

Using lxml.etree to transform XML using an XSL with XPATH 2.0 function(s)

import lxml.etree as ET dom = ET.parse(xml_filename) xslt = ET.parse(xsl_filename) transform = ET.XSLT(xslt) newdom = transform(dom) print(ET.tostring(newdom, pretty_print=True)) Returns: ... XSLTParseError: xsl:for-each : could not compile select…
Srappel
  • 13
  • 1
  • 6
0
votes
0 answers

Can't print nested list in an XML from an API

This is the results of an API request (truncated for space and focus) { "bib": [ { "mms_id": "################", "record_format": "marc21", "network_number": [ "(OCoLC)########", "(OCoLC)########", …
czellib
  • 1
  • 1
0
votes
0 answers

XML Parsing painfully slow

I'm current parsing 4 different XML files, each around 500MB. I expect around 30'/file, but it took so long for just 1 (7 hours to be exact), and somehow loops on itself. Any ideas on how to optimize the code? I've been looking on the web for a…
0
votes
0 answers

xml tag and text not being found using widcard

I have blocks of xml like so:
pymat
  • 1,090
  • 1
  • 23
  • 45
0
votes
2 answers

Get image url sub-element using Python Elementree

I have the following xml format. I can get the title and link easily enough, but am getting stuck on how I can get the img src out of the content. A title
0
votes
1 answer

Python elementtree append new node: '>' in the text gets modified to >

I'm trying to add a new node to an existing xml. The node I'm adding looks like this: This is working. Some time the node looks like this:
Fran
  • 15
  • 5
0
votes
2 answers

How to force ElementTree to look in a specific directory for xml files?

I have been trying to get ElementTree(ET) to look for xml files in a specific directory which the user will point to, however I found out that ET is only searching for that xml file in the directory of the script itself. How can I force ET to look…
Avila
  • 31
  • 6
0
votes
2 answers

Add Markup Declaration while using ElementTree

Certain xml specifications require a markup declaration to perform a task. One such example is below; a conditional to check a framework version in Wix
0
votes
0 answers

Problem generating and verifying signature with signxml in python (namespaces and signature)

sorry for my english firstly. I'm taking my first steps with signxml in Python, and from the articles I've seen it looks quite easy to use, but I haven't been able to correctly sign the document as I need it. I was looking at the documentation and…