• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

should we pass a reference of Buffer in Parser

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually i have a XMLData in Buffered memory and then i replcaed some of contents from XMLdata,now it became fresh data which i need in StringBuffer.
but now i need to parse it but i m not getting any way to parse it.due to Document doc=db.Parse(Filename)....and my fresh XMLData is in StringBuffer.

can any provide any solution for it. here below is code for reference.
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at this thread
 
Shanu Khan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tony i got my desired result.


public void Get_Cal_Xml(String CTR_XML) {
String today_Date="";
String Tomm_Date="";
String Tomo_Next="";
String Tomo_Next1="";
String Tomo_Next2="";
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
File infile = new File(CTR_XML);
File outfile = new File("D:\\ctrlmfile\\calendar1.xml");

if (infile.exists()) {
BufferedReader br = new BufferedReader(new FileReader(infile));
BufferedWriter bw = new BufferedWriter(new FileWriter(outfile));
String line = null;

while ((line = br.readLine()) != null)
{
if (line.contains("</b><br><br>"))
{
line = line.replace("</b><br><br>", "</b><br></br>");
}
else if(line.contains("</td><font"))
{
line=line.replace("<font face=\"verdana\" color=\"black\" size=\"2\">","");
}
else if(line.contains("</font>"))
{
line=line.replace("</font>"," ");
}
else if (line.contains(" <font")&& line.contains("   "))
{
line = line.replace("   ", " ");
line=line.replace("<font face=\"verdana\" color=\"black\" size=\"2\">","");
line=line.replace("</font></td>","</td>");
}
else if (line.contains("</body></html>")) {
line = line.replace("</body></html>",
"</p></font></body></html>");
}

bw.write(line.toString());
bw.newLine();

}
bw.flush();
//Parsing starts from here//
Document doc = db.parse(outfile);
//Document doc = db.parse("D:\\ctrlmfile\\cal.xml");
Element docElemnt = doc.getDocumentElement();
System.out.println("Root Element --" + doc.getNodeName());

NodeList PO = docElemnt.getElementsByTagName("tr");

if (PO != null && PO.getLength() > 0) {
for (int i = 0; i < PO.getLength(); i++) {
Node N = PO.item(i);

if(N.getNodeType()==Node.ELEMENT_NODE)
{
System.out.println("-------------");
Element e = (Element) N;

NodeList td = e.getElementsByTagName("td");

if (td.item(0).getChildNodes().item(0).getNodeValue() != null)
{
String country = td.item(0).getChildNodes().item(0).getNodeValue();
if(i==0){
today_Date=td.item(1).getChildNodes().item(0).getNodeValue();
Tomm_Date=td.item(2).getChildNodes().item(0).getNodeValue();
Tomo_Next=td.item(3).getChildNodes().item(0).getNodeValue();
Tomo_Next1=td.item(4).getChildNodes().item(0).getNodeValue();
Tomo_Next2=td.item(5).getChildNodes().item(0).getNodeValue();
}
System.out.println("Country :" + country);
//if(line)
{
System.out.println("PO Status :");
}
System.out.println("Today Date :"+ today_Date);
System.out.println("Tomm. Date :"+ Tomm_Date);
System.out.println("Tomm.+1 :"+ Tomo_Next);
System.out.println("Tomm.+2 :" + Tomo_Next1);
System.out.println("Tomm.+3 :" +Tomo_Next2);

} else
{
System.out.println("can't access td element");
}

}
}
} else {
System.out.println(" Parsing loop not working ");
}

}
} catch (Exception e) {
e.printStackTrace();
}

}

 
Shanu Khan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
package com.srk;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class ISISWeekly {

public void ISISInfor()
{
String Path="D:\\a\\ISISWeekly.xml";

String Today="";
String Tomm_Date="";
String Tomo_Next="";
String Tomo_Next1="";
String Tomo_Next2="";

try {

DocumentBuilderFactory DBF=DocumentBuilderFactory.newInstance();
DocumentBuilder DB=DBF.newDocumentBuilder();
File file= new File(Path);
File outfile=new File("D:\\ctrlmfile\\ISISWeekly_Out.xml");

if(file.exists())
{
BufferedReader br = new BufferedReader(new FileReader(file));
BufferedWriter bw = new BufferedWriter(new FileWriter(outfile));
String line=null;

while((line=br.readLine())!=null)
{
if (line.contains("<meta")) {
line = line.replace(">", "/>");
}
if (line.contains("CELLPADDING=0")) {
line = line.replace("CELLPADDING=0","CELLPADDING=\"0\"");
}
if (line.contains("CELLSPACING=0")) {
line = line.replace("CELLSPACING=0","CELLSPACING=\"0\"");
}
if (line.contains("BORDER=0")) {
line = line.replace("BORDER=0", "BORDER=\"0\"");
}
if(line.contains("<img"))
{
line=line.replace("></td>","></img></td>");
}
if(line.contains("</font></td>"))
{
line=line.replace("<font color=\"#FFFFFF\" face=\"Arial Rounded MT Bold\">","");
}
if(line.contains("</font></td>"))
{
line=line.replace("</font></td>","</td>");
}
if(line.contains("<img src=D"))
{
line=line.replace("=D","=\"D");
}
if(line.contains("png>"))
{
line=line.replace("png>","png\">");
}

bw.write(line.toString());
bw.newLine();
}
bw.flush();

Document doc =DB.parse(outfile);
Element docElemnt = doc.getDocumentElement();
System.out.println("Root Element --" + doc.getNodeName());

NodeList PO = docElemnt.getElementsByTagName("tr");
System.out.println("No of ISAP PO : "+(PO.getLength()-6));
if (PO != null && PO.getLength() > 0)
{
for (int i = 5; i < PO.getLength(); i++)
{

Node N = PO.item(i);
if (N.getNodeType() == Node.ELEMENT_NODE)
{
String mydate="";
String Ctr="";
System.out.println("--------------");
Element e = (Element) N;
NodeList td = e.getElementsByTagName("td");
if (td.item(0).getChildNodes().item(0).getNodeValue() != null)
{
String country = td.item(0).getChildNodes().item(0).getNodeValue();
if(!country.toString().equals("UNIT"))
{
System.out.println("Country : " + country);
}

if(i==5)
{
Today=td.item(1).getChildNodes().item(0).getNodeValue();
Tomm_Date = td.item(2).getChildNodes().item(0).getNodeValue();
Tomo_Next = td.item(3).getChildNodes().item(0).getNodeValue();
Tomo_Next1 = td.item(4).getChildNodes().item(0).getNodeValue();
Tomo_Next2 = td.item(5).getChildNodes().item(0).getNodeValue();
}

if(!country.toString().equals("UNIT"))
{
for(int j=1;j<=5;j++)
{
switch(j)
{
case 1:

mydate="Today Date :"+ Today +" Status : ";
break;
case 2:
mydate="Tomm. Date :"+ Tomm_Date +" Status : ";
break;
case 3:
mydate ="Tomm.+1 :"+ Tomo_Next +" Status : ";
break;
case 4:
mydate ="Tomm.+2 :"+ Tomo_Next1 +" Status : ";
break;
case 5:
mydate ="Tomm.+3 :"+ Tomo_Next2 +" Status : ";
break;
}
if(country.toString().equals("UNIT"))
{
if(td.item(j).getChildNodes().item(0).getNodeValue().toString().equals("check.png"))
{
Ctr="OPEN";
}
else if(td.item(j).getChildNodes().item(0).getNodeValue().toString().equals("cross.png"))
{
Ctr="CLOSE";
}
}
else if(td.item(j).getChildNodes().item(0).getAttributes().item(0).toString().contains("check.png"))
{
Ctr="OPEN";
}
else if(td.item(j).getChildNodes().item(0).getAttributes().item(0).toString().contains("cross.png"))
{
Ctr="CLOSE";
}
System.out.println(mydate + Ctr);
}
}


}
else{System.out.println("TD Item can't access" );}

}
else
{
System.out.println("PO can't access");
}
}
}
else{System.out.println("PO is null");}

}

} catch (Exception e)
{
e.printStackTrace();
}

}

public static void main(String[] args) {


ISISWeekly IW=new ISISWeekly();
IW.ISISInfor();

}

}
**************************************************************************************************
 
Shanu Khan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is resolved..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic