Questions tagged [lxml.objectify]
48 questions
9
votes
2 answers
Test the existence of an Element with lxml.objectify
What is the standard way for testing if an element exists or not with lxml.objectify ?
Sample XML :
sdfsdfdsfd
Code
from lxml import etree, objectify
with…

Basj
- 41,386
- 99
- 383
- 673
4
votes
2 answers
Setting values without pytype - lxml objectify
Setting values to an element using the objectify API of the lxml library, assigns the auto detected pytype to that element and the required namespaces, by default.
For example, setting the root element:
root =…

pgmank
- 5,303
- 5
- 36
- 52
3
votes
1 answer
How to get parent path of lxml.etree._ElementTree object
Using lxml library I have objectified some elements (sample code below)
config = objectify.Element("config")
gui = objectify.Element("gui")
color = objectify.Element("color")
gui.append(color)
config.append(gui)
config.gui.color.active =…

Jan Pips
- 113
- 1
- 3
- 11
3
votes
1 answer
lxml - unable to replace children of children
I'm using lxml as a solution for XML parsing in my application.
I understand that lxml can only replace the immediate child of a parent, but no levels under that child using .replace
Example XML:

Varun Verma
- 213
- 3
- 12
3
votes
1 answer
lxml.objectify and leading zeros
When the objectify element is printed on the console, the leading zero is lost, but it is preserved in the .text:
>>> from lxml import objectify
>>>
>>> xml = "01"
>>> a = objectify.fromstring(xml)
>>> print(a.b)
1
>>>…

alecxe
- 462,703
- 120
- 1,088
- 1,195
3
votes
1 answer
dir(element) returns non-existing element. Trying to use getattr(element, ...) fails
Basically what i do is:
attrs = dir(oe)
for attr in attrs:
attr_obj = getattr(oe, attr)
.... more code ...
but the getattr call fails with: AttributeError: no such child: comment
oe is an ObjectifiedElement of the lxml.objectify library.
When…

RedX
- 14,749
- 1
- 53
- 76
3
votes
2 answers
How do you create a non-nested xml element using Python's lxml.objectify?
My current code is
xml_obj = lxml.objectify.Element('root_name')
xml_obj[root_name] = str('text')
lxml.etree.tostring(xml_obj)
but this creates the following xml:
text
In the application I am using…

SegFaults McGee
- 321
- 2
- 13
3
votes
1 answer
Getting valueless elements in python lxml
I've been trying to use the lxml package's "objectify" to parse my XMLs and I've come across a problem. If I have a valueless tag, I can't seem to find a way to get its attributes.
For instance:
import lxml.objectify
xml_obj =…

KimiNewt
- 501
- 3
- 14
2
votes
3 answers
Convert a dot notation string to object to access lxml objects python
I am trying to update the xml using object notation using lxml objectify.
I am trying to add another fruit called mango using lxml objectify like
root =…

Vinay
- 470
- 1
- 5
- 18
2
votes
1 answer
Mutiple same tag names and lxml.objectify
I have been noticing a little issue with lxml.objetify. I am getting XLM as a string. The XLM presents an structure like shown down below:
-
1
…

manespgav
- 167
- 1
- 9
2
votes
1 answer
lxml iterparse with objectify
How to parse a big XML file and process its elements as ObjectifiedElement (using objectify parser).
I didn't find any better solution than :
from lxml import etree, objectify
for event, elt in etree.iterparse('onebigfile.xml', tag='MyTag'):
…

ElBidoule
- 169
- 1
- 2
- 9
2
votes
1 answer
lxml.objectify.parse fails while fromstring works
Struggling on why lxml.objectify.parse is failing when I use a file IO but not a string IO.
The following code works:
with open(logPath,'r', encoding='utf-8') as f:
xml = f.read()
root = objectify.fromstring(xml)
print(root.tag)
The…

frankr6591
- 1,211
- 1
- 8
- 14
2
votes
1 answer
lxml.objectify can not parse attrib without quotes - need recover=Ttrue
Does anyone have any tips on how to use lxml.objectify with recover=True?
I have xml where the attributes are not quoted --> name=value instead of name='value'.
Below is some sample code... I do not have control over the XML formatting so I can not…

frankr6591
- 1,211
- 1
- 8
- 14
2
votes
1 answer
Change int element to str element in lxml objectify python
Hope someone can help.
I am using lxml objectify to parse xml, which is returned from a third party integration using objectify.fromstring(). I have one element in my xml which sometimes consists of ints 0-9 only, when it is ints only the leading…

Billy
- 69
- 1
- 9
2
votes
1 answer
Error validating/parsing xml file against xsd with lxml/objectify in Python
in Python/Django, I need to parse and objectify a file .xml according to a given XMLSchema made of three .xsd files referring each other in such a way:
schema3.xsd (referring schema1.xsd)
schema2.xsd (referring schema1.xsd)
schema1.xsd (referring…

3biano
- 21
- 4