Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving trouble saving node input to a string
    primarykey
    data
    text
    <p>Below is a class I have for a 2 class project. Basically I want to parse the title of the wiki page, and save it to the string title or something I can call from another class using something like <code>retrieveTitle.setText(WikiSearcherExtension.title);</code> In eclipse its telling me the local variable title isnt being used at all to store the node information.</p> <p>It wouldnt let me paste the xml as a block of code so here is the url I have been using <a href="http://en.wikipedia.org/w/api.php?action=query&amp;prop=revisions&amp;format=xml&amp;rvprop=timestamp&amp;rvlimit=1&amp;rvtoken=rollback&amp;titles=test&amp;redirects=" rel="nofollow">http://en.wikipedia.org/w/api.php?action=query&amp;prop=revisions&amp;format=xml&amp;rvprop=timestamp&amp;rvlimit=1&amp;rvtoken=rollback&amp;titles=test&amp;redirects=</a></p> <pre><code>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&amp;prop=revisions&amp;format=xml&amp;rvprop=timestamp&amp;rvlimit=1&amp;rvtoken=rollback&amp;titles=test&amp;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 &lt; 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(); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload