From 71ddf0fc9f7ed4545c374585e96e9fbdbcf9738f Mon Sep 17 00:00:00 2001 From: "Sean E. Millichamp" Date: Mon, 10 Aug 2015 08:53:51 -0400 Subject: [PATCH] Support multiple occurrence of a XML node This patch adds support for a SOAP response where a multi-valued response may be presented in multiple occurrences of the named node. --- AUTHORS.md | 1 + pysimplesoap/simplexml.py | 4 +++- tests/simplexmlelement_test.py | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/AUTHORS.md b/AUTHORS.md index 46056066..73907cc5 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -40,3 +40,4 @@ Patches and Suggestions - jpc - Luka Birsa - Bill Bennert @billwebreply +- Sean E. Millichamp diff --git a/pysimplesoap/simplexml.py b/pysimplesoap/simplexml.py index 01f884b1..3fe52ccd 100644 --- a/pysimplesoap/simplexml.py +++ b/pysimplesoap/simplexml.py @@ -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() diff --git a/tests/simplexmlelement_test.py b/tests/simplexmlelement_test.py index 4c03e22d..333a900a 100644 --- a/tests/simplexmlelement_test.py +++ b/tests/simplexmlelement_test.py @@ -141,6 +141,29 @@ def test_tuple_unmarshall(self): )}} self.eq(span.unmarshall(d), e) + def test_multiple_element_unmarshall_one(self): + xml = """ + + bar + + """ + 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 = """ + + bar + baz + + """ + span = SimpleXMLElement(xml) + d = {'results': {'foo': [str]}} + e = {'results': {'foo': ['bar', 'baz']}} + self.eq(span.unmarshall(d), e) + def test_basic(self): span = SimpleXMLElement( 'pyar'