Skip to Content
0
Former Member
Jun 20, 2005 at 10:22 AM

Reading data from a XML file.

10 Views

Hi,

I am new user to webdynpro and has the task of reading data from XML file.The file is created using XML form Builder and is stored at a location.But my code gives me the path instead of the content in the data.

The code is :

try

{

IWDClientUser wdClientUser = WDClientUser.getCurrentUser();

com.sap.security.api.IUser sapUser = wdClientUser.getSAPUser();

// create an ep5 user from the retrieved user

IUser ep5User = WPUMFactory.getUserFactory().getEP5User(sapUser);

IResourceContext context = new ResourceContext(ep5User);

/Specify the path of ur document here./

RID pathRID = RID.getRID("/documents/70f51182-84c3-2710-ce91-8d5fbfde713d.xml");

//RID pathRID = RID.getRID("/documents/hol.txt");

wdContext.currentContextElement().setSetDisp(pathRID.toString());

IResource resource = ResourceFactory.getInstance().getResource(pathRID, context);

InputStream in = resource.getContent().getInputStream();

ByteArrayOutputStream out = new ByteArrayOutputStream();

byte[] buffer = new byte[4096];

int bytesread = 0;

while ((bytesread = in.read(buffer)) != -1)

{

out.write(buffer, 0, bytesread);

}

String myData = out.toString();

/*myFile will containS the content of the document./

wdContext.currentContextElement().setSetDisp(myData);

}

catch (Exception e)

{

// wdContext.currentContextElement().setTextdisp("IO Error:" + e.getMessage());

}

text data is read from the location but XML data is not read.

Please help me out.