Skip to Content
0
Former Member
Jul 06, 2006 at 11:15 AM

updating .xml files through JAVA?

15 Views

Hi all,

I am Krishna..

I need to basically parse the content of the XML form and do a text replace. The Promotions that are created by the users will also reference images. These references are stored in the XMLforms (which are basically XML files). When the Promotions are being 'submitted' the file path within the XMLForms should be updated with the target location.

<b>Example:</b>

Source Location where Promotion was created:

/myForms/filesystem/Partner Promotion/user1_folder/

Target Location where the Promotion is to be copied:

/myForms/filesystem/Submitted Promotions/user1_folder/

The Promotion XMLForm should be parsed for occurrences of “/myForms/filesystem/Partner Promotion/user1_folder/” and replaced

with “/myForms/filesystem/Submitted Promotions/user1_folder/”

Problem is that, i am unable to build the XML file:

try {
	String rpathString = "/documents/Test/promotions/Contacts.xml";
	
	com.sapportals.portal.security.usermanagement.IUser user =
		WPUMFactory.getUserFactory().getEP5User(request.getUser());
	IResourceContext ctxt = new ResourceContext(user);
	RID rid = RID.getRID(rpathString);
	IResource resource =
		ResourceFactory.getInstance().getResource(rid, ctxt);
	
	//read the xml file
	   SAXBuilder builder = new SAXBuilder();
	  <b>Document doc = builder.build(new File(resource.getName()));</b> <i>//getting exception at this line</i>
	   Element root = doc.getRootElement();
	   List list = root.getChildren("contact");
	   Iterator iter = list.iterator();
	   while(iter.hasNext()) {
		Element e = (Element)iter.next();
		String name = e.getChild("name").getText();
		response.write("<br>name:"+name);
		String address = e.getChild("address").getText();
		response.write(":::address:"+address);
	}
} catch (Exception e) {
   response.write(e.getLocalizedMessage());
   e.printStackTrace();
}

I have also tried with

new File("http://<server>:50000/irj/go/km/docs/documents/Test/promotions/Contacts.xml");

and

new File(resource.getAccessURI());

.. but i don't get it. 😔

<b>PS:</b> i have added <b>jdom.jar</b> file in the build path

Plz help . .. Thanking you in advance!

Regards,

Krish.