Home > Articles > Web Services > XML

Like this article? We recommend

Like this article? We recommend

Migrating Some Legacy Data into XML

Let's assume that we decided that some of the legacy NMS data are a candidate for migration into a brand-new NMS product. We want to convert the old data into XML format so that our ultra-modern Java applications can use it. Listing 2 illustrates a text file that contains some typical legacy NMS data that relates to our old friend LER A from Figure 1.

Listing 2 Legacy NMS Node Data for LER A (Contained in File LegacyNMSData1.txt)

Contact: Stephen Morris
Email: stephenbjm@yahoo.com
Phone: 1800 512 9999
System name: LER A
IP-capable: Yes
MPLS-capable: Yes
Last Discovery: 1 January 2005
Location: Europe

The data in Listing 2 might have been sitting in a relational database from which it was exported into a flat ASCII file. This is the scenario I assume. In passing, I note two fields in Listing 2 that are of interest to a network manager: IP-capable and MPLS-capable. These fields simply describe the fact that the host device (LER A) supports these technologies. Given this support, the NMS can then allow appropriate operations to be executed against LER A (such as LSP creation/termination).

So, we now want to migrate the data in Listing 2 into XML format. This means that we want to see the Listing 2 data as illustrated in Listing 3 (Listing 3 is the output from some Java code we'll look at shortly).

Listing 3 XML Version of the Legacy Data

<?xml version="1.0" encoding="UTF-8"?>
<nodedata>
 <contact>Stephen Morris</contact>
 <email>stephenbjm@yahoo.com</email>
 <telephone>1800 512 9999</telephone>
 <sysnname>LER A</sysnname>
 <IP-capable>Yes</IP-capable>
 <MPLS-capable>Yes</MPLS-capable>
 <Last Discovery>1 January 2005</Last Discovery>
 <Location>Europe</Location>
</nodedata>

In Listing 3, our Java program has converted the column headings at the left of Listing 2 into XML tags. This is purely for convenience and is driven by the parser code illustrated in Listing 4.

Listing 4 Parsing Code for Legacy Data Migration

      handler.startDocument();
      handler.startElement(nsu, rootElement, rootElement, atts);
      output("contact", "Contact", line);
      line = br.readLine();
      output("email", "Email", line);
      line = br.readLine();
      output("telephone", "Phone", line);
      line = br.readLine();
      output("sysnname","System name", line);
      line = br.readLine();
      output("IP-capable", "IP-capable", line);
      line = br.readLine();
      output("MPLS-capable", "MPLS-capable", line);
      line = br.readLine();
      output("Last Discovery", "Last Discovery", line);
      line = br.readLine();
      output("Location", "Location", line);

The elements of Listing 4 correspond with the legacy data in Listing 2. For the grisly details about using the XSLT/SAX API, please see the excellent J2EE tutorial cited in the References section at the end of this article.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.