{ "metadata": { "name": "xmlsnippet" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "We are making this xml snippet" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "\n", "\tjOOst\n", "\tjOOst\n", "\t127.0.0.1\n", "\thttp://dtvirt5.deltares.nl/wps/\n", "\twebIDT_ToolInitialise\n", "\tInteractive Dredge Planning Tool\n", "\tIDT_Singapore\n", "" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import lxml.builder\n", "import lxml.etree\n", "import cStringIO" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "E = lxml.builder.ElementMaker()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "# Define all the elements that we need \n", "# using the somewhat odd syntax of the ElementMaker\n", "xml = E.xml\n", "sessionID = E.sessionID\n", "uniqueID = E.uniqueID\n", "IP = E.IP\n", "weburl = E.weburl\n", "function = E.function\n", "tool = E.tool\n", "toolid = E.toolid" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "code", "collapsed": false, "input": [ "doc = xml(\n", " uniqueID(\"jOOst\"),\n", " sessionID(\"jOOst\"),\n", " IP(\"127.0.0.1\"),\n", " weburl(\"http://dtvirt5.deltares.nl/wps\"),\n", " function(\"webIDT_ToolInitialise\"),\n", " tool(\"Interactive Dredge Planning Tool\"),\n", " toolid(\"IDT_Singapore\")\n", " )\n", "\n", "\n", " \n", " " ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 4 }, { "cell_type": "code", "collapsed": false, "input": [ "doctxt = lxml.etree.tostring(doc, pretty_print=True)\n", "f = cStringIO.StringIO(doctxt)\n", "f.seek(0)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 5 }, { "cell_type": "code", "collapsed": false, "input": [ "# save f to ftp" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 6 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 6 } ], "metadata": {} } ] }