/, Java/Read a Single XML File in Java

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.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.*;
import org.dom4j.*;
import java.util.Properties; /* Added for proxy use */
import java.io.IOException;
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(fileDAL.read(absoluteFilePath))  ;
fileElem.add(fileDCR.getRootElement().createCopy())  ;

return doc;

By |2017-11-30T10:42:09+01:00March 2nd, 2009|Articles, Java|0 Comments

About the Author: