Skip to content

Commit

Permalink
Merge pull request #84 from seanmil/multoccurrence
Browse files Browse the repository at this point in the history
Support multiple occurrence of a XML node
  • Loading branch information
reingart committed Jan 12, 2016
2 parents 2ffb9ab + 71ddf0f commit e7e688d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
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

0 comments on commit e7e688d

Please sign in to comment.