Skip to content

Instantly share code, notes, and snippets.

@shomah4a
Created December 19, 2014 08:05
Show Gist options
  • Save shomah4a/70bbf4214991b760d3fa to your computer and use it in GitHub Desktop.
Save shomah4a/70bbf4214991b760d3fa to your computer and use it in GitHub Desktop.
ほっけ
import java.io.File;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
public class Hokke
{
static class Handler extends DefaultHandler
{
public void startElement(String uri,
String localName,
String qName,
Attributes attributes)
{
System.out.println("attribute: " + attributes.getValue("hokke"));
}
public void characters(char[] ch,
int offset,
int length)
{
System.out.println("text: " + new String(ch, offset, length));
}
}
public static void main(String[] args) throws Exception
{
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
parser.parse(new File("hokke.xml"), new Handler());
}
}
<!--*- coding:utf-8 -*-->
<xml>
<hoge hokke="𩸽">𩸽</hoge>
<hoge hokke="𩸽">𩸽</hoge>
<hoge hokke="𩸽">𩸽</hoge>
<hoge hokke="𩸽">𩸽</hoge>
</xml>
$ java Hokke
attribute: null
text:
attribute: 𩸽
text: 𩸽
text:
attribute: 𩸽𩸽
text: 𩸽
text:
attribute: 𩸽𩸽𩸽
text: 𩸽
text:
attribute: 𩸽𩸽𩸽𩸽
text: 𩸽
text:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment