これに似たオンラインの XML ファイルがあります。
<example>
<date>2012-10-13</date>
<bob>What I already know how to get</bob>
</example>
<example>
<date>2012-10-14</date>
<bob>What I want as well as the above</bob>
</example>
「取得方法が既にわかっているもの」タグでデータを取得するために使用しているものは次のとおりです。
/**
* Gets be called on opening tags like: <tag> Can provide attribute(s), when
* xml was like: <tag attribute="attributeValue">
*/
@Override
public void startElement(String namespaceURI, String localName,
String qName, Attributes atts) throws SAXException {
if (localName.equals("example")) {
this.in_example = true;
} else if (localName.equals("bob")) {
this.in_bob = true;
}
}
/**
* Gets be called on closing tags like: </tag>
*/
@Override
public void endElement(String namespaceURI, String localName, String qName)
throws SAXException {
if (localName.equals("example")) {
this.in_example = false;
} else if (localName.equals("bob")) {
this.in_bob = false;
}
}
/**
* Gets be called on the following structure: <tag>characters</tag>
*/
@Override
public void characters(char ch[], int start, int length) {
if (this.in_bob) {
// A custom DataParser
myDataParser.setExtractedString(new String(ch, start, length));
}
}
わかりました、ここで質問があります... 「私がすでに取得する方法を知っているもの」と同様のタグで囲まれているにもかかわらず、「上記と同様に欲しいもの」を取得するにはどうすればよいですか?
前もって感謝します :)
注: XML ドキュメントは予報のようなものなので、日付と他のタグの内容は常に変化します。