Add a Doctype declaration to an XML file

I need to add a doctype declaration below the XML declaration in my XML output. Is there a way to do this? Thank you.

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE segue PUBLIC “Carmen/segue” “segue.dtd”>

You can do this by reading in your XML file as plain text, inserting the extra row and then writing it back out as plain text.

insert-xml-doctype.transform (3.1 KB)

It’s not ideal. Perhaps we could add an Above root field where you could put this for XML output?

I am starting with CSV (or Excel) and making my output XML.

An “above root” option would be helpful for adding doctype declarations.

Or, if my XML could be intermediate format (instead of an output format), I could add the doctype with Stack or some other transform, and then output it to a file.

You probably have to do it as 2 passes. Output as XML and then input the .xml as plain text, add the row and output it again. You should be able to do this in 1 .transform if you put the first input to the left - but you might get warning messages about inputting an output.

It wouldn’t be hard to add, but it needs to be a multi-row edit, so it does eat up quite a lot of vertical screen real estate. I will think about it.

You can now add extra lines above the root. See:

I just tested it and it works great. This is a very useful enhancement. Thank you very much.

1 Like