我使用了下面的脚本,输出是
X 值:123 Y 值:123 X 值:123 Y 值:130
如何将第一个 X 设置为 X0;第一个 Y 作为 Y0,第二个 X 作为 X1,第二个 Y 作为 Y1?我使用了 SAX 解析器,它已经正确处理了我的输入文件,现在我想定义 X0、X1、Y0、Y1 以画线
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();
}
谢谢