xml2dcm(1)

πŸŽ€ xml2dcm(1) β€” OFFIS DCMTK πŸŽ€


🌸 NAME 🌸

xml2dcm β€” convert XML document to DICOM file or data set. That's the whole vibe, bestie: XML goes in, DICOM comes out, and you look iconic doing it. πŸ’…

✨ SYNOPSIS ✨

xml2dcm [options] xmlfile-in dcmfile-out

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so the xml2dcm utility converts the contents of an XML (Extensible Markup Language) document to DICOM file or data set. It's giving converter energy, no cap.

The XML document is expected to validate against the DTD (Document Type Definition) which is described in file dcm2xml.dtd. An appropriate XML file can be created using the dcm2xml tool (option +Wb recommended to include binary data). iykyk β€” that +Wb is the little binary-data bestie.

πŸ“ PARAMETERS πŸ“

  • xmlfile-in β€” XML input filename to be converted ("-" for stdin). Yes, a literal dash means stdin, bestie.
  • dcmfile-out β€” DICOM output filename ("-" for stdout). And another dash means stdout. The dash is lowkey doing main character work.

🌈 OPTIONS 🌈

πŸ’– general options πŸ’–

  • -h, --help β€” print this help text and exit. Helpful icon behavior.
  • --version β€” print version information and exit. Version check, slay.
  • --arguments β€” print expanded command line arguments. So you can see exactly what the shell fed it.
  • -q, --quiet β€” quiet mode, print no warnings and errors. Shhh era.
  • -v, --verbose β€” verbose mode, print processing details. Talkative era.
  • -d, --debug β€” debug mode, print debug information. Maximum yapping, but make it diagnostics.
  • -ll, --log-level [l]evel: string constant β€” (fatal, error, warn, info, debug, trace); use level l for the logger. Pick your log-level lore.
  • -lc, --log-config [f]ilename: string β€” use config file f for the logger. Logger config file moment.

🧚 input options 🧚

πŸ’œ input file format

  • +f, --read-meta-info β€” read meta information if present (default). Default behavior, bestie.
  • -f, --ignore-meta-info β€” ignore file meta information. Pretend you didn't see it.

πŸŽ€ processing options πŸŽ€

🌟 validation

  • +Vd, --validate-document β€” validate XML document against DTD. DTD vibe check.
  • +Vn, --check-namespace β€” check XML namespace in document root. Namespace inspection, no cap.

πŸ‘‘ unique identifiers

  • +Ug, --generate-new-uids β€” generate new Study/Series/SOP Instance UID. Fresh UIDs, fresh era.
  • -Uo, --dont-overwrite-uids β€” do not overwrite existing UIDs (default). Default: leave those UIDs alone.
  • +Uo, --overwrite-uids β€” overwrite existing UIDs. Overwrite mode, handle with care energy.

πŸ”₯ output options πŸ”₯

🌸 output file format

  • +F, --write-file β€” write file format (default). Default file format behavior.
  • -F, --write-dataset β€” write data set without file meta information. Data set only, no file meta information.
  • +Fu, --update-meta-info β€” update particular file meta information. Meta info gets a little refresh.

πŸ¦‹ output transfer syntax

  • +t=, --write-xfer-same β€” write with same TS as input (default). Default: same transfer syntax as the input.
  • +te, --write-xfer-little β€” write with explicit VR little endian TS. Explicit VR little endian TS.
  • +tb, --write-xfer-big β€” write with explicit VR big endian TS. Explicit VR big endian TS.
  • +ti, --write-xfer-implicit β€” write with implicit VR little endian TS. Implicit VR little endian TS.
  • +td, --write-xfer-deflated β€” write with deflated explicit VR little endian TS. Deflated explicit VR little endian TS.

πŸ’€ error handling

  • -E, --stop-on-error β€” do not write if document is invalid (default). Default: invalid document means no write.
  • +E, --ignore-errors β€” attempt to write even if document is invalid. Attempt to write anyway.

⭐ post-1993 value representations

  • +u, --enable-new-vr β€” enable support for new VRs (UN/UT) (default). Default: new VRs are enabled.
  • -u, --disable-new-vr β€” disable support for new VRs, convert to OB. New VRs off, convert to OB.

🌈 group length encoding

  • +g=, --group-length-recalc β€” recalculate group lengths if present (default). Default: recalculate if present.
  • +g, --group-length-create β€” always write with group length elements. Always include group length elements.
  • -g, --group-length-remove β€” always write without group length elements. Always leave group length elements out.

πŸŽ€ length encoding in sequences and items πŸŽ€

  • +e, --length-explicit β€” write with explicit lengths (default). Default: explicit lengths.
  • -e, --length-undefined β€” write with undefined lengths. Undefined lengths mode.

🌟 data set trailing padding (not with --write-dataset)

  • -p=, --padding-retain β€” do not change padding (default if not --write-dataset). Default when you're not using --write-dataset: leave padding alone.
  • -p, --padding-off β€” no padding (implicit if --write-dataset). No padding; implicit if --write-dataset.
  • +p, --padding-create [f]ile-pad [i]tem-pad: integer β€” align file on multiple of f bytes and items on multiple of i bytes. Alignment math, bestie: file on multiples of f bytes, items on multiples of i bytes.

πŸ’œ deflate compression level (only with --write-xfer-deflated)

  • +cl, --compression-level [l]evel: integer (default: 6) β€” 0=uncompressed, 1=fastest, 9=best compression. Compression dial: 0 uncompressed, 1 fastest, 9 best compression. Default is 6.

✨ NOTES ✨

okay so the basic structure of the XML input it expects looks like this πŸ’–

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE file-format SYSTEM "dcm2xml.dtd">
<file-format xmlns="http://dicom.offis.de/dcmtk">
  <meta-header xfer="1.2.840.10008.1.2.1" name="Little Endian Explicit">
    <element tag="0002,0000" vr="UL" vm="1" len="4"
             name="MetaElementGroupLength">
      166
    </element>
    ...
    <element tag="0002,0013" vr="SH" vm="1" len="16"
             name="ImplementationVersionName">
      OFFIS_DCMTK_353
    </element>
  </meta-header>
  <data-set xfer="1.2.840.10008.1.2" name="Little Endian Implicit">
    <element tag="0008,0005" vr="CS" vm="1" len="10"
             name="SpecificCharacterSet">
      ISO_IR 100
    </element>
    ...
    <sequence tag="0028,3010" vr="SQ" card="2" name="VOILUTSequence">
      <item card="3">
        <element tag="0028,3002" vr="xs" vm="3" len="6"
                 name="LUTDescriptor">
          256\0\8
        </element>
        ...
      </item>
      ...
    </sequence>
    ...
    <element tag="7fe0,0010" vr="OW" vm="1" len="262144"
             name="PixelData" loaded="no" binary="hidden">
    </element>
  </data-set>
</file-format>

and bestie, listen β€” the "file-format" and "meta-header" tags may be absent for DICOM data sets. they're optional, not mandatory, mwah πŸ’…


🌸 Character Encoding 🌸

so the DICOM character encoding? it gets determined automatically from the element with tag "0008,0005" (Specific Character Set) β€” if it's present. like, the file just tells you what it is. iconic behavior tbh ✨

here's the full lineup of character sets currently supported (and heads up, this requires libxml to include iconv support β€” go peek at the --version output to check πŸ‘€):

  • ASCII β€” (ISO_IR 6) β€” (UTF-8)
  • UTF-8 β€” "ISO_IR 192" β€” (UTF-8)
  • ISO Latin 1 β€” "ISO_IR 100" β€” (ISO-8859-1)
  • ISO Latin 2 β€” "ISO_IR 101" β€” (ISO-8859-2)
  • ISO Latin 3 β€” "ISO_IR 109" β€” (ISO-8859-3)
  • ISO Latin 4 β€” "ISO_IR 110" β€” (ISO-8859-4)
  • ISO Latin 5 β€” "ISO_IR 148" β€” (ISO-8859-9)
  • ISO Latin 9 β€” "ISO_IR 203" β€” (ISO-8859-15)
  • Cyrillic β€” "ISO_IR 144" β€” (ISO-8859-5)
  • Arabic β€” "ISO_IR 127" β€” (ISO-8859-6)
  • Greek β€” "ISO_IR 126" β€” (ISO-8859-7)
  • Hebrew β€” "ISO_IR 138" β€” (ISO-8859-8)
lowkey important: multiple character sets are not supported. only the first value of the "Specific Character Set" gets used for the character encoding when there's value multiplicity. one charset and one charset only, bestie 😭

and yeah β€” see the dcm2xml documentation for more details on the XML structure. go read your sibling's manual, it's giving family bonding 🫢


πŸ¦‹ Binary Data πŸ¦‹

binary data (*) can be encoded one of two ways, pick your fighter:

  • as a sequence of hex numbers separated by a backslash "\"
  • in Base64 format (binary="base64")

and there's a third option that's lowkey the best one: binary data can also be read from a file (binary="file"). in that case the filename has to be specified as the element value, like this:

<element tag="7fe0,0010" vr="OW" ...
         binary="file">subdir/pixeldata.raw</element>
⚠️ please note that the contents of the file will be read as is. OW data is expected to be little endian ordered and will be swapped if necessary. no checks will be made to ensure that the amount of data is reasonable in terms of other attributes such as Rows or Columns. and Base64 encoded data is expected to use big endian byte ordering. the tool is trusting you completely, no vibe check, no cap πŸ’€

() also a real one: currently only OB and OW data is supported β€” meaning element values with a VR of OD, OF, OL and OV are *not regarded as "binary data" and get treated as all other VRs. them's the rules 🌈


πŸŽ€ Compression πŸŽ€

if libxml is compiled with zlib support, the input file (xmlfile-in) can also be compressed with ZIP, which usually results in much smaller files (tiny file slay πŸ’–). check the output of option --version to see whether zlib support is available.


πŸ’€ Limitations πŸ’€

different versions of libxml might have different limits for the maximum length of an XML element value. so yeah β€” it should be avoided to use very long element values (e.g. for pixel data). don't push your luck bestie πŸ™ˆ

also: xml2dcm currently does not fully support DICOMDIR files. specifically, the value of the various offset data elements is not updated automatically by this tool. you're on your own for those, fr fr.

πŸ”₯ LOGGING πŸ”₯

the level of logging output of the various command line tools and underlying libraries can be specified by the user. by default, only errors and warnings are written to the standard error stream. basic.

  • option --verbose also gives you informational messages like processing details β€” she's chatty ✨
  • option --debug gets you more details on the internal activity, e.g. for debugging purposes β€” she's very chatty πŸ‘€
  • other logging levels can be selected using option --log-level
  • in --quiet mode only fatal errors are reported. in such very severe error events, the application will usually terminate 😭

for more details on the different logging levels, see documentation of module "oflog".

in case the logging output should be written to file (optionally with logfile rotation), to syslog (Unix) or the event log (Windows), the option --log-configcan be used β€” yes, the raw manpage text literally mashes it into --log-configcan be used, we love a roff artifact πŸŽ€. this configuration file also allows for directing only certain messages to a particular output stream and for filtering certain messages based on the module or application where they are generated. an example configuration file is provided in *<etcdir>/logger.cfg.


πŸ‘‘ COMMAND LINE πŸ‘‘

all command line tools use the following notation for parameters: square brackets enclose optional values (0-1), three trailing dots indicate that multiple values are allowed (1-n), and a combination of both means 0 to n values. iykyk πŸ’…

command line options are distinguished from parameters by a leading '+' or '-' sign, respectively. usually, order and position of command line options are arbitrary (i.e. they can appear anywhere). however, if options are mutually exclusive, the rightmost appearance is used. this behavior conforms to the standard evaluation rules of common Unix shells β€” she's consistent, periodt 🌟

in addition, one or more command files can be specified using an '@' sign as a prefix to the filename (e.g. @command.txt). such a command argument is replaced by the content of the corresponding text file (multiple whitespaces are treated as a single separator unless they appear between two quotation marks) prior to any further evaluation.

⚠️ please note that a command file cannot contain another command file. no inception, we don't do that here πŸ™…β€β™€οΈ

this simple but effective approach allows one to summarize common combinations of options/parameters and avoids longish and confusing command lines (an example is provided in file <datadir>/dumppat.txt). short commands = happy life πŸ¦‹


πŸ’œ ENVIRONMENT πŸ’œ

the xml2dcm utility will attempt to load DICOM data dictionaries specified in the DCMDICTPATH environment variable. by default, i.e. if the DCMDICTPATH environment variable is not set, the file <datadir>/dicom.dic will be loaded β€” unless the dictionary is built into the application (default for Windows).

the default behavior should be preferred, and the DCMDICTPATH environment variable only used when alternative data dictionaries are required. like, don't come for the defaults unless you have a reason bestie 🫢

the DCMDICTPATH environment variable has the same format as the Unix shell PATH variable in that a colon (":") separates entries. on Windows systems, a semicolon (";") is used as a separator. the data dictionary code will attempt to load each file specified in the DCMDICTPATH environment variable.

🚨 it is an error if no data dictionary can be loaded. that's a hard fail, no cap.

πŸ“ FILES πŸ“

  • <datadir>/dcm2xml.dtd β€” Document Type Definition (DTD) file

⭐ SEE ALSO ⭐


Copyright (C) 2003-2026 by OFFIS e.V., Escherweg 2, 26121 Oldenburg, Germany.


and that's the whole page, bestie, you ate that πŸ’…βœ¨ this cutie was brought to you by Version 3.7.1, dated Sat Oct 17 2026 09:34:01 β€” go forth and convert your XML into DICOM, you absolute icon πŸŽ€πŸ‘‘

πŸ“¦ where this page comes from