I have Flask-Spyne server (web service) and I want to return (return to client after he will ask) a XML file.
I want to do this:
Is there a way how to do it?
Here is mine code:
class Service(spyne.Service):
__service_url_path__ = '/soap';
__in_protocol__ = Soap11(validator='lxml');
__out_protocol__ = Soap11();
@spyne.srpc(DateTime, DateTime, _returns="What to put here?")
def Function(A,B):
GetXML(A,B)
s = open("file.xml");
return s;
if __name__ == '__main__':
app.run(host = '127.0.0.1');
Thank You very much for any help.. :)
EDIT:
So, this is mine code now: (sending string)
@spyne.srpc(DateTime, DateTime, _returns=Iterable(Unicode))
def oracle(A,B):
GetXML(A,B)
s = open("file.xml");
return s
If you want to return it as a regular string inside a document, you must set your _return type to Unicode
.
If you want to return it as an xml document, you must parse it (etree.parse("Databaze.xml")
) and return the resulting ElementTree instance. Your return type in this case should be AnyXml
.
Also see these examples:
Sending as string isolates your document from parent context. It's a bit more inefficient (e.g. <
character becomes <
) but otherwise harmless.
Sending as document makes your document part of the SOAP message. It's more efficient but makes it inherit namespace prefixes from the parent document which may cause slight changes to the document -- i.e. what you put in and what you get back out may not be equal byte-for-byte (but equivalent nevertheless).
It totally depends on the use case. If in doubt, return as string.