{"id":465,"date":"2023-07-17T22:25:33","date_gmt":"2022-08-27T08:24:53","guid":{"rendered":"https:\/\/www.silicloud.com\/ja\/blog\/index.php\/2023\/11\/30\/java-sax-%e3%83%91%e3%83%bc%e3%82%b5%e3%83%bc%e3%81%ae%e4%be%8b\/"},"modified":"2025-07-31T23:48:03","modified_gmt":"2025-07-31T14:48:03","slug":"java-sax-%e3%83%91%e3%83%bc%e3%82%b5%e3%83%bc%e3%81%ae%e4%be%8b","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/ja\/blog\/java-sax-%e3%83%91%e3%83%bc%e3%82%b5%e3%83%bc%e3%81%ae%e4%be%8b\/","title":{"rendered":"Java SAX \u30d1\u30fc\u30b5\u30fc\u306e\u4f8b"},"content":{"rendered":"<p>Java\u306eSAX\u30d1\u30fc\u30b5\u30fc\u306f\u3001XML\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3092\u89e3\u6790\u3059\u308b\u305f\u3081\u306eAPI\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002SAX\u30d1\u30fc\u30b5\u30fc\u306fDOM\u30d1\u30fc\u30b5\u30fc\u3068\u306f\u7570\u306a\u308a\u3001\u5b8c\u5168\u306aXML\u3092\u30e1\u30e2\u30ea\u306b\u30ed\u30fc\u30c9\u305b\u305a\u306b\u3001XML\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3092\u9806\u6b21\u8aad\u307f\u8fbc\u3080\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>SAX \u30d1\u30fc\u30b5\u30fc<\/h2>\n<p>\u4ee5\u4e0b\u306f\u65e5\u672c\u8a9e\u306e\u521d\u3081\u304b\u3089\u306e\u8981\u7d04\u3067\u3059\uff1a<\/p>\n<p>javax.xml.parsers.SAXParser\u306f\u3001\u30a4\u30d9\u30f3\u30c8\u30cf\u30f3\u30c9\u30e9\u3092\u4f7f\u7528\u3057\u3066XML\u6587\u66f8\u3092\u89e3\u6790\u3059\u308b\u305f\u3081\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u3053\u306e\u30af\u30e9\u30b9\u306f\u3001XMLReader\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u5b9f\u88c5\u3057\u3001parse()\u30e1\u30bd\u30c3\u30c9\u306e\u30aa\u30fc\u30d0\u30fc\u30ed\u30fc\u30c9\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u63d0\u4f9b\u3057\u3066\u3001\u30d5\u30a1\u30a4\u30eb\u3001InputStream\u3001SAX InputSource\u3001\u304a\u3088\u3073\u6587\u5b57\u5217URI\u304b\u3089XML\u6587\u66f8\u3092\u8aad\u307f\u53d6\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u5b9f\u969b\u306e\u89e3\u6790\u306fHandler\u30af\u30e9\u30b9\u306b\u3088\u3063\u3066\u884c\u308f\u308c\u307e\u3059\u3002\u81ea\u5206\u81ea\u8eab\u306e\u30cf\u30f3\u30c9\u30e9\u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3057\u3066XML\u6587\u66f8\u3092\u89e3\u6790\u3059\u308b\u305f\u3081\u306b\u306f\u3001org.xml.sax.ContentHandler\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u5b9f\u88c5\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u306e\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u306b\u306f\u3001\u30a4\u30d9\u30f3\u30c8\u304c\u767a\u751f\u3057\u305f\u3068\u304d\u306b\u901a\u77e5\u3092\u53d7\u3051\u53d6\u308b\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u30e1\u30bd\u30c3\u30c9\u304c\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002\u305f\u3068\u3048\u3070\u3001StartDocument\u3001EndDocument\u3001StartElement\u3001EndElement\u3001CharacterData\u306a\u3069\u3067\u3059\u3002org.xml.sax.helpers.DefaultHandler\u306fContentHandler\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u5b9f\u88c5\u3092\u63d0\u4f9b\u3057\u3066\u304a\u308a\u3001\u3053\u306e\u30af\u30e9\u30b9\u3092\u62e1\u5f35\u3057\u3066\u81ea\u5206\u81ea\u8eab\u306e\u30cf\u30f3\u30c9\u30e9\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u5b9f\u88c5\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u304c\u307b\u3068\u3093\u3069\u306a\u3044\u5834\u5408\u306f\u3001\u3053\u306e\u30af\u30e9\u30b9\u3092\u62e1\u5f35\u3059\u308b\u3053\u3068\u3092\u304a\u52e7\u3081\u3057\u307e\u3059\u3002\u3053\u306e\u30af\u30e9\u30b9\u3092\u62e1\u5f35\u3059\u308b\u3053\u3068\u3067\u3001\u30b3\u30fc\u30c9\u3092\u3088\u308a\u7dba\u9e97\u306b\u4fdd\u3061\u3001\u4fdd\u5b88\u6027\u3092\u9ad8\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>SAX\u30d1\u30fc\u30b5\u30fc\u306e\u4f8b<\/h3>\n<p>\u3067\u306f\u3001SAX\u30d1\u30fc\u30b5\u30fc\u306e\u4f8b\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u79fb\u308a\u307e\u3057\u3087\u3046\u3002\u5f8c\u3067\u3001\u7570\u306a\u308b\u6a5f\u80fd\u306b\u3064\u3044\u3066\u8a73\u3057\u304f\u8aac\u660e\u3057\u307e\u3059\u3002employees.xml<\/p>\n<pre class=\"post-pre\"><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;Employees&gt;\r\n\t&lt;Employee id=\"1\"&gt;\r\n\t\t&lt;age&gt;29&lt;\/age&gt;\r\n\t\t&lt;name&gt;Pankaj&lt;\/name&gt;\r\n\t\t&lt;gender&gt;Male&lt;\/gender&gt;\r\n\t\t&lt;role&gt;Java Developer&lt;\/role&gt;\r\n\t&lt;\/Employee&gt;\r\n\t&lt;Employee id=\"2\"&gt;\r\n\t\t&lt;age&gt;35&lt;\/age&gt;\r\n\t\t&lt;name&gt;Lisa&lt;\/name&gt;\r\n\t\t&lt;gender&gt;Female&lt;\/gender&gt;\r\n\t\t&lt;role&gt;CEO&lt;\/role&gt;\r\n\t&lt;\/Employee&gt;\r\n\t&lt;Employee id=\"3\"&gt;\r\n\t\t&lt;age&gt;40&lt;\/age&gt;\r\n\t\t&lt;name&gt;Tom&lt;\/name&gt;\r\n\t\t&lt;gender&gt;Male&lt;\/gender&gt;\r\n\t\t&lt;role&gt;Manager&lt;\/role&gt;\r\n\t&lt;\/Employee&gt;\r\n\t&lt;Employee id=\"4\"&gt;\r\n\t\t&lt;age&gt;25&lt;\/age&gt;\r\n\t\t&lt;name&gt;Meghna&lt;\/name&gt;\r\n\t\t&lt;gender&gt;Female&lt;\/gender&gt;\r\n\t\t&lt;role&gt;Manager&lt;\/role&gt;\r\n\t&lt;\/Employee&gt;\r\n&lt;\/Employees&gt;\r\n<\/code><\/pre>\n<p>\u79c1\u305f\u3061\u306f\u30d5\u30a1\u30a4\u30eb\u30b7\u30b9\u30c6\u30e0\u306e\u3069\u3053\u304b\u306bXML\u30d5\u30a1\u30a4\u30eb\u304c\u4fdd\u5b58\u3055\u308c\u3066\u3044\u308b\u306e\u3092\u898b\u308b\u3068\u3001\u305d\u306e\u4e2d\u306b\u306f\u5f93\u696d\u54e1\u306e\u30ea\u30b9\u30c8\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002\u5404\u5f93\u696d\u54e1\u306b\u306f\u300cid\u300d\u5c5e\u6027\u3068\u300cage\u300d\u3001\u300cname\u300d\u3001\u300cgender\u300d\u3001\u300crole\u300d\u3068\u3044\u3046\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u3042\u308a\u307e\u3059\u3002\u79c1\u305f\u3061\u306fSAX\u30d1\u30fc\u30b5\u30fc\u3092\u4f7f\u7528\u3057\u3066\u3053\u306eXML\u3092\u89e3\u6790\u3057\u3001\u5f93\u696d\u54e1\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30ea\u30b9\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306b\u3001XML\u304b\u3089\u62bd\u51fa\u3057\u305f\u5f93\u696d\u54e1\u8981\u7d20\u3092\u8868\u3059Employee\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.scdev.xml;\r\n\r\npublic class Employee {\r\n    private int id;\r\n    private String name;\r\n    private String gender;\r\n    private int age;\r\n    private String role;\r\n    \r\n    public int getId() {\r\n        return id;\r\n    }\r\n    public void setId(int id) {\r\n        this.id = id;\r\n    }\r\n    public String getName() {\r\n        return name;\r\n    }\r\n    public void setName(String name) {\r\n        this.name = name;\r\n    }\r\n    public String getGender() {\r\n        return gender;\r\n    }\r\n    public void setGender(String gender) {\r\n        this.gender = gender;\r\n    }\r\n    public int getAge() {\r\n        return age;\r\n    }\r\n    public void setAge(int age) {\r\n        this.age = age;\r\n    }\r\n    public String getRole() {\r\n        return role;\r\n    }\r\n    public void setRole(String role) {\r\n        this.role = role;\r\n    }\r\n    \r\n    @Override\r\n    public String toString() {\r\n        return \"Employee:: ID=\"+this.id+\" Name=\" + this.name + \" Age=\" + this.age + \" Gender=\" + this.gender +\r\n                \" Role=\" + this.role;\r\n    }\r\n    \r\n}\r\n<\/code><\/pre>\n<p>\u30c7\u30d5\u30a9\u30eb\u30c8 \u30cf\u30f3\u30c9\u30e9\u30af\u30e9\u30b9\u3092\u62e1\u5f35\u3057\u305f SAX \u30d1\u30fc\u30b5\u30cf\u30f3\u30c9\u30e9\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"post-pre\"><code>\r\npackage com.scdev.xml.sax;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\n\r\nimport org.xml.sax.Attributes;\r\nimport org.xml.sax.SAXException;\r\nimport org.xml.sax.helpers.DefaultHandler;\r\n\r\nimport com.scdev.xml.Employee;\r\n\r\npublic class MyHandler extends DefaultHandler {\r\n\r\n\t\/\/ List to hold Employees object\r\n\tprivate List&lt;Employee&gt; empList = null;\r\n\tprivate Employee emp = null;\r\n\tprivate StringBuilder data = null;\r\n\r\n\t\/\/ getter method for employee list\r\n\tpublic List&lt;Employee&gt; getEmpList() {\r\n\t\treturn empList;\r\n\t}\r\n\r\n\tboolean bAge = false;\r\n\tboolean bName = false;\r\n\tboolean bGender = false;\r\n\tboolean bRole = false;\r\n\r\n\t@Override\r\n\tpublic void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {\r\n\r\n\t\tif (qName.equalsIgnoreCase(\"Employee\")) {\r\n\t\t\t\/\/ create a new Employee and put it in Map\r\n\t\t\tString id = attributes.getValue(\"id\");\r\n\t\t\t\/\/ initialize Employee object and set id attribute\r\n\t\t\temp = new Employee();\r\n\t\t\temp.setId(Integer.parseInt(id));\r\n\t\t\t\/\/ initialize list\r\n\t\t\tif (empList == null)\r\n\t\t\t\tempList = new ArrayList&lt;&gt;();\r\n\t\t} else if (qName.equalsIgnoreCase(\"name\")) {\r\n\t\t\t\/\/ set boolean values for fields, will be used in setting Employee variables\r\n\t\t\tbName = true;\r\n\t\t} else if (qName.equalsIgnoreCase(\"age\")) {\r\n\t\t\tbAge = true;\r\n\t\t} else if (qName.equalsIgnoreCase(\"gender\")) {\r\n\t\t\tbGender = true;\r\n\t\t} else if (qName.equalsIgnoreCase(\"role\")) {\r\n\t\t\tbRole = true;\r\n\t\t}\r\n\t\t\/\/ create the data container\r\n\t\tdata = new StringBuilder();\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void endElement(String uri, String localName, String qName) throws SAXException {\r\n\t\tif (bAge) {\r\n\t\t\t\/\/ age element, set Employee age\r\n\t\t\temp.setAge(Integer.parseInt(data.toString()));\r\n\t\t\tbAge = false;\r\n\t\t} else if (bName) {\r\n\t\t\temp.setName(data.toString());\r\n\t\t\tbName = false;\r\n\t\t} else if (bRole) {\r\n\t\t\temp.setRole(data.toString());\r\n\t\t\tbRole = false;\r\n\t\t} else if (bGender) {\r\n\t\t\temp.setGender(data.toString());\r\n\t\t\tbGender = false;\r\n\t\t}\r\n\t\t\r\n\t\tif (qName.equalsIgnoreCase(\"Employee\")) {\r\n\t\t\t\/\/ add Employee object to list\r\n\t\t\tempList.add(emp);\r\n\t\t}\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void characters(char ch[], int start, int length) throws SAXException {\r\n\t\tdata.append(new String(ch, start, length));\r\n\t}\r\n}\r\n<\/code><\/pre>\n<p>MyHandler\u30af\u30e9\u30b9\u306f\u3001\u30b2\u30c3\u30bf\u30fc\u30e1\u30bd\u30c3\u30c9\u3092\u6301\u3064\u30d5\u30a3\u30fc\u30eb\u30c9\u3068\u3057\u3066\u3001Employee\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30ea\u30b9\u30c8\u3092\u4fdd\u6301\u3057\u3066\u3044\u307e\u3059\u3002Employee\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u3001\u30a4\u30d9\u30f3\u30c8\u30cf\u30f3\u30c9\u30e9\u30fc\u30e1\u30bd\u30c3\u30c9\u5185\u3067\u8ffd\u52a0\u3055\u308c\u307e\u3059\u3002\u307e\u305f\u3001Employee\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u308bEmployee\u30d5\u30a3\u30fc\u30eb\u30c9\u3082\u3042\u308a\u3001\u5168\u3066\u306e\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u8a2d\u5b9a\u3055\u308c\u305f\u5f8c\u3067\u3001\u305d\u308c\u3092\u5f93\u696d\u54e1\u30ea\u30b9\u30c8\u306b\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n<h3>SAX\u30d1\u30fc\u30b5\u30fc\u30e1\u30bd\u30c3\u30c9\u306e\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3059\u308b\u65b9\u6cd5<\/h3>\n<p>\u91cd\u8981\u306a\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u306fstartElement()\u3001endElement()\u3001characters()\u3067\u3059\u3002SAXParser\u306f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306e\u89e3\u6790\u3092\u958b\u59cb\u3057\u3001\u958b\u59cb\u8981\u7d20\u304c\u898b\u3064\u304b\u308b\u3068startElement()\u30e1\u30bd\u30c3\u30c9\u304c\u547c\u3073\u51fa\u3055\u308c\u307e\u3059\u3002\u79c1\u305f\u3061\u306f\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3057\u3066\u3001\u8981\u7d20\u3092\u8b58\u5225\u3059\u308b\u305f\u3081\u306b\u4f7f\u7528\u3055\u308c\u308b\u30d6\u30fc\u30eb\u5909\u6570\u3092\u8a2d\u5b9a\u3057\u307e\u3059\u3002\u307e\u305f\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u3001Employee\u306e\u958b\u59cb\u8981\u7d20\u304c\u898b\u3064\u304b\u308b\u305f\u3073\u306b\u65b0\u3057\u3044Employee\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u3001id\u5c5e\u6027\u304c\u3069\u306e\u3088\u3046\u306b\u8aad\u307f\u8fbc\u307e\u308c\u3001Employee\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306eid\u30d5\u30a3\u30fc\u30eb\u30c9\u304c\u8a2d\u5b9a\u3055\u308c\u308b\u304b\u3092\u78ba\u8a8d\u3057\u3066\u304f\u3060\u3055\u3044\u3002characters()\u30e1\u30bd\u30c3\u30c9\u306f\u3001SAXParser\u304c\u8981\u7d20\u5185\u3067\u6587\u5b57\u30c7\u30fc\u30bf\u3092\u898b\u3064\u3051\u308b\u3068\u304d\u306b\u547c\u3073\u51fa\u3055\u308c\u307e\u3059\u3002SAX\u30d1\u30fc\u30b5\u30fc\u306f\u30c7\u30fc\u30bf\u3092\u8907\u6570\u306e\u30c1\u30e3\u30f3\u30af\u306b\u5206\u5272\u3057\u3001characters()\u30e1\u30bd\u30c3\u30c9\u3092\u8907\u6570\u56de\u547c\u3073\u51fa\u3059\u3053\u3068\u304c\u3042\u308b\u3053\u3068\u306b\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\uff08ContentHandler\u30af\u30e9\u30b9\u306echaracters()\u30e1\u30bd\u30c3\u30c9\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3092\u8aad\u3093\u3067\u304f\u3060\u3055\u3044\uff09\u3002\u305d\u306e\u305f\u3081\u3001\u3053\u306e\u30c7\u30fc\u30bf\u3092\u4fdd\u6301\u3059\u308b\u305f\u3081\u306bStringBuilder\u3092\u4f7f\u7528\u3057\u3066append()\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002endElement()\u306f\u3001StringBuilder\u306e\u30c7\u30fc\u30bf\u3092\u4f7f\u7528\u3057\u3066employee\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u8a2d\u5b9a\u3057\u3001Employee\u306e\u7d42\u4e86\u8981\u7d20\u30bf\u30b0\u304c\u898b\u3064\u304b\u308b\u305f\u3073\u306bEmployee\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u30ea\u30b9\u30c8\u306b\u8ffd\u52a0\u3059\u308b\u5834\u6240\u3067\u3059\u3002\u4ee5\u4e0b\u306f\u3001\u4e0a\u8a18\u306eXML\u3092Employee\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30ea\u30b9\u30c8\u306b\u89e3\u6790\u3059\u308b\u305f\u3081\u306bMyHandler\u3092\u4f7f\u7528\u3059\u308b\u30c6\u30b9\u30c8\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.scdev.xml.sax;\r\n\r\nimport java.io.File;\r\nimport java.io.IOException;\r\nimport java.util.List;\r\n\r\nimport javax.xml.parsers.ParserConfigurationException;\r\nimport javax.xml.parsers.SAXParser;\r\nimport javax.xml.parsers.SAXParserFactory;\r\n\r\nimport org.xml.sax.SAXException;\r\n\r\nimport com.scdev.xml.Employee;\r\n\r\npublic class XMLParserSAX {\r\n\r\n    public static void main(String[] args) {\r\n    SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();\r\n    try {\r\n        SAXParser saxParser = saxParserFactory.newSAXParser();\r\n        MyHandler handler = new MyHandler();\r\n        saxParser.parse(new File(\"\/Users\/scdev\/employees.xml\"), handler);\r\n        \/\/Get Employees list\r\n        List&lt;Employee&gt; empList = handler.getEmpList();\r\n        \/\/print employee information\r\n        for(Employee emp : empList)\r\n            System.out.println(emp);\r\n    } catch (ParserConfigurationException | SAXException | IOException e) {\r\n        e.printStackTrace();\r\n    }\r\n    }\r\n\r\n}\r\n<\/code><\/pre>\n<p>\u4e0a\u8a18\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u51fa\u529b\u306f\u3053\u3061\u3089\u3067\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>Employee:: ID=1 Name=Pankaj Age=29 Gender=Male Role=Java Developer\r\nEmployee:: ID=2 Name=Lisa Age=35 Gender=Female Role=CEO\r\nEmployee:: ID=3 Name=Tom Age=40 Gender=Male Role=Manager\r\nEmployee:: ID=4 Name=Meghna Age=25 Gender=Female Role=Manager\r\n<\/code><\/pre>\n<p>SAXParserFactory\u306f\u3001SAXParser\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306e\u30d5\u30a1\u30af\u30c8\u30ea\u30e1\u30bd\u30c3\u30c9\u3092\u63d0\u4f9b\u3057\u3066\u3044\u307e\u3059\u3002parse\u30e1\u30bd\u30c3\u30c9\u306b\u306f\u3001File\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068MyHandler\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u30a4\u30d9\u30f3\u30c8\u306e\u51e6\u7406\u306b\u6e21\u3057\u307e\u3059\u3002SAXParser\u306f\u6700\u521d\u306f\u5c11\u3057\u6df7\u4e71\u3057\u307e\u3059\u304c\u3001\u5927\u304d\u306aXML\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3067\u4f5c\u696d\u3057\u3066\u3044\u308b\u5834\u5408\u3001DOM Parser\u3088\u308a\u3082\u52b9\u7387\u7684\u306aXML\u306e\u8aad\u307f\u53d6\u308a\u65b9\u6cd5\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u3053\u308c\u3067Java\u306b\u304a\u3051\u308bSAX Parser\u306e\u8aac\u660e\u306f\u7d42\u308f\u308a\u3067\u3059\u3002<\/p>\n<p>\u5f53\u793e\u306eGitHub\u30ea\u30dd\u30b8\u30c8\u30ea\u304b\u3089\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u53c2\u8003\uff1aSAXParser\u3001DefaultHandler<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java\u306eSAX\u30d1\u30fc\u30b5\u30fc\u306f\u3001XML\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3092\u89e3\u6790\u3059\u308b\u305f\u3081\u306eAPI\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002SAX\u30d1\u30fc\u30b5\u30fc\u306fDOM\u30d1\u30fc\u30b5\u30fc\u3068\u306f\u7570\u306a\u308a\u3001\u5b8c\u5168\u306aXML\u3092\u30e1\u30e2\u30ea\u306b\u30ed\u30fc\u30c9\u305b\u305a\u306b\u3001XML\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3092\u9806\u6b21\u8aad\u307f\u8fbc\u3080\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002 SAX \u30d1 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[26,61],"class_list":["post-465","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-26","tag-61"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java SAX \u30d1\u30fc\u30b5\u30fc\u306e\u4f8b - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"Java SAX \u30d1\u30fc\u30b5\u30fc\u306e\u4f8b\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/ja\/blog\/java-sax-\u30d1\u30fc\u30b5\u30fc\u306e\u4f8b\/\" \/>\n<meta property=\"og:locale\" content=\"ja_JP\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java SAX \u30d1\u30fc\u30b5\u30fc\u306e\u4f8b\" \/>\n<meta property=\"og:description\" content=\"Java SAX \u30d1\u30fc\u30b5\u30fc\u306e\u4f8b\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/ja\/blog\/java-sax-\u30d1\u30fc\u30b5\u30fc\u306e\u4f8b\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-27T08:24:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-31T14:48:03+00:00\" \/>\n<meta name=\"author\" content=\"\u967d, \u5411\u5b87\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u57f7\u7b46\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u967d, \u5411\u5b87\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593\" \/>\n\t<meta name=\"twitter:data2\" content=\"17\u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/java-sax-%e3%83%91%e3%83%bc%e3%82%b5%e3%83%bc%e3%81%ae%e4%be%8b\/\",\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/java-sax-%e3%83%91%e3%83%bc%e3%82%b5%e3%83%bc%e3%81%ae%e4%be%8b\/\",\"name\":\"Java SAX \u30d1\u30fc\u30b5\u30fc\u306e\u4f8b - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#website\"},\"datePublished\":\"2022-08-27T08:24:53+00:00\",\"dateModified\":\"2025-07-31T14:48:03+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/4aef6196128551a0f5d66db46c42866c\"},\"description\":\"Java SAX \u30d1\u30fc\u30b5\u30fc\u306e\u4f8b\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/java-sax-%e3%83%91%e3%83%bc%e3%82%b5%e3%83%bc%e3%81%ae%e4%be%8b\/#breadcrumb\"},\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/ja\/blog\/java-sax-%e3%83%91%e3%83%bc%e3%82%b5%e3%83%bc%e3%81%ae%e4%be%8b\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/java-sax-%e3%83%91%e3%83%bc%e3%82%b5%e3%83%bc%e3%81%ae%e4%be%8b\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/ja\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java SAX \u30d1\u30fc\u30b5\u30fc\u306e\u4f8b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"ja\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/4aef6196128551a0f5d66db46c42866c\",\"name\":\"\u967d, \u5411\u5b87\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ad96b120e219751fa368cbd7d2c48ca01b59185e6ed394449bac72614a760bf3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ad96b120e219751fa368cbd7d2c48ca01b59185e6ed394449bac72614a760bf3?s=96&d=mm&r=g\",\"caption\":\"\u967d, \u5411\u5b87\"},\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/author\/hinatasora\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/java-sax-%e3%83%91%e3%83%bc%e3%82%b5%e3%83%bc%e3%81%ae%e4%be%8b\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Java SAX \u30d1\u30fc\u30b5\u30fc\u306e\u4f8b - Blog - Silicon Cloud","description":"Java SAX \u30d1\u30fc\u30b5\u30fc\u306e\u4f8b\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/ja\/blog\/java-sax-\u30d1\u30fc\u30b5\u30fc\u306e\u4f8b\/","og_locale":"ja_JP","og_type":"article","og_title":"Java SAX \u30d1\u30fc\u30b5\u30fc\u306e\u4f8b","og_description":"Java SAX \u30d1\u30fc\u30b5\u30fc\u306e\u4f8b\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","og_url":"https:\/\/www.silicloud.com\/ja\/blog\/java-sax-\u30d1\u30fc\u30b5\u30fc\u306e\u4f8b\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2022-08-27T08:24:53+00:00","article_modified_time":"2025-07-31T14:48:03+00:00","author":"\u967d, \u5411\u5b87","twitter_card":"summary_large_image","twitter_misc":{"\u57f7\u7b46\u8005":"\u967d, \u5411\u5b87","\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593":"17\u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/ja\/blog\/java-sax-%e3%83%91%e3%83%bc%e3%82%b5%e3%83%bc%e3%81%ae%e4%be%8b\/","url":"https:\/\/www.silicloud.com\/ja\/blog\/java-sax-%e3%83%91%e3%83%bc%e3%82%b5%e3%83%bc%e3%81%ae%e4%be%8b\/","name":"Java SAX \u30d1\u30fc\u30b5\u30fc\u306e\u4f8b - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/#website"},"datePublished":"2022-08-27T08:24:53+00:00","dateModified":"2025-07-31T14:48:03+00:00","author":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/4aef6196128551a0f5d66db46c42866c"},"description":"Java SAX \u30d1\u30fc\u30b5\u30fc\u306e\u4f8b\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/java-sax-%e3%83%91%e3%83%bc%e3%82%b5%e3%83%bc%e3%81%ae%e4%be%8b\/#breadcrumb"},"inLanguage":"ja","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/ja\/blog\/java-sax-%e3%83%91%e3%83%bc%e3%82%b5%e3%83%bc%e3%81%ae%e4%be%8b\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/ja\/blog\/java-sax-%e3%83%91%e3%83%bc%e3%82%b5%e3%83%bc%e3%81%ae%e4%be%8b\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/ja\/blog\/"},{"@type":"ListItem","position":2,"name":"Java SAX \u30d1\u30fc\u30b5\u30fc\u306e\u4f8b"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#website","url":"https:\/\/www.silicloud.com\/ja\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"ja"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/4aef6196128551a0f5d66db46c42866c","name":"\u967d, \u5411\u5b87","image":{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ad96b120e219751fa368cbd7d2c48ca01b59185e6ed394449bac72614a760bf3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ad96b120e219751fa368cbd7d2c48ca01b59185e6ed394449bac72614a760bf3?s=96&d=mm&r=g","caption":"\u967d, \u5411\u5b87"},"url":"https:\/\/www.silicloud.com\/ja\/blog\/author\/hinatasora\/"},{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.silicloud.com\/ja\/blog\/java-sax-%e3%83%91%e3%83%bc%e3%82%b5%e3%83%bc%e3%81%ae%e4%be%8b\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/comments?post=465"}],"version-history":[{"count":1,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/465\/revisions"}],"predecessor-version":[{"id":40960,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/465\/revisions\/40960"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/media?parent=465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/categories?post=465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/tags?post=465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}