Я читаю файл XML
, используя приведенный ниже код, но каждый раз, когда я читаю XML
и печатаю его, открывающий тег XML
всегда отсутствует, что, в свою очередь, приводит к ошибке.
код для чтения xml:
package com.vaannila.action;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.vaannila.FormBean.XmlRetrivalForm;
public class AppletRefeshAction extends Action {
String filepath = "C:/Users/ashutosh_k/idoc/docRuleTool/WebContent/data/Malaria.xml";
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
XmlRetrivalForm xrf = (XmlRetrivalForm)form;
String dieasename =xrf.getDieseasename();
System.out.println("ghhjhhjkh"+dieasename);
/* this part of the code is from jsp */
//FileReader fis = new FileReader(new File(filepath));
FileInputStream fis = new FileInputStream(new File(filepath));
byte bin[] = new byte[(int) new File(filepath).length()];
while(fis.read()>0){
fis.read(bin);
}
System.out.println("I am here after reading the xml part of it ");
response.setContentType("text/xml");
response.setCharacterEncoding("UTF-8");
response.getOutputStream().write(bin);
// response.getWriter().write(bin);
String ashu = new String(bin);
String iam =ashu.trim();
System.out.println("i am in the new action class now ");
System.out.println(iam);
fis.close();
/* this part of the code jsp ends here */
return null;
}
}
Сгенерированный вывод xml:
?xml version="1.0" encoding="UTF-8" standalone="no"?><tree>
<declarations>
<attributeDecl name="name" type="String"/>
</declarations>
<branch>
<branch>
<attribute name="name" value="Excess Stool"/>
<branch>
<branch>
<attribute name="name" value="Do you have this condition for more than a weeks time"/>
<branch>
<attribute name="name" value=""/></branch>
<branch>
<attribute name="name" value=""/></branch>
</branch>
<branch>
<attribute name="name" value="No"/></branch>
<attribute name="name" value="Do you have watery stool"/></branch>
<branch>
<attribute name="name" value="No"/></branch>
</branch>
<branch>
<branch>
<attribute name="name" value="Was your peak temperature greater than 104"/>
<branch>
<branch>
<attribute name="name" value="Do you have chills"/>
</branch>
<branch>
<attribute name="name" value="No"/></branch>
<attribute name="name" value="Do you have high fever for more than a weeks time "/></branch>
<branch>
<attribute name="name" value="No"/></branch>
</branch>
<branch>
<attribute name="name" value="No"/></branch>
<attribute name="name" value="High Fever"/></branch>
<branch>
<branch>
<attribute name="name" value="Do you have pain in the left part of the head "/>
<branch>
<branch>
<attribute name="name" value="Duration of the headache spans for more than a day "/>
</branch>
<branch>
<attribute name="name" value="No"/></branch>
<attribute name="name" value="Do you have headache more than 5 times a day "/></branch>
<branch>
<attribute name="name" value="No"/></branch>
</branch>
<branch>
<attribute name="name" value="No"/></branch>
<attribute name="name" value="Bodyache"/></branch>
<attribute name="name" value="Malaria"/></branch>
</tree>