rendered paste bodyimport java.io.*;
import java.util.*;
import java.util.ArrayList;
// JDOM
import org.jdom.*;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.SAXOutputter;
public class XMLhandling
{
SAXBuilder builder = new SAXBuilder();
// reference on IOclass object
private IOclass currentIO;
// constructur of XMLhandling
public XMLhandling (IOclass oneIO) throws Exception
{
try
{
this.setIOCLASS(oneIO);
}
catch (Exception e)
{
System.out.println("XMLHANDLING: "+e.getMessage());
throw e;
}
}
// set Io class
public void setIOCLASS(IOclass oneIO) throws Exception
{
this.currentIO=oneIO;
try
{
this.getData();
}
catch(Exception e)
{
System.out.println("setIOCLASS: "+e.getMessage());
throw e;
}
}
public ArrayList<String> getIndivFormdata(int n, ArrayList<String> list1, ArrayList<String> list2, ArrayList<String> list3)
{
ArrayList<String> indiv_formdata = new ArrayList<String>();
indiv_formdata.add(list1.get(n));
indiv_formdata.add(list2.get(n));
indiv_formdata.add(list3.get(n));
return indiv_formdata;
}
private void getData() throws Exception
{
try
{
SAXBuilder builder = new SAXBuilder();
Document XMLdoc = builder.build("targets.xml");
// arraylists for attributes
ArrayList<String> list_fieldname = new ArrayList<String>();
ArrayList<String> list_fieldvalue = new ArrayList<String>();
ArrayList<String> list_fielddescrip = new ArrayList<String>();
ArrayList<String> indivList = new ArrayList<String>();
Element targets = XMLdoc.getRootElement();
Element form = targets.getChild("formfields");
List forminfos = form.getChildren();
Iterator formIterator = forminfos.iterator();
while (formIterator.hasNext())
{
Element actelement = (Element)formIterator.next(); // next Element of formfield
List actAttributes = actelement.getAttributes();
list_fieldname.add(actelement.getAttributeValue("fieldname"));
list_fieldvalue.add(actelement.getAttributeValue("fieldvalue"));
list_fielddescrip.add(actelement.getAttributeValue("fielddescrip"));
}
indivList = getIndivFormdata(2, list_fieldname, list_fieldvalue, list_fielddescrip);
// System.out.println(list_fieldname.get(2));
System.out.println(indivList.get(0));
System.out.println(indivList.get(1));
System.out.println(indivList.get(2));
// System.out.println(list_fielddescrip.size());
// currentIO.setFormdata(2, list_fieldname.get(2))
/* currentIO.setTargetnumber(targets.getAttribute("number").getValue());
currentIO.setTargetip(targets.getChild("ip").getText());
currentIO.setTargetpath(targets.getChild("path").getText());
currentIO.setTargetmethod(targets.getChild("formfields").getAttribute("method").getValue());
currentIO.setFormf_gender1(targets.getChild("formfields").getChild("gender1").getAttribute("name").getValue());
currentIO.setFormf_gender1(targets.getChild("formfields").getChild("gender1").getAttribute("value").getValue());
currentIO.setFormf_gender2(targets.getChild("formfields").getChild("gender2").getAttribute("name").getValue());
currentIO.setFormf_gender2(targets.getChild("formfields").getChild("gender2").getAttribute("value").getValue());
currentIO.setFormf_prename(targets.getChild("formfields").getChild("prename").getAttribute("name").getValue());*/
}
catch (JDOMException e)
{
System.out.println("JDOM Exception: "+e.getMessage());
throw new Exception(e);
}
catch (IOException e)
{
System.out.println("IO Excep:"+e.getMessage());
throw new Exception(e);
}
catch (Exception e)
{
System.out.println((e.getClass()).toString());
}
}
}