One of the really cool features added to XMLSpy a few years ago based on customer requests is the ability to embed external files – such as images – directly in an XML document as encoded text. This gives you the option to package all required data from various external files together in one large XML document. The functionality is also available for embedding images in JSON documents.
Let’s take a look at how easy it is to accomplish this in the XML and JSON editor in just a few steps.
Embed Images in XML or JSON
First, click the Insert / Encoded External File command, which is is available in Text View and Grid View for XML documents, and Text View for JSON files.
Browse to select the file to embed, and then choose either Base 16 or Base 64 encoding. If you wish to enclose the encoded text in an element, check the Create Element check box and specify the name to use.
In this example, we’re creating a new XML element called <photo>. If the Create Element check box is not checked, the encoded text will be inserted directly at the cursor location.
When we click OK, the encoded text of the image file we specified is inserted in the <photo> element and is now a part of our XML document.
Here is a shot of a JSON document in the powerful JSON Grid Editor. You can see an image we embedded in the file.
And that’s all there is to it! You can download a free trial of XMLSpy to try it out.