1from __future__ import print_function
2import xml.dom
3import xml.dom.minidom
4import pyxb.utils.domutils
5from pyxb.utils import six
6import pyxb.namespace
7
8# Structure
9#import DWML
10#print 'Validating DWML'
11#DWML.Namespace.validateSchema()
12#print 'Validated DWML: types %s' % ("\n".join(six.iterkeys(DWML.Namespace.typeDefinitions()),)
13
14dom = xml.dom.minidom.parse(open('NDFDgen.xml', 'rb'))
15body_dom = dom.documentElement.firstChild.nextSibling.firstChild.nextSibling
16#print(body_dom)  # contains varying text in object description
17
18# Service interface types
19import ndfd
20
21# WSDL
22import pyxb.bundles.wssplat.wsdl11 as wsdl
23
24uri_src = open('ndfdXML.wsdl')
25doc = xml.dom.minidom.parse(uri_src)
26spec = wsdl.definitions.createFromDOM(doc.documentElement, process_schema=True)
27
28binding = spec.binding[0]
29print(binding.name)
30port_type = spec.portType[0]
31print(port_type.name)
32bop = binding.operationMap()[body_dom.localName]
33print(bop.toxml("utf-8").decode('utf-8'))
34pop = port_type.operationMap()[body_dom.localName]
35print(pop.toxml("utf-8").decode('utf-8'))
36input = pop.input
37print(input.toxml("utf-8").decode('utf-8'))
38print(type(input))
39print(input.message)
40im_en = input.message
41print(im_en)
42msg = im_en.message()
43#print(msg) # contains varying text in object description
44for p in msg.part:
45    print(p.toxml("utf-8").decode('utf-8'))
46msg_ns = pyxb.namespace.NamespaceForURI(body_dom.namespaceURI)
47print('%s %s' % (body_dom.namespaceURI, msg_ns))
48
49parts = msg.part
50nodes = body_dom.childNodes
51
52while parts and nodes:
53    p = parts.pop(0)
54    while nodes and (not (xml.dom.Node.ELEMENT_NODE == nodes[0].nodeType)):
55        nodes.pop(0)
56    assert nodes
57    n = nodes.pop(0)
58    if p.name != n.localName:
59        print('Desynchronized: part %s expected node %s' % (p.name, n.localName))
60        nodes.insert(0, n)
61        continue
62    print('%s %s' % (p.name, n.localName))
63
64#print '%s yielded %s' msg_ns
65
66#msg = spec.messageMap()
67#print msg
68
69#print req
70#dom_support =  req.toDOM(pyxb.utils.domutils.BindingDOMSupport())
71#dom_support.finalize()
72#print dom_support.document().toxml("utf-8")
73