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 retrieve value from deeper nesting in xml file?

I'm having trouble getting the Administrators value from a <\q4:Member> nest. I have a file generated with the command ssh PC03 "gpresult /scope computer /x:\\VBoxSvr\Exchange\PC03.xml in which the GPO settings from ADDC are…
Kubix
  • 73
  • 7
0
votes
0 answers

ET.iterparse is not loading all XML tags inside a specifc tag in python with xml.etree.ElementTree

My code: tree = ET.iterparse(file_path, events=('start',)) for _, elem in tree: if 'product' in elem.tag: if elem.attrib.get('product-id') == "B4_1003847_000": print(ET.tostring(elem)) …
Shaida Muhammad
  • 1,428
  • 14
  • 25
0
votes
1 answer

Is there a way to preserve newlines in attribute strings in XML while manipulating the XML with a python script?

According to (for instance) this discussion, newlines in strings in XML files are allowed. I have such a file and I need to manipulate it. To be specific, From certain subelements with an existing id, I need to create duplicates with a new id. I…
gctwnl
  • 217
  • 1
  • 8
0
votes
1 answer

Get information from xml with element tree

I am trying to use elementTree to get at information in an xml response. The response xmlresponse.xml looks like: 1
abinitio
  • 609
  • 6
  • 20
0
votes
0 answers

Editing L5X file with xml.etree.ElementTree

I've used xml.etree.ElementTree and can parse through a L5XX with no problem but when I go to make a change to it, it breaks it. " It changes the text but…
0
votes
1 answer

scraping xml data using import lxml.etree as ElementTree

I am trying to learn how to scrape a website using XML. I am quite familiar with html but I noticed some of the websites I attempt to scrape have XML API's. If I am not mistaken it is faster and fairly simpler to scrape. I have the following sample…
pyj
  • 55
  • 6
0
votes
0 answers

remove ns0 from XML using python lxml etree

I'm using Python LXML etree to parse XML addenda and I need to get rid of ns0 NAMESPACE I already tried the solution described in the link below but did not get the result I'm looking for. Remove namespace and prefix from xml in python using lxml My…
Hugo
  • 3
  • 2
0
votes
1 answer

Remove XML element attribute with namespace

I want to remove an attribute of a specific element, which includes a namespace. In the following element: I want to remove xsi:nil="true" in order to add a value to the element, Country Code in later…
0
votes
1 answer

XML : lxml.etree - findall() when document element has attributes

.findall() doesn't find anything when the document element has attributes. Why this behavior and how to solve it? Here is the code: from lxml import etree as et text = '''\
macxpat
  • 173
  • 2
  • 11
0
votes
2 answers

How to add new element in nested xml based on parent tag name in python

I have config.json file i need to generate xml file based on config file my config file looks like. { "Elements": [ { "Element type": "root", "Element name": "root_element" }, { "Element…
dp808139
  • 122
  • 2
  • 12
0
votes
0 answers

How to edit and retain CDATA section with ElementTree?

I am working with an xml file which uses CDATA in some of the tags. I wish to edit the contents of CDATA but the ElementTree parser removes the CDATA from output xml Sample input xml: decimal to…
0
votes
1 answer

Python and XML: update specific value

I have to work with some XML file which seems weirdly sparse compared to what I saw in tutorials. text text2 v3 How to…
Benji_90210
  • 25
  • 1
  • 7
0
votes
0 answers

how to edit XML file in python

I have an XML file that I need to change only 2 attributes inside :
Ahmed Wagdi
  • 3,913
  • 10
  • 50
  • 116
0
votes
0 answers

How to write geopandas data into osm.pbf file using python?

I have sample nodes, edges data like below. I am using ElementTree to write the data into .osm file and then trying to convert into .osm.pbf using osmosis but when trying to convert from .osm to .osm.pbf osmosis throws error saying "osm format is…
data en
  • 431
  • 1
  • 2
  • 9
0
votes
0 answers

Modify (add subElements) to a xml and save it with ElementTree

I know there are different similar topics on StackOverflow but I cannot figure out the problem on my example. I have a template xml file. I want to use this template to add new subelements and save a new (modified) xml file. Input xml file The input…
pklein
  • 3
  • 4