Knigesserse
New Member
I have used script below and the output is
X value : 123Y value : 123X value : 123Y value : 130how can I set first X as X0; first Y as Y0 and second X as X1 and second Y as Y1 ? I used SAX parser, it has processed my input file properly, and now i want to define X0, X1, Y0, Y1 in order to draw line\[code\]public static void main(String argv[]) { try { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); DefaultHandler handler = new DefaultHandler() { 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; } if (yele) { System.out.println("Y value : " + new String(ch, start, length)); yele = false; } } }; saxParser.parse("c:\\input.xml", handler); } catch (Exception e) { e.printStackTrace(); }\[/code\]Thanks
X value : 123Y value : 123X value : 123Y value : 130how can I set first X as X0; first Y as Y0 and second X as X1 and second Y as Y1 ? I used SAX parser, it has processed my input file properly, and now i want to define X0, X1, Y0, Y1 in order to draw line\[code\]public static void main(String argv[]) { try { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); DefaultHandler handler = new DefaultHandler() { 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; } if (yele) { System.out.println("Y value : " + new String(ch, start, length)); yele = false; } } }; saxParser.parse("c:\\input.xml", handler); } catch (Exception e) { e.printStackTrace(); }\[/code\]Thanks