When submitting XML to XNAT via REST, you receive an error message similar to this:
This error occurs due to invalid XML, but the cause may be either actual invalid XML (in which case the solution is to fix the XML) or the formatting of the XML. Specifically, when processing the XML text, the XNAT server will read each line of the incoming request body, concatenating each line into a single block of XML. If there are line feeds or returns in your XML in a place that requires whitespace between XML elements, those elements may end up not being separated by whitespace.
For example, consider the following XML describing a standard XNAT QC assessment.
Each line is terminated by a line feed, with no other whitespace. That can then be sent to XML via curl or some other command:
This will result in a SAXParseException message similar to the one above. The problem is at the end of the lines. Look at the end of the first line and the beginning of the second line. Those are concatenated, but no whitespace is added, resulting in the following:
Note that project="PRJ001" and label="PRJ001_001_MR1_QC" run right into each other. This is the cause of the SAXParseException error.
To fix this issue, you have a few options:
- End all lines with an empty space. Incoming line feeds are removed, but not other whitespace. This will ensure that elements in the XML remain distinct.
- Ensure that all XML elements are on the same line, so that a line feed doesn't break the element up.
- Use a pretty-print or other XML formatting option when generating or composing XML.
Once you've eliminated this problem, valid and well-formed XML should import properly into XNAT.