Skip to content

Commit

Permalink
#251: XML parser should respect HapiContext it has been obtained from…
Browse files Browse the repository at this point in the history
… (including validation)
  • Loading branch information
ohr committed Oct 16, 2018
1 parent 0bbbdbf commit f17db02
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ public Message parseDocument(Document xmlMessage, String version) throws HL7Exce
assertNamespaceURI(xmlMessage.getDocumentElement().getNamespaceURI());

Message message = instantiateMessage(xmlMessage.getDocumentElement().getLocalName(), version, true);
// Note: this will change in future to reuse the Parser's/HapiContext's
// ValidationContext.
// message.setValidationContext(getValidationContext());
// Set parser before parsing the contents actually starts in order to respect
// the settings of the HapiContext
message.setParser(this);
parse(message, xmlMessage.getDocumentElement());
return message;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ca.uhn.hl7v2.parser;

import ca.uhn.hl7v2.DefaultHapiContext;
import ca.uhn.hl7v2.HapiContext;
import ca.uhn.hl7v2.model.Message;
import org.junit.Test;

/**
* @author Christian Ohr
*/
public class ValidatingParserTest {

@Test
public void testValidation() throws Exception {
String inValidMessage = "MSH|^~\\&|MedSeries|CAISI_1-2|PLS|3910|200903230934||ADT^A31^ADT_A05|75535037-1237815294895|P^T|2.4\r"
+ "EVN|A31|THIS-IS-NOT-DATE-VALUE\r"
+ "PID|1||29^^CAISI_1-2^PI~\"\"||Test300^Leticia^^^^^L||19770202|M||||||||||||||||||||||";

HapiContext context = new DefaultHapiContext();
context.getParserConfiguration().setValidating(false); // disable validation
PipeParser parser = context.getPipeParser();
Message hapiMsg = parser.parse(inValidMessage); // successfull parsed
XMLParser xmlParser = context.getXMLParser();
String xmlDoc = xmlParser.encode(hapiMsg,"XML");
xmlParser.parse(xmlDoc); // validation still disabled
}
}

0 comments on commit f17db02

Please sign in to comment.