DOMライブラリを使用してxml形式の文字列を解析しようとしています。何らかの理由で、私のドキュメントにnullが含まれていて、それを解析しようとすると問題が発生します。文字列変数'response'はnullではなく、デバッグモードで文字列を表示できます。
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(response));
Document doc = builder.parse(is);
NodeList nodes = doc.getElementsByTagName("BatchFile");;
for (int i = 0; i < nodes.getLength(); i++) {
Element element = (Element) nodes.item(i);
NodeList batchItem = element.getChildNodes();
String uri = batchItem.item(0).getNodeValue();
String id = batchItem.item(1).getNodeValue();
String fqName = batchItem.item(2).getNodeValue();
}
実行後に行を強調Document doc = builder.parse(is);
表示すると、の結果が表示され[#document: null]
ます。
編集:空のドキュメントを取得できませんでしたが、文字列値はまだnullです(コードの最後)。このようなものの価値をどのように得るのでしょうか
<GetBatchFilesResult>
<BatchFile>
<Uri>uri</Uri>
<ID>id</ID>
<FQName>file.zip</FQName>
</BatchFile>
</GetBatchFilesResult>