Interstage Shunsaku Data Manager Application Development Guide - Microsoft(R) Windows(R) 2000/ Microsoft(R) Windows Server(TM) 2003 - - UNIX -
|
Contents
Index

|
12.6.3 Creation of XMLGenerator to Acquisition of XML Documents
The following example shows how the APIs are used, from the creation of XMLGenerator through to acquisition of XML documents.
The following example extracts and outputs XML documents in String format, after XMLGenerator has performed a conversion based on a ResultSet object that has been obtained from data stored in either a database or CSV file.
XMLGenerator gen = null;
GeneratorMap map = null;
DocumentFountain df = null;
try
{
gen = new XMLGenerator();
map = new GeneratorMap("map01.xml");
df = gen.createDocumentFountain( DocumentFountain.TYPE_STRING ,rs, map );
df.setCode("SJIS");
}
catch(Exception e)
{
e.printStackTrace();
return;
}
String ResultStr = null;
try
{
while(df.hasXMLDocument())
{
ResultStr = (String)df.getXMLDocument();
System.out.println("Result:"+ResultStr);
}
rs.close(); // If the input is from a database, connection release is also required.
}
catch(Exception e)
{
e.printStackTrace();
return;
}
}
}
|
The following example extracts and outputs XML documents in Stream format, after XMLGenerator has performed a conversion based on a ResultSet object that has been obtained from data stored in either a database or CSV file.
import java.io.File;
import java.io.FileOutputStream;
:
XMLGenerator gen = null;
GeneratorMap map = null;
DocumentFountain df = null;
try
{
gen = new XMLGenerator();
map = new GeneratorMap("map01.xml");
df = gen.createDocumentFountain( DocumentFountain.TYPE_STREAM, rs, map );
df.setCode("SJIS");
}
catch(Exception e)
{
e.printStackTrace();
return;
}
FileOutputStream ResultStream = null;
try
{
ResultStream = new FileOutputStream(new File("filename"));
df.setDestination(ResultStream);
while(df.hasXMLDocument())
{
df.getXMLDocument();
}
ResultStream.close();
rs.close(); // If the input is from a database, connection release is also required.
}
catch(Exception e)
{
e.printStackTrace();
return;
}
}
} |
The following example extracts and outputs XML documents as a file after XMLGenerator has performed a conversion based on a ResultSet object that has been obtained from data stored in either a database or CSV file. One record is output to one file. Therefore, the name of the file for the output destination must be changed every time a new file is generated.
XMLGenerator gen = null;
GeneratorMap map = null;
DocumentFountain df = null;
try
{
gen = new XMLGenerator();
map = new GeneratorMap("map01.xml");
df = gen.createDocumentFountain( DocumentFountain.TYPE_FILE, rs, map );
df.setCode("SJIS");
}
catch(Exception e)
{
e.printStackTrace();
return;
}
try
{
int i = 1;
while(df.hasXMLDocument())
{
df.setDestination("result" + i + ".xml");
df.getXMLDocument();
i++;
}
rs.close(); // If the input is from a database, connection release is also required.
}
catch(Exception e)
{
e.printStackTrace();
return;
}
}
} |
The following example extracts XML documents as a DOM tree for use in an application, after XMLGenerator has performed a conversion based on a ResultSet object that has been obtained from data stored in either a database or CSV file.
import org.w3c.dom.Document;
:
XMLGenerator gen = null;
GeneratorMap map = null;
DocumentFountain df = null;
try
{
gen = new XMLGenerator();
map = new GeneratorMap("map01.xml");
df = gen.createDocumentFountain( DocumentFountain.TYPE_DOM, rs, map );
df.setCode("SJIS");
}
catch(Exception e)
{
e.printStackTrace();
return;
}
Document docRoot = null;
try
{
while(df.hasXMLDocument())
{
docRoot = (Document)df.getXMLDocument();
//
// This section specifies application processing that uses docRoot received as a DOM tree.
}
rs.close(); // If the input is from a database, connection release is also required.
}
catch(Exception e)
{
e.printStackTrace();
return;
}
}
} |
The following example extracts XML documents as SAX for use in an application, after XMLGenerator has performed a conversion based on a ResultSet object that has been obtained from data stored in either a database or CSV file.
The user should set an instance of a class that implements the org.xml.sax.ContentHandler interface as the argument of the setDestination() method. In the following example, the SAXhandler class implements the org.xml.sax.ContentHandler interface separately.
import org.xml.sax.helpers.DefaultHandler;
:
XMLGenerator gen = null;
GeneratorMap map = null;
DocumentFountain df = null;
try
{
gen = new XMLGenerator();
map = new GeneratorMap("map01.xml");
df = gen.createDocumentFountain( DocumentFountain.TYPE_SAX,rs, map );
df.setCode("SJIS");
}
catch(Exception e)
{
e.printStackTrace();
return;
}
try
{
while(df.hasXMLDocument())
{
//
// This section specifies application processing received as a SAX event.
SAXhandler sh = new SAXhandler();
df.setDestination(sh);
df.getXMLDocument();
}
rs.close(); // If the input is from a database, connection release is also required.
}
catch(Exception e)
{
e.printStackTrace();
return;
}
}
}
class SAXhandler extends DefaultHandler
{
:
}
|
All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006