Need Help to read text file

Tuksor

New Member
i am a new in JAVA and i want to read text file and write it in XML here is my input:[*]R.-J. Roe, J. Appl.Phys. 36, 2024 (1965).and the output but is:\[code\] <ref id="1"> <label>1</label> <citation-alternatives> <mixed-citation>R.-J. Roe, J. Appl.Phys. 36, 2024 (1965).</mixed-citation> </citation-alternatives> </ref>\[/code\]put in many cases this input comes in two lines without space between them like this:[*]R.-J. Roe,J. Appl.Phys. 36, 2024 (1965).and the output will be this:\[code\] <ref id="1"> <label>1</label> <citation-alternatives> <mixed-citation>R.-J. Roe, </mixed-citation> </citation-alternatives> </ref> <ref id="1"> <label>1</label> <citation-alternatives> <mixed-citation>J. Appl.Phys. 36, 2024 (1965).</mixed-citation> </citation-alternatives> </ref>\[/code\]Now my question is how can i read this two lines as one stirng to be like the first output?and here is my code:\[code\]try { String strLine; String num=""; String mix=""; DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); // Back element Document doc = docBuilder.newDocument(); Element rootElement = doc.createElement("Back"); doc.appendChild(rootElement); // ref-list element Element reflist = doc.createElement("ref-list"); rootElement.appendChild(reflist); while( (strLine = br.readLine()) != null) { if (strLine.equals("")) { continue; } int dotIndex = strLine.indexOf("."); num = strLine.substring(0,dotIndex); mix = strLine.substring(dotIndex+2,strLine.length()); // ref element Element ref= doc.createElement("ref"); reflist.appendChild(ref); // set attribute of ref element Attr attr = doc.createAttribute("id"); attr.setValue(num); ref.setAttributeNode(attr); // label element Element label = doc.createElement("label"); ref.appendChild(label); label.setTextContent(num); // citation-alternatives element Element citationalternatives = doc.createElement("citation-alternatives"); ref.appendChild(citationalternatives); // mixed-citation element Element mixedcitation = doc.createElement("mixed-citation"); citationalternatives.appendChild(mixedcitation); mixedcitation.setTextContent(mix); }\[/code\]
 
Back
Top