Python/PyXB - Getting the value of “grandchild” element
up vote
0
down vote
favorite
My service provider gave me data using XML and XSD files and I'm trying to parse this data using PYXB library in Python.
I can access the root and child elements and attributes except for the grandchild element. I'd like to know how I can access the value of grandchild element(GenderValue).
Here is a part of xml file:
<Person id="10441" recordaction="add" date="10-Jul-2018">
<GenderDetails>
<Gender>
<ReferenceGroup ReferenceGroupCode="DJ"/>
<GenderValue>Male</GenderValue>
</Gender>
</GenderDetails>
Here is my python test code and result:
>>> for person in dj.Records.Person:
... if person.GenderDetails is not None:
... if person.GenderDetails.Gender is not None:
... print(person.GenderDetails.Gender)
... print(person.GenderDetails.Gender.GenderValue)
...
[<schema_DJ.CTD_ANON_14 object at 0x11b97afd0>]
Traceback (most recent call last):
File "<stdin>", line 5, in <module>
AttributeError: '_PluralBinding' object has no attribute 'GenderValue'
The result shows there are Gender object is in the memory and AttributeError. I don't know why it searched the attribute instead of the element. Thank you for your help in advance.
python xml parsing xsd pyxb
add a comment |
up vote
0
down vote
favorite
My service provider gave me data using XML and XSD files and I'm trying to parse this data using PYXB library in Python.
I can access the root and child elements and attributes except for the grandchild element. I'd like to know how I can access the value of grandchild element(GenderValue).
Here is a part of xml file:
<Person id="10441" recordaction="add" date="10-Jul-2018">
<GenderDetails>
<Gender>
<ReferenceGroup ReferenceGroupCode="DJ"/>
<GenderValue>Male</GenderValue>
</Gender>
</GenderDetails>
Here is my python test code and result:
>>> for person in dj.Records.Person:
... if person.GenderDetails is not None:
... if person.GenderDetails.Gender is not None:
... print(person.GenderDetails.Gender)
... print(person.GenderDetails.Gender.GenderValue)
...
[<schema_DJ.CTD_ANON_14 object at 0x11b97afd0>]
Traceback (most recent call last):
File "<stdin>", line 5, in <module>
AttributeError: '_PluralBinding' object has no attribute 'GenderValue'
The result shows there are Gender object is in the memory and AttributeError. I don't know why it searched the attribute instead of the element. Thank you for your help in advance.
python xml parsing xsd pyxb
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
My service provider gave me data using XML and XSD files and I'm trying to parse this data using PYXB library in Python.
I can access the root and child elements and attributes except for the grandchild element. I'd like to know how I can access the value of grandchild element(GenderValue).
Here is a part of xml file:
<Person id="10441" recordaction="add" date="10-Jul-2018">
<GenderDetails>
<Gender>
<ReferenceGroup ReferenceGroupCode="DJ"/>
<GenderValue>Male</GenderValue>
</Gender>
</GenderDetails>
Here is my python test code and result:
>>> for person in dj.Records.Person:
... if person.GenderDetails is not None:
... if person.GenderDetails.Gender is not None:
... print(person.GenderDetails.Gender)
... print(person.GenderDetails.Gender.GenderValue)
...
[<schema_DJ.CTD_ANON_14 object at 0x11b97afd0>]
Traceback (most recent call last):
File "<stdin>", line 5, in <module>
AttributeError: '_PluralBinding' object has no attribute 'GenderValue'
The result shows there are Gender object is in the memory and AttributeError. I don't know why it searched the attribute instead of the element. Thank you for your help in advance.
python xml parsing xsd pyxb
My service provider gave me data using XML and XSD files and I'm trying to parse this data using PYXB library in Python.
I can access the root and child elements and attributes except for the grandchild element. I'd like to know how I can access the value of grandchild element(GenderValue).
Here is a part of xml file:
<Person id="10441" recordaction="add" date="10-Jul-2018">
<GenderDetails>
<Gender>
<ReferenceGroup ReferenceGroupCode="DJ"/>
<GenderValue>Male</GenderValue>
</Gender>
</GenderDetails>
Here is my python test code and result:
>>> for person in dj.Records.Person:
... if person.GenderDetails is not None:
... if person.GenderDetails.Gender is not None:
... print(person.GenderDetails.Gender)
... print(person.GenderDetails.Gender.GenderValue)
...
[<schema_DJ.CTD_ANON_14 object at 0x11b97afd0>]
Traceback (most recent call last):
File "<stdin>", line 5, in <module>
AttributeError: '_PluralBinding' object has no attribute 'GenderValue'
The result shows there are Gender object is in the memory and AttributeError. I don't know why it searched the attribute instead of the element. Thank you for your help in advance.
python xml parsing xsd pyxb
python xml parsing xsd pyxb
asked Nov 7 at 17:51
user689072
1156
1156
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53195025%2fpython-pyxb-getting-the-value-of-grandchild-element%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown