以下のxmlを処理しています:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE CASE SYSTEM "C:\Users\user123\Desktop\demo.dtd">
<INFO>
<NAME>John Smith</NAME>
<BUSINESSNAME>Smith</BUSINESSNAME>
</INFO>
しかし、私は無視しなければなりません
<!DOCTYPE CASE SYSTEM "C:\Users\user123\Desktop\demo.dtd"> because in presence of this parsing is giving error.
これは私のコードです:
StringBuilder sb = new StringBuilder();
File xmlFile = new File("C:/Users/Desktop/demo.xml");
BufferedReader br = new BufferedReader(new FileReader(xmlFile));
String line = null;
while((line = br.readLine())!= null){
if(line.indexOf("&") != -1)
{
line = line.replaceAll("&","&");
}
sb.append(line);
}
br.close();
BufferedWriter bw = new BufferedWriter(new FileWriter(xmlFile));
Source xmlInput = new StreamSource(new StringReader(sb.toString()));
StringWriter stringWriter = new StringWriter();
StreamResult xmlOutput = new StreamResult(stringWriter);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformerFactory.setAttribute("indent-number", 2);
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(xmlInput, xmlOutput);
bw.write(xmlOutput.getWriter().toString());
bw.close();
System.out.println("success");
助言がありますか?