回答編集履歴

2

URL のクエリ文字列部分を微修正

2021/10/12 10:49

投稿

jimbe
jimbe

スコア12744

test CHANGED
@@ -110,7 +110,11 @@
110
110
 
111
111
  static Document getDocument(String isbn, DocumentBuilder builder) throws IOException, SAXException {
112
112
 
113
+ String operation = "searchRetrieve";
114
+
115
+ String query = URLEncoder.encode("isbn=\""+isbn+"\"", "UTF-8");
116
+
113
- URL url = new URL("https://iss.ndl.go.jp/api/sru?operation=searchRetrieve&query=isbn%3d%22"+isbn+"%22");
117
+ URL url = new URL("https://iss.ndl.go.jp/api/sru?operation="+operation+"&query="+query);
114
118
 
115
119
  HttpsURLConnection https = (HttpsURLConnection)url.openConnection();
116
120
 

1

cx20 さんのコメントでのご指摘より、コード修正

2021/10/12 10:49

投稿

jimbe
jimbe

スコア12744

test CHANGED
@@ -48,7 +48,7 @@
48
48
 
49
49
  static List<Book> getBookList(String isbn) throws ParserConfigurationException, IOException, SAXException, XPathExpressionException {
50
50
 
51
- DocumentBuilderFactory factory = DocumentBuilderFactory.newDefaultInstance();
51
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
52
52
 
53
53
  //factory.setNamespaceAware(true);
54
54
 
@@ -86,7 +86,7 @@
86
86
 
87
87
  String data = recordDataList.item(i).getTextContent();
88
88
 
89
- Document datadoc = builder.parse(new ByteArrayInputStream(data.getBytes()));
89
+ Document datadoc = builder.parse(new ByteArrayInputStream(data.getBytes("UTF-8")));
90
90
 
91
91
 
92
92