Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple occurrence of a XML node #84

Merged
merged 1 commit into from Jan 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.md
Expand Up @@ -40,3 +40,4 @@ Patches and Suggestions
- jpc <jpc@alumni.rice.edu>
- Luka Birsa
- Bill Bennert @billwebreply
- Sean E. Millichamp
4 changes: 3 additions & 1 deletion pysimplesoap/simplexml.py
Expand Up @@ -385,7 +385,9 @@ def unmarshall(self, types, strict=True):
if isinstance(fn, list):
# append to existing list (if any) - unnested dict arrays -
value = d.setdefault(name, [])
children = node.children()
# If the node has no children then the node itself might
# have multiple occurrences:
children = node.children() or node
# TODO: check if this was really needed (get first child only)
##if len(fn[0]) == 1 and children:
## children = children()
Expand Down
23 changes: 23 additions & 0 deletions tests/simplexmlelement_test.py
Expand Up @@ -141,6 +141,29 @@ def test_tuple_unmarshall(self):
)}}
self.eq(span.unmarshall(d), e)

def test_multiple_element_unmarshall_one(self):
xml = """
<results>
<foo>bar</foo>
</results>
"""
span = SimpleXMLElement(xml)
d = {'results': {'foo': [str]}}
e = {'results': {'foo': ['bar']}}
self.eq(span.unmarshall(d), e)

def test_multiple_element_unmarshall_two(self):
xml = """
<results>
<foo>bar</foo>
<foo>baz</foo>
</results>
"""
span = SimpleXMLElement(xml)
d = {'results': {'foo': [str]}}
e = {'results': {'foo': ['bar', 'baz']}}
self.eq(span.unmarshall(d), e)

def test_basic(self):
span = SimpleXMLElement(
'<span><a href="python.org.ar">pyar</a>'
Expand Down