Integration Basics: XML Handling

XML has become the preferred language of integration. While JSON has its adherents and there are many proprietary text file formats used by various APIs, XML is the lingua franca. At one time, it seemed BPEL4WS would become the standard. While it also has its adherents, it is only one of many XML based approaches.

While XML’s ubiquity makes it a preferred language, it is not without overhead. XML data typically includes both the raw data and metadata, which describes the data. An integration platform can take much of the heavy lifting out of XML handling. That’s just one of the many reasons why an integration platform should be used to interface applications, but it is an important one.

This blog entry provides a technical overview of the XML handling provided by the Magic xpi Integration Platform. For a detailed “deep dive,” you can consult the documentation on XML Handling.

So what can Magic xpi do for you when it comes to XML handling?

Magic xpi allows you to build integration flows taking a “drag, drop and configure” approach.  When you place the XML Handling component in a flow, Magic xpi automatically opens the Component Properties dialog box for the component and you can specify your XML source type as a file or as a variable.

Magic xpi Integration Platform supports a wide variety of XML handling methods that make it much easier to deal with XML in an integration flow. The platform removes the need for any programming and instead allows you to use its built-in methods for XML manipulation.

Here is what you will be able to do with the Magic xpi XML Handling component:

Use Aliases. One of the first things you can do to simplify working with XML is use aliases. An alias provides an easy way to reference a namespace URI. With the Magic xpi Set Namespace method you can associate an alias with a namespace URI for the root element. The Magic xpi method known as Get Alias likewise retrieves the alias associated with a namespace for the root element.

A word about Elements vs. Attributes. When working with XML, information can be contained in either elements or attributes. There are no real rules about when to use elements or attributes. The same information can be stored as either an element or an attribute. In general, however, it is usually best to use attributes for metadata and nested child elements for data.

In the following two examples, the same information is presented:

  Fred  Smith

  Platinum  Fred  Smith

In the first example Loyalty Type is an attribute. In the second example, Loyalty Type is a child element.

With Magic xpi, you can easily check to see if an element or attribute exists and count the number of instances that it exists. The Magic xpi Check Exists method returns a true value if an XML element or an XML attribute is located by the XML’s element path. The Magic xpi Count method returns the number of occurrences of an XML element or an XML attribute according to its path.

Working with XML Elements. XML Elements can be either Alphanumeric text or BLOBs. There are two Magic xpi methods that apply to both types of elements. The Magic xpiFind Element Index method returns the index of an XML element that has a value equal to a specified value. Likewise, the Magic xpi Delete Element method deletes an XML element.

Working with Alpha Elements. The Magic xpi Get Element Alpha Value method returns the Alpha value of an XML element or an XML attribute according to its element path. The Magic xpi Insert Element Alpha method inserts an XML element with an Alpha value at a specified location in an XML document. The Magic xpi Modify Element Alpha method modifies the Alpha value of an XML element.

Working with Binary Large Objects (BLOB) in XML. A BLOB is a binary large object. These are useful to include in an XML that is being used for integration as they can pass the data in a binary format. The Magic xpi Get Element Blob Value method returns the Blob value of an XML element or an XML attribute according to its element path. The Magic xpiInsert Element Blob method inserts an XML element with a Blob value at a specified location in an XML document. The Magic xpi Modify Element Blob method modifies the Blob value of an XML element.

Working with XML Attributes. The Magic xpi Get Attribute Value method returns the value of an XML element or an XML attribute according to its element path. The Magic xpi  Insert Attribute method inserts an XML element at a specified location in an XML document or adds an attribute to an existing XML element. The Magic xpi Modify Attribute method modifies the value of an attribute whereas Delete Attribute deletes an XML attribute.

A Word About XML Encoding. Magic xpi includes methods that can be used to convert XML content from one character code to another to use that content without affecting the structure or validity of an XML document. Most, but certainly not all, XML uses UTF-8 by default. If you want to access or use special character sets, then you need to specify them. In Magic xpi, the Get XML Encoding method retrieves the encoding of an XML document and the Set XML Encoding method sets the encoding of an XML document that was opened for Write access.

Be Sure to Validate. Just as with parking, make sure you always validate your XML. It’s just good practice and saves you from issues down the line.  With the Magic xpi Integration Platform, the Validate method returns a list of validation errors. You should remember, however, that any changes made to an XML document will not be seen until the XML Handling step is complete. 

In my next entry, we’ll discuss XML transformation using the Magic xpi XSLT component.

Featured Articles

Smart Industry
How mid-size manufacturers should consider digitalization case studies
Read More
Supply & Demand Chain Executive
Dear Mid-Sized Manufacturer, Do You Have a Plan for Transitioning to Industry 4.0?
Read More
Manufacturing News
FactoryEye Launches Strategic Partner Program
Read More