Business Objects and Data Sources > Data Sources > Advanced Parsing and Writing of a Data Source

In addition to the basic IlpDefaultDataSource API for parsing an XML file a data source and writing the data source content to an XML file, JViews TGO provides the classes IlpDataSourceLoader and IlpDataSourceOutput for a more advanced use. Both these classes are located in the package ilog.cpl.storage.

Parsing an XML File

The class IlpDataSourceLoader has the following functionality:

How to Modify the Behavior of the XML Reader
IlpDataSourceLoader loader = new IlpDataSourceLoader(inputSource,
                                                     dataSource);
XMLReader reader = loader.getXMLReader();
reader.setFeature("http://xml.org/sax/features/validation",false);
loader.parse();

The example below loads a template file into the data source. It shows how to create an identifier factory to modify parent identifiers of root objects. The complete sample code is located in the following directory:

<installdir>/tutorials/browser

How to Load a File into a Data Source
final Object parentID = expandedObject.getIdentifier();
 
// Create an identifier factory that prepends the parent ID to
// all identifiers read from the template.
IlpIdentifierFactory idFactory = new IlpIdentifierFactory(){
  public Object getIdentifier (Object previousIdentifier){
    return parentID.toString() + "/" + previousIdentifier.toString();
  }
};
// Load the template into the datasource
// Load the template objects under the parent node, and transform
// their IDs so they are unique
IlpDataSourceLoader loader = new IlpDataSourceLoader(templateFileName,
                                                     mainDataSource);
loader.setIdentifierFactory(idFactory);
loader.setParentIdOfRootObjects(parentID);
loader.parse();

Writing to an XML File

The class IlpDataSourceOutput has the following functionality: