Thursday, April 17, 2008

Parsing XML present within Documentum Server

Here is the Java method for parsing an XML file present within documentum. In this case JDOM has been used for the parsing purpose . Other Document parsers can also be used.

/*The argument of the method is the documentum session object and r_object_id of the xml document. The method returns a org.jdom.Document object which can then be used to parse the XML file (ref: http://www.jdom.org/) .*/

private Document parseXML(IDfSession losession,String r_object_id)
{
IDfSysObject xmlObj =null;
Document document=null;
try
{
xmlObj =(IDfSysObject) losession.getObject(new DfId(r_object_id));
System.out.println("objectname= "+xmlObj.getObjectName());
ByteArrayInputStream bis=xmlObj.getContent();
/*getContent() method returns a ByteArrayInputStream object of the file present in
content server. This method is also helpful in reading files having other extensions. */
SAXBuilder builder = new SAXBuilder();
document = builder.build(bis);
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
return document;
}
}