Data Conversion API's

Having a data conversion toolkit is a pretty handy item in your toolbox. It's too bad most of them cost more than your house, and are harder to run than a nuclear power plant. All that's about to change.

The World's Simplest XML Converter

To show how simple it is to use DataDirect XML Converters™, consider this program that reads EDI from one file specified on the command line, and writes it as XML to the other.

 1import com.exln.stylus.io.*;
 2import com.stylusstudio.converter.*;
 3import javax.xml.transform.stream.*;

 4public class ConverterOne {
 5    public static void main(String args[]) throws Throwable {
 6        if (!StylusFileFactory.unlockAPI("Insert your Installation ID here")) {
 7            System.out.println(StylusFileFactory.getUnlockAPIError());
 8            return;
          }

          // From EDI to XML
 9        Converter toXML = ConverterFactory.newInstance().newConvertToXML("adapter:EDI");
10        toXML.convert(new StreamSource(args[0]), new StreamResult(args[1]));
11        System.out.println(args[0] + " --> " + args[1]);
      }
  }

That's it! Of the eleven lines of code, only six are actually executable code, and of those, the call to the converter is only two lines long (see lines 9 and 10 above).

And the Stylus Studio® EDI converter isn't some wimpy little converter either. It automatically can determine the type of EDI — whether it's EDIFACT, X12, IATA, EANCOM or HL7 — and can handle dozens of versions. It will produce wonderfully indented and documented XML.

Many of the converters have additional options that can be set on the URL to tune their behavior — to set things such as encoding or delimiters or element names. Those same parameters can be added right to the URL string here. The easiest way to get them (even easier than reading the manual!) is to do File|Open in Stylus Studio® and to set them there, and then copy out the URL and paste it into your application.

Ambidextrous Converters

The converter is bidirectional too, so that XML can be turned into EDI. To go into the other direction, the changes are just what you'd expect. They've been underlined below for clarity.

          // From XML to EDI
 9        Converter fromXML = ConverterFactory.newInstance().newConvertFromXML("adapter:EDI");
10        fromXML.convert(new StreamSource(args[0]), new StreamResult(args[1]));

Custom Converters

If you've build your own converter using Convert to XML, you can use that just as easily. Instead of putting in one of the built-in converter names, you specify the URL of the .conv converter definition file that you created, like this:

          // Convert to XML
 9        Converter toXML = ConverterFactory.newInstance().newConvertToXML("adapter:file:///c:/home/weather.conv");
10        toXML.convert(new StreamSource(args[0]), new StreamResult(args[1]));

We tried to make it more complicated, but we failed. Our loss is your gain!

File Format Converters

The other converters, such as those for flat files or dBase files, or those created through the Convert to XML module, are run in exactly the same way. There is a growing series of converters available for your use. These include:

Base-64Base-64 encoding of a binary file as documented in RFC 1341
BinaryEncoding of a binary file as a sequence of digits in a base from 2 to 36
ConvertToXMLConvert to XML
CSVComma-Separated Values
dBase_IIdBase II
dBase_IIIdBase III
dBase_III_plusdBase III+
dBase_IVdBase IV
dBase_VdBase V
DIFData Interchange Format
DotDOpenEdge .d Data Dump
EDIElectronic Data Interchange (EDIFACT, X12, IATA, EANCOM)
HTMLTidyHTML-to-XHTML HtmlTidy
JavaPropsJava .properties File
JSONJavaScript Object Notation
LineWhole-line Text
MBoxE-mail mbox [to XML only]
PyxPyx format
RTFRich Text Format
SDISuper Data Interchange Format
SYLKSymbolic Link Format
TABTab-Separated Values
WinIniWindows .ini File
WinWriteWinWrite [to XML only]

Base-64 XML Converter

This converts any file, text or binary (such as an image), into a XML document with a single element containing the Base-64 encoded content of the input file.

This converter is most useful to embed some arbitrary binary data inside of another document, where the target document contains a field with the W3C XML Schema type of base64Binary. The following example in-lines the binary image for each shirt into an aggregate XML file.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:param name="base" select="'http://www.stylusstudio.com/images/publish/'"/>
    <xsl:template match="/">
        <images>
            <xsl:for-each select="inventory/item">
                <image>
                    <xsl:value-of select="document(concat('adapter:Base-64?', $base, substring(sku, 2), '.gif'))"/>
                </image>
            </xsl:for-each>
        </images>
    </xsl:template>
</xsl:stylesheet>

For more detailed and bi-directional examples, along with explanations of the techniques involved, see the Binary XML How-to page.

Binary XML Converter

The binary converter is most useful for doing something similar to the Base-64 converter, except with hexadecimal output, as in the W3C XML Schema base64Hex datatype. It does have some other options, which allow output in other bases, such as decimal or octal or even binary.

To see how this can be used to embed binary data into XML, see the Binary XML Tutorial page.

Convert to XML Converter

When plain ol' comma-separated-values aren't enough, this is the sleek yet sophisticated Convert to XML converter. Unlike many other flat file converters, this provides a handsome user interface experience.

Comma-Separated Value XML Converter

More than just the plain-vanilla CSV converter, this supports multiple encodings and options to tweak the quote and escape characters. Despite its name, it shares a common heritage with the tab-separated-value converter, and supports other delimiters besides commas.

dBase II, III, III+, IV and V XML Converters

The dBase file format has been around for a long time. It's surprising how many modern systems still store information in this format. Now you can get out what's been stuck inside — and now you can create these files as well.

Data Interchange Format XML Converter

A useful spreadsheet interchange format, this goes all the way back to the days of VisiCalc.

OpenEdge .d Data Dump XML Converter

OpenEdge has an extremely efficient and powerful database, and this converter allows you to read and write its text dump file format.

Electronic Data Interchange XML Converter

The most sophisticated and powerful converter in the library is the EDI converter. It automatically detects and parses EDIFACT, X12, IATA and EANCOM, and can handle reading or writing with equal facility. Also included are EDI XML Schema generators, which let you pick a vocabulary, a message type and a version and will generate an XML Schema that corresponds to the EDI message.

This converter generates beautiful XML, with options to indent and comment each element and code list lookup value — making reading the interchange data a treat and not a chore.

HTML-to-XHTML HtmlTidy

HTML Tidy is a widely-used tool that converts sloppy HTML into clean XHTML. And since XHTML is just a specific vocabulary of XML, this means you can use XQuery and XSLT to parse and transform even malformed pages found in the wild.

Java .properties File XML Converter

Java .properties files are used for all sorts of tasks — from program configuration to internationalization/translation to raw data storage. Being able to read and subsequently write this format is a useful tool.

JSON XML Converter

It's become very convenient with all of this AJAX stuff going on, to communicate between web services using JavaScript Object Notation. This converter uses the algorithms on the JSON.org website to read from XML and write to JSON, and vice-versa, so that tools expecting XML can easily cross-communicate. This can be especially useful for calling services that expect JSON.

Plain Text XML Converter

For the most basic needs, this converter just reads in text one line at a time and wraps an element around each line, escaping any embedded & or > or < symbols. For when you just need your XSLT or XQuery to inhale raw text.

E-mail XML Converter

Wouldn't it be great if your program could read its own mail? This converter contains the ability to parse the standard mbox file format and even handles multi-part messages.

Pyx XML Converter

Pyx is a line-orientated notation roughly equivalent to XML for expressing tree-oriented data. This converter will read and write the Pyx format.

Rich Text Format XML Converter

The RTF file format converter turns RTF into a straight XML representation of the RTF. Since it also works the other way, this provides a way to create RTF documents from XSLT or XQuery.

Super Data Interchange Format XML Converter

This format, also used by spreadsheets, builds on the base of the DIF converter.

Symbolic Link Format XML Converter

Pioneered by Microsoft­ MultiPlan, this format is used also for the exchange of spreadsheet data.

Tab-Separated Value XML Converter

A format favored by Microsoft­ Excel, this and the comma-separated-value converter are two general-purpose tools no converter toolkit should be without.

Windows .ini File XML Converter

Sometimes it's useful to be able to read configuration data, or to update that data. This bidirectional converter lets you do just that.

WinWrite XML Converter

If you've got old text or instructions written with the default editor that came with older copies of Microsoft Windows, this one-way converter will get at that text for you. It turns it into XHTML, convenient for further processing or just right for leaving as-is.

All Your Data Are Belong To Us

This is just quick overview of the power of DataDirect XML Converters™. New features are constantly being added — download a free trial and see how the conversion API can make short work of tough integration problems.

All Your Data Are Belong To Us

Content Management

Build Content Management systems with Stylus Studio's powerful XML publishing tools that enable you to unlock and re-use valuable content from your enterprise information repositories.

Using the Stylus Studio XML Grid View

This free onlince video tutorial shows how to use the Stylus Studio XML Grid View.

Working with Tables in XSLT

This free video tutorial about working with XSL tables covers how to handle iteration and looping using xsl:for-each to create HTML reports driven by XML data.

XML-DEV Blog

Join the XML Development discussion at XML-Dev - the hottest place to talk about XML technologies, trends, systems architecture and all the latest buzz. Bookmark this RSS and ATOM feed now!

Stylus Most Wanted

PURCHASE STYLUS STUDIO ONLINE TODAY!!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Try Our Data Conversion API's Today

Using DataDirect XML Converters — Powerful Data Conversion API's, you can run any data conversion from inside of your Java or .NET program code, instead of just doing them manually from within a desktop application — Download a free trial today!

Attend a Live Webinar This Week!

Learn about Stylus Studio's unique features and benefits in just under an hour. Register for the Stylus Studio QuickStart Training WebCast!

Ask Someone You Know

Does your company use Stylus Studio? Do your competitors? Engineers from over 100,000 leading companies use Stylus Studio, and now you can ask someone from your own organization about their experiences using Stylus Studio.

Top Ten XQuery Trends

Read about the top 10 XQuery Trends and how they will impact change the way enterprise software applications are built.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.