以下は、2クラスのプロジェクト用のクラスです。基本的に、wikiページのタイトルを解析し、それを文字列のタイトルに保存したい、またはEclipseのようなものを使用して別のクラスから呼び出すことができるものに保存するとretrieveTitle.setText(WikiSearcherExtension.title);
、ノード情報を保存するためにローカル変数のタイトルがまったく使用されていないことがわかります
xml をコードのブロックとして貼り付けることはできないので、ここに私が使用している URL を示しますhttp://en.wikipedia.org/w/api.php?action=query&prop=revisions&format=xml&rvprop=timestamp&rvlimit=1&rvtoken=rollback&titles =テスト&リダイレクト=
public class WikiParserTrials {
private String wikiInformation;
private String wikiUrl;
String title;
public void urlRefactor(String url) throws IOException {
String wikiPageName = url.replaceAll(" ", "_");
wikiUrl = "http://en.wikipedia.org/w/api.php?action=query&prop=revisions&format=xml&rvprop=timestamp&rvlimit=1&rvtoken=rollback&titles=test&redirects=";
setUrlInformation();
}
private void setUrlInformation() throws IOException {
URL url = new URL(wikiUrl);
URLConnection connection = url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
wikiInformation = "";
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
wikiInformation += line;
}
}
public class ReadAndPrintXMLFile {
public void main(String argv[]) {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(wikiInformation));
Document doc = db.parse(is);
NodeList nodes = doc.getElementsByTagName("normalized");
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
NodeList name = element.getElementsByTagName("to");
Element line = (Element) name.item(0);
String title = (getCharacterDataFromElement(line));
}
}
catch (Throwable t) {
t.printStackTrace();
}
}
}
}