19
19
20
20
import ast
21
21
22
- from SpiffWorkflow .bpmn .parser .node_parser import NodeParser , DEFAULT_NSMAP
22
+ from SpiffWorkflow .bpmn .parser .node_parser import NodeParser
23
23
from SpiffWorkflow .bpmn .parser .ValidationException import ValidationException
24
24
25
25
from SpiffWorkflow .bpmn .parser .util import xpath_eval
34
34
Rule ,
35
35
)
36
36
37
- def get_dmn_ns (node ):
38
- """
39
- Returns the namespace definition for the current DMN
40
-
41
- :param node: the XML node for the DMN document
42
- """
43
- nsmap = DEFAULT_NSMAP .copy ()
44
- if 'http://www.omg.org/spec/DMN/20151101/dmn.xsd' in node .nsmap .values ():
45
- nsmap ['dmn' ] = 'http://www.omg.org/spec/DMN/20151101/dmn.xsd'
46
- elif 'http://www.omg.org/spec/DMN/20180521/DI/' in node .nsmap .values ():
47
- nsmap ['dmn' ] = 'http://www.omg.org/spec/DMN/20180521/DI/'
48
- elif 'https://www.omg.org/spec/DMN/20191111/MODEL/' in node .nsmap .values ():
49
- nsmap ['dmn' ] = 'https://www.omg.org/spec/DMN/20191111/MODEL/'
50
- return nsmap
51
37
52
38
class DMNParser (NodeParser ):
53
39
"""
@@ -79,20 +65,20 @@ def __init__(self, p, node, nsmap, svg=None, filename=None):
79
65
self .filename = filename
80
66
81
67
def parse (self ):
82
- self .decision = self ._parse_decision (self .node . findall ( '{*} decision' ))
68
+ self .decision = self ._parse_decision (self .xpath ( './/dmn: decision' ))
83
69
84
70
@property
85
71
def bpmn_id (self ):
86
72
"""
87
73
Returns the process ID
88
74
"""
89
- return self .node . findall ( '{*} decision[1]' )[0 ].get ('id' )
75
+ return self .xpath ( 'dmn: decision[1]' )[0 ].get ('id' )
90
76
91
77
def get_name (self ):
92
78
"""
93
79
Returns the process name (or ID, if no name is included in the file)
94
80
"""
95
- return self .node . findall ( '{*} decision[1]' )[0 ].get ('name' )
81
+ return self .xpath ( 'dmn: decision[1]' )[0 ].get ('name' )
96
82
97
83
def _parse_decision (self , root ):
98
84
decision_elements = list (root )
@@ -115,7 +101,7 @@ def _parse_decision(self, root):
115
101
return decision
116
102
117
103
def _parse_decision_tables (self , decision , decisionElement ):
118
- for decision_table_element in decisionElement .findall ('{*} decisionTable' ):
104
+ for decision_table_element in decisionElement .findall ('dmn: decisionTable' , namespaces = self . nsmap ):
119
105
name = decision_table_element .attrib .get ('name' , '' )
120
106
hitPolicy = decision_table_element .attrib .get ('hitPolicy' , 'UNIQUE' ).upper ()
121
107
decision_table = DecisionTable (decision_table_element .attrib ['id' ],
@@ -146,12 +132,11 @@ def _parse_inputs_outputs(self, decisionTable,
146
132
147
133
def _parse_input (self , input_element ):
148
134
type_ref = None
149
- prefix = self .nsmap ['dmn' ]
150
- xpath = xpath_eval (input_element , {'dmn' : prefix })
135
+ xpath = xpath_eval (input_element , self .nsmap )
151
136
expression = None
152
137
for input_expression in xpath ('dmn:inputExpression' ):
153
138
type_ref = input_expression .attrib .get ('typeRef' , '' )
154
- expression_node = input_expression .find ('{' + prefix + '} text' )
139
+ expression_node = input_expression .find ('dmn: text' , namespaces = self . nsmap )
155
140
if expression_node is not None :
156
141
expression = expression_node .text
157
142
0 commit comments