Read a Single XML File in Java

2 March 2009
by Billy Czajkowska

The following should complement the supplied article for reading XML files (DCRs) based on a directory.  This will read the contents of a singe file

package com.littleforest.examples;
import com.interwoven.livesite.dom4j.Dom4jUtils;
import com.interwoven.livesite.external.ParameterHash;
import com.interwoven.livesite.runtime.RequestContext;
import com.interwoven.livesite.external.*;
import java.util.*;
import org.dom4j.*;
import java.util.Properties; /* Added for proxy use */
import com.interwoven.livesite.file.FileDALIfc; /* Added to avoid use of CDATA write */
public class xmlDcrUtilities{
public Document readSingle(RequestContext context)
//look in any single directory only
Document doc = Dom4jUtils.newDocument();
Element fileElem = doc.addElement("Records");
FileDALIfc fileDAL = context.getFileDal();
String absoluteFilePath = context.getParameterString("DCRPath");
Document fileDCR = Dom4jUtils.newDocument(  ;
fileElem.add(fileDCR.getRootElement().createCopy())  ;
return doc;

Our Latest News