i have problem concerning to XML and java.util.List. In my script Iam able to parse XML file from input and System writes me e.g. [124, 123], [123, 130] (according to this what is in the input file.) but my question is – how to pass values from xList and yList to paint method? What do I Have to do? set/get value? Or maybe is there a better way how to do it. Thanks
part of my script:
try
{
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
MyDefaultHandler handler = new MyDefaultHandler();
saxParser.parse(filechooser.getSelectedFile(), handler);
System.out.println(handler.getXList() + ", " + handler.getYList());
}
catch (Exception exe)
{
exe.printStackTrace();
}
}
}
class MyDefaultHandler extends DefaultHandler
{
final List<Integer> xList = new ArrayList<Integer>();
final List<Integer> yList = new ArrayList<Integer>();
boolean xele = false;
boolean yele = false;
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
{
if (qName.equalsIgnoreCase("X"))
{
xele = true;
}
if (qName.equalsIgnoreCase("Y"))
{
yele = true;
}
}
public void characters(char ch[], int start, int length) throws SAXException
{
if (xele)
{
System.out.println("X value : " + new String(ch, start, length));
xele = false;
xList.add(Integer.parseInt(new String(ch, start, length)));
}
if (yele)
{
System.out.println("Y value : " + new String(ch, start, length));
yele = false;
yList.add(Integer.parseInt(new String(ch, start, length)));
}
;
}
final List<Integer> getXList()
{
return xList;
}
final List<Integer> getYList()
{
return yList;
}
If I understand you question and expecting that the lists are of the same length, you’ll need something like this: