问题
I had downloaded "Validation Pack" from http://www.hl7.org/implement/standards/fhir/downloads.html.
After unzip 'validator.zip' and read 'readme.txt', I tried to run 'org.hl7.fhir.validator.jar' file on Windows Command Prompt.
java -jar org.hl7.fhir.validator.jar mysourcefile.xml
I encountered the following error:
java.lang.Exception: Unknown command 'mysourcefile.xml' at org.hl7.fhir.instance.test.ToolsHelper.main(ToolsHelper.java:77) java.lang.ArrayIndexOutOfBoundsException: 1 at org.hl7.fhir.instance.test.ToolsHelper.main(ToolsHelper.java:81)
Why is 'mysourcefile.xml' an unknown command? Please help. Thanks!
回答1:
The jar file is set up to load the wrong class. The correct class is org.hl7.fhir.instance.validation.Validator.
You can name that class explicitly when you run the jar, and you'll get the help, which will say:
Usage: FHIRValidator.jar [source] (-defn [definitions]) (-output [output]) (-noxslt)
you'll got more documentation as well.
Else you edit the manifest inside the jar and change the main class.
回答2:
If you want to validate your resource against the base specification run the following command:
java -jar org.hl7.fhir.validator.jar your-fhir-resource.xml -defn validation.zip
If you want to validate your resource against a profile (structure definition) run the following command:
java -jar org.hl7.fhir.validator.jar your-fhir-resource.xml -defn validation.zip -profile your-structure-definition.xml
回答3:
Updated docmentation
Validation Instructions:
- You need java 1.7 jre or jdk installed
- Download the validator tool and the validation pack (java executable, and dictionary of FHIR definitions, respectively), and unzip the validator (but not the validation pack)
Execute the validator with the following command line: java –jar org.hl7.fhir.validator.jar [source] (-defn [definitions]) (-profile [profile]) (-output [output]) where:
[source] is a file name or url of the resource or bundle feed to validate [definitions] is the file name or url of the validation pack (validation.zip). Default: get it from inside the jar file
[profile] is an optional filename or URL for a specific profile to validate a resource against. In the absence of this parameter, the resource will be checked against the base specification using the definitions.
[output] is a filename for the results (OperationOutcome). Default: results are sent to the std out.
Note: at this time, the validator is only able to validate XML resources, not JSON ones.
Here’s a windows batch file that will do all this:
REM get the validator and unzip it
wget.exe http://hl7-fhir.github.io/validator.zip
7z.exe x validator.zip
7z.exe x saxon.zip
REM Get the validation source file (dictionary)
wget.exe http://hl7-fhir.github.io/validation-min.zip
REM get an example to validate
wget.exe http://ec2-54-87-74-90.compute-
1.amazonaws.com/open/Patient/1234 -O daf-patient.xml
REM validate it. The DAF profile will be loaded out of the
definitions in validation-min.zip
java -jar org.hl7.fhir.validator.jar daf-patient.xml -defn
validation-min.zip -profile
http://hl7.org/fhir/StructureDefinition/patient-daf-dafpatient
pause
回答4:
The documentation needs updating. Try:
java -jar org.hl7.fhir.validator.jar round mysourcefile.xml output.xml
But I don't think the DSTU validation.jar is applying the XSD or Schematrons. If this is your goal, then you can use other tools.
For XSD:
xmllint --noout --schema <XSD_FILE> mysourcefile.xml
For Schematron, using probatron4j
java -jar probatron.jar mysourcefile.xml fhir-atom.sch
来源:https://stackoverflow.com/questions/24407744/how-to-run-fhir-validator-java-jar