SAXParser は初めてなので、ご容赦ください。
XML ファイルを解析して .xml に変換するにはどうすればよいList<XNode>
ですか? 以下は、クラス XNode の構造です。
class XNode{
private String nodeName;
private String nodeValue;
private List<XAttribute> attributes;
private boolean isParentNode;
private List<XNode> childNodes;
}
また、XAttribute の構造:
class XAttribute{
private String name;
private String value;
}
ファイルを解析すると、List オブジェクトが返されます。
これまでのところ、以下のコードを試しましたが、childNodes を確認してアタッチする方法がわかりません。
public class XmlProcesser extends DefaultHandler {
XMLResponse xmlResponse = null;
boolean endtag = false;
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
System.out.print("" + qName + "");
if (attributes.getLength() == 0) {
} else {
for (int index = 0; index < attributes.getLength(); index++) {
System.out.print(attributes.getLocalName(index) + " = " + attributes.getValue(index));
}
}
}
@Override
public void characters(char ch[], int start, int length) throws SAXException {
String s = new String(ch, start, length);
System.out.println(s);
endtag = false;
}
@Override
public void endElement(String uri, String localName,
String qName) throws SAXException {
endtag = true;
System.out.print(" " + qName + " ");
}
}