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:
from flask import Flask
from flask_spyne import Spyne
from spyne.protocol.soap import Soap11
from spyne.model.primitive import Unicode, Integer, Float, DateTime
from spyne.model.complex import Iterable
app = Flask(__name__)
spyne = Spyne(app)
__service_url_path__ = '/soap/oracleservice';
__in_protocol__ = Soap11(validator='lxml');
__out_protocol__ = Soap11();
@spyne.srpc(DateTime, DateTime, _returns="What to put here?")
def oracle(DATE_INCOME, DATE_ISSUE):
#from OracleDB_Procedure import UlozeniDoXML
s = open("Databaze.xml");
if __name__ == '__main__':
app.run(host = '127.0.0.1');
If you want to return it as a regular string inside a document, you must set your _return type to
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
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.