Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to read XML response in specific character code in Java
    primarykey
    data
    text
    <p>I use Wikimedia API Sandbox for Japanese. </p> <p><a href="http://ja.wikipedia.org/wiki/%E7%89%B9%E5%88%A5%3aApiSandbox" rel="nofollow">Japanese Version</a></p> <p><a href="http://en.wikipedia.org/wiki/Special%3aApiSandbox" rel="nofollow">English Version</a></p> <p>I send a HTTP request to Wikimedia and I get a result formed in XML. When I try to send a request and get a result on API Sandbox Webpage, there is no character corruption in a result. </p> <p>But when I get a result in Java, a result includes character corruptions. </p> <p>I cannot assign a specific character code in XML file. </p> <p>How can I assign a result a specific character code? How can I resolve my problem?</p> <pre><code> try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db .parse(new URL( "http://ja.wikipedia.org/w/api.php?action=query&amp;prop=categories&amp;format=xml&amp;cllimit=10&amp;titles=" + key).openStream()); Element root = doc.getDocumentElement(); NodeList queryList = root.getChildNodes(); Node query = queryList.item(0); if (query instanceof Element) { Element queryEle = (Element) query; NodeList pagesList = queryEle.getChildNodes(); Node pgs = pagesList.item(0); if (pgs instanceof Element) { Element pagesElement = (Element) pgs; NodeList pageList = pagesElement.getChildNodes(); Node page = pageList.item(0); if (page instanceof Element) { Element pageElement = (Element) page; String title = pageElement.getAttribute("title"); title = new String(title.getBytes("UTF-8"), "UTF-8"); } } } } catch (ParserConfigurationException e) { } catch (SAXException e) { } catch (IOException e) { } </code></pre> <p>Now I send a <a href="http://ja.wikipedia.org/wiki/%E7%89%B9%E5%88%A5%3aApiSandbox#action=query&amp;prop=categories&amp;format=xml&amp;cllimit=10&amp;titles=%E5%A4%A7%E5%AD%A6" rel="nofollow">request</a>, I got a result whose page title is "大学". But in Java, it shows "??". </p> <p>I use above code for Android Application. </p>
    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.
    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