Embedding Images in XML


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.

Photo for embedding images

 

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.

insert-encoded-file

 

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.

 

encoded-image

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.

image-base64

 

Here is a shot of a JSON document in the powerful JSON Grid Editor. You can see an image we embedded in the file. 

How to embed an image in JSON file

And that’s all there is to it!  You can download a free trial of XMLSpy to try it out.

Tags: , , , ,