📄 xmltest.java
字号:
package pushbook;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import java.io.*;
import javax.xml.parsers.*;
public class XMLTest extends DefaultHandler
{
public void startDocument() throws SAXException
{
}
public void endDocument () throws SAXException
{
}
public void startElement(String namespaceURI, String localName, String qName, Attributes attr) throws
SAXException
{
if (qName.equals("title"))
{
System.out.print("关卡名称:");
}
else if (qName.equals("music"))
{
System.out.print("背景音乐:");
}
else if (qName.equals("unitSize"))
{
System.out.print("图形元素尺寸:");
}
else if (qName.equals("element"))
{
System.out.println("元素名称:" +
attr.getValue("ID") +
" 图片:" + attr.getValue("img"));
}
else if (qName.equals("mainMap"))
{
System.out.println("主地图:");
}
else if (qName.equals("activeMap"))
{
System.out.println("可动元素地图:");
}
}
public void endElement(String namespaceURI, String localName, String qName) throws SAXException
{
}
public void characters(char[] ch, int start, int length) throws SAXException
{
try
{
String tt = new String(ch);
tt = tt.substring(start, start + length);
if (tt.indexOf("\n") >= 0)return;
System.out.println(tt);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] argv)
{
try
{
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser saxparser = saxparser = spf.newSAXParser();
File XMLFile = new File("D:/Projects/PushBook/src/resource/level_001.xml");
saxparser.parse(XMLFile, new XMLTest());
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -