[ismrmrd] 147/177: Added xml validation to Matlab. Fixed a bug in the produced XML document as a consequence

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Jan 14 20:02:13 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to annotated tag v1.1.0.beta.1
in repository ismrmrd.

commit 810e83b47cec74291a6104d6285ca804af29977e
Author: David C Hansen <dch at cs.au.dk>
Date:   Fri Oct 17 11:01:45 2014 +0200

    Added xml validation to Matlab. Fixed a bug in the produced XML document as a consequence
---
 matlab/+ismrmrd/+xml/serialize.m | 22 +++++++++++-----------
 matlab/+ismrmrd/+xml/validate.m  | 20 ++++++++++++++++++++
 2 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/matlab/+ismrmrd/+xml/serialize.m b/matlab/+ismrmrd/+xml/serialize.m
index 8f970c2..c9cbe4b 100644
--- a/matlab/+ismrmrd/+xml/serialize.m
+++ b/matlab/+ismrmrd/+xml/serialize.m
@@ -8,12 +8,12 @@ docRootNode.setAttribute('xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance'
 docRootNode.setAttribute('xmlns:xs','http://www.w3.org/2001/XMLSchema');
 
 docRootNode.setAttribute('xsi:schemaLocation','http://www.ismrm.org/ISMRMRD ismrmrd.xsd');
-docRootNode.setAttribute('version','1');
+% docRootNode.setAttribute('version','1');
 
-append_optional(docNode,docRootNode,header,'version', at int2str)
+% append_optional(docNode,docRootNode,header,'version', at int2str)
 
 if isfield(header,'subjectInformation')
-    subjectInformation = header.subjectInformation
+    subjectInformation = header.subjectInformation;
     subjectInformationNode = docNode.createElement('subjectInformation');
     append_optional(docNode,subjectInformationNode,subjectInformation,'patientName');
     append_optional(docNode,subjectInformationNode,subjectInformation,'patientWeight_kg', at num2str);
@@ -24,7 +24,7 @@ if isfield(header,'subjectInformation')
 end
 
 if isfield(header,'studyInformation')
-    studyInformation = header.studyInformation
+    studyInformation = header.studyInformation;
     studyInformationNode = docNode.createElement('subjectInformation');
     append_optional(docNode,studyInformationNode,studyInformation,'studyDate');
     append_optional(docNode,studyInformationNode,studyInformation,'studyTime');
@@ -62,7 +62,7 @@ if isfield(header,'measurementInformation')
     append_optional(docNode,measurementInformationNode,measurementInformation,'frameOfReferenceUID');
     
     referencedImageSequence = measurementInformation.referencedImageSequence;
-    referencedImageSequenceNode = docNode.createElement('referencedImageSequence')
+    referencedImageSequenceNode = docNode.createElement('referencedImageSequence');
     for ref = referencedImageSequence(:)
         append_node(docNode,referencedImageSequenceNode,ref,'referencedSOPInstanceUID');
     end
@@ -84,7 +84,7 @@ if isfield(header,'acquisitionSystemInformation')
 end
 
 experimentalConditions = header.experimentalConditions;
-experimentalConditionsNode = docNode.createElement('experimentalConditionsNode');
+experimentalConditionsNode = docNode.createElement('experimentalConditions');
 append_node(docNode,experimentalConditionsNode,experimentalConditions,'H1resonanceFrequency_Hz', at int2str);
 docRootNode.appendChild(experimentalConditionsNode);
 
@@ -111,7 +111,7 @@ for enc = header.encoding(:)
     append_encoding_limits(docNode,node,'set',enc);
     append_encoding_limits(docNode,node,'segment',enc);
     append_node(docNode,node,enc,'trajectory');
-    node.appendChild(n2)
+    node.appendChild(n2);
     
     
     if isfield(enc,'trajectoryDescription')
@@ -130,12 +130,12 @@ for enc = header.encoding(:)
         parallelImaging = enc.parallelImaging;
         append_node(docNode,n3,parallelImaging.accelerationFactor,'kspace_encoding_step_1', at int2str);
         append_node(docNode,n3,parallelImaging.accelerationFactor,'kspace_encoding_step_2', at int2str);
-        n2.appendChild(n3)
+        n2.appendChild(n3);
         
         append_optional(docNode,n2,parallelImaging,'calibrationMode'); 
         append_optional(docNode,n2,parallelImaging,'interleavingDimension'); 
         
-        node.appendChild(n2)
+        node.appendChild(n2);
     end
         
     append_optional(docNode,node,enc,'echoTrainLength');
@@ -153,7 +153,7 @@ if isfield(header,'sequenceParameters')
     append_node(docNode,n1,sequenceParameters,'TI', at num2str);
     
     append_node(docNode,n1,sequenceParameters,'flipAngle_deg', at num2str);
-    docRootNode.appendChild(n1)
+    docRootNode.appendChild(n1);
 end
 
 if isfield(header,'userParameters')
@@ -164,7 +164,7 @@ if isfield(header,'userParameters')
     append_user_parameter(docNode,n1,userParameters,'userParameterDouble', at num2str);
     append_user_parameter(docNode,n1,userParameters,'userParameterString');
     append_user_parameter(docNode,n1,userParameters,'userParameterBase64');
-    docRootNode.appendChild(n1)
+    docRootNode.appendChild(n1);
 end
 xml_doc = xmlwrite(docNode);
 
diff --git a/matlab/+ismrmrd/+xml/validate.m b/matlab/+ismrmrd/+xml/validate.m
new file mode 100644
index 0000000..85511d1
--- /dev/null
+++ b/matlab/+ismrmrd/+xml/validate.m
@@ -0,0 +1,20 @@
+function validate( xml,schemaFile )
+%UNTITLED Summary of this function goes here
+%   Detailed explanation goes here
+import java.io.*;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.*;
+
+factory = SchemaFactory.newInstance('http://www.w3.org/2001/XMLSchema');
+schemaLocation = File(schemaFile);
+schema = factory.newSchema(schemaLocation);
+validator = schema.newValidator();
+sr = StringReader(xml);
+source = StreamSource(sr);
+validator.validate(source);
+
+
+
+end
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/ismrmrd.git



More information about the debian-science-commits mailing list