objectify.fromstring using parser from objectify.makeparser does not produce objectified objects

Bug #1416853 reported by Anentropic on 2015-02-01
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lxml
Undecided
Unassigned

Bug Description

In the docs:

```
>>> root = objectify.fromstring('<test/>')
>>> print(isinstance(root, objectify.ObjectifiedElement))
True
```

Works as above for me.

But when I use a parser it no longer works:

```
schema = etree.XMLSchema(ebay_schema) # from xsd schema
parser = objectify.makeparser(schema=schema)

In [56]: root = objectify.fromstring('<test/>', parser=parser)

In [57]: isinstance(root, objectify.ObjectifiedElement)
Out[57]: False
```

I don't see this mentioned in the docs and I would expect `objectify.fromstring` using a parser from `objectify.makeparser` to produce objectified elements.

Python : sys.version_info(major=2, minor=7, micro=9, releaselevel='final', serial=0)
lxml.etree : (3, 4, 1, 0)
libxml used : (2, 9, 0)
libxml compiled : (2, 9, 0)
libxslt used : (1, 1, 28)
libxslt compiled : (1, 1, 28)

Anentropic (anentropic) wrote :

Furthermore, there is this example in the docs, which doesn't work:

```
>>> xml = "<a><b>test</b></a>"
>>> a = objectify.fromstring(xml, parser)

>>> print(a.b)
test
```

when I try it:

```
In [65]: xml = "<a><b>test</b></a>"

In [66]: a = objectify.fromstring(xml, parser=p)

In [67]: a.b
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-67-8c3e650d746c> in <module>()
----> 1 a.b

AttributeError: 'lxml.etree._Element' object has no attribute 'b'
```

...because it is not returning objectified elements

scoder (scoder) wrote :

Both work just fine on my side. There must be something else going on on your side. Could you try the examples from a clean Python session? Maybe your initial (I)Python session setup is changing something in lxml's global configuration?

Anentropic (anentropic) wrote :

hmm, I can't reproduce either now

what sort of thing would I have to do to change the lxml config in that way?

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers