@@ -27,51 +27,63 @@ public class XPathParser {
27
27
private XPath xpath ;
28
28
29
29
public XPathParser (String xml ) {
30
- commonConstructor (createDocument (new StringReader (xml )), false , null , null );
30
+ commonConstructor (false , null , null );
31
+ this .document = createDocument (new StringReader (xml ));
31
32
}
32
33
33
34
public XPathParser (Reader reader ) {
34
- commonConstructor (createDocument (reader ), false , null , null );
35
+ commonConstructor (false , null , null );
36
+ this .document = createDocument (reader );
35
37
}
36
38
37
39
public XPathParser (Document document ) {
38
- commonConstructor (document , false , null , null );
40
+ commonConstructor (false , null , null );
41
+ this .document = document ;
39
42
}
40
43
41
44
public XPathParser (String xml , boolean validation ) {
42
- commonConstructor (createDocument (new StringReader (xml )), validation , null , null );
45
+ commonConstructor (validation , null , null );
46
+ this .document = createDocument (new StringReader (xml ));
43
47
}
44
48
45
49
public XPathParser (Reader reader , boolean validation ) {
46
- commonConstructor (createDocument (reader ), validation , null , null );
50
+ commonConstructor (validation , null , null );
51
+ this .document = createDocument (reader );
47
52
}
48
53
49
54
public XPathParser (Document document , boolean validation ) {
50
- commonConstructor (document , validation , null , null );
55
+ commonConstructor (validation , null , null );
56
+ this .document = document ;
51
57
}
52
58
53
59
public XPathParser (String xml , boolean validation , Properties variables ) {
54
- commonConstructor (createDocument (new StringReader (xml )), validation , variables , null );
60
+ commonConstructor (validation , variables , null );
61
+ this .document = createDocument (new StringReader (xml ));
55
62
}
56
63
57
64
public XPathParser (Reader reader , boolean validation , Properties variables ) {
58
- commonConstructor (createDocument (reader ), validation , variables , null );
65
+ commonConstructor (validation , variables , null );
66
+ this .document = createDocument (reader );
59
67
}
60
68
61
69
public XPathParser (Document document , boolean validation , Properties variables ) {
62
- commonConstructor (document , validation , variables , null );
70
+ commonConstructor (validation , variables , null );
71
+ this .document = document ;
63
72
}
64
73
65
74
public XPathParser (String xml , boolean validation , Properties variables , EntityResolver entityResolver ) {
66
- commonConstructor (createDocument (new StringReader (xml )), validation , variables , entityResolver );
75
+ commonConstructor (validation , variables , entityResolver );
76
+ this .document = createDocument (new StringReader (xml ));
67
77
}
68
78
69
79
public XPathParser (Reader reader , boolean validation , Properties variables , EntityResolver entityResolver ) {
70
- commonConstructor (createDocument (reader ), validation , variables , entityResolver );
80
+ commonConstructor (validation , variables , entityResolver );
81
+ this .document = createDocument (reader );
71
82
}
72
83
73
84
public XPathParser (Document document , boolean validation , Properties variables , EntityResolver entityResolver ) {
74
- commonConstructor (document , validation , variables , entityResolver );
85
+ commonConstructor (validation , variables , entityResolver );
86
+ this .document = document ;
75
87
}
76
88
77
89
public void setVariables (Properties variables ) {
@@ -170,6 +182,7 @@ private Object evaluate(String expression, Object root, QName returnType) {
170
182
}
171
183
172
184
private Document createDocument (Reader reader ) {
185
+ // important: this must only be called AFTER common constructor
173
186
try {
174
187
DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance ();
175
188
factory .setValidating (validation );
@@ -200,11 +213,10 @@ public void warning(SAXParseException exception) throws SAXException {
200
213
}
201
214
}
202
215
203
- private void commonConstructor (Document document , boolean validation , Properties variables , EntityResolver entityResolver ) {
216
+ private void commonConstructor (boolean validation , Properties variables , EntityResolver entityResolver ) {
204
217
this .validation = validation ;
205
218
this .entityResolver = entityResolver ;
206
219
this .variables = variables ;
207
- this .document = document ;
208
220
XPathFactory factory = XPathFactory .newInstance ();
209
221
this .xpath = factory .newXPath ();
210
222
}
0 commit comments