SAX Parser Application


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class ReadXMLFileSAX {
public static StringBuffer sb = new StringBuffer();

public String Category_ID = "3";// Set the category of the product here

// public String Family="Bolts";
// public String Segment="Fasteners";

public int count = 0;

public static void main(String args[]) {

ReadXMLFileSAX rs = new ReadXMLFileSAX();
rs.processSAX();
}

public void processSAX() {
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
DefaultHandler handler = new DefaultHandler() {
String SKU = "";

String BrandID = "";

String AssetID = "";

String SupportingAssetID = "";

String Alias = "";

String CURRENT_CATALOG_PAGE_NO = "";

String CALIFORNIA_PROP_65_REPRODUCTIVE_HARM = "";

String GREEN_MATERIAL_FLAG = "";

String MFR_MODEL_NO = "";

String SHIP_PACK_QTY = "";

String SHORT_DESCRIPTION = "";

String WA_PRICE = "";

String LONG_DESCRIPTION = "";

String TABLE_MFR_MODEL_NO = "";

String M_NPT_Inlet_In = "";

String M_NPT_Outlet_In = "";

String Amps = "";

String Amps_Watts = "";

String Barrel_Dia = "";

String Barrel_Length = "";

String Base = "";

String Bore_Dia_In = "";

String Brand = "";

String Eye_Inside_Dia_In = "";

String Eye_Inside_Dia = "";

String Eye_Outside_Dia_In = "";

String Eye_Outside_Dia = "";

String Fuse_Amps = "";

String Groove = "";

String HP = "";

String HP_Required = "";

String Inlet_In = "";

String Inlet_Outlet_NPTF_In = "";

String Inlet_Outlet_In = "";

String Inside_Length = "";

String Inside_Width = "";

String Lamp_Base = "";

String Material = "";

String Max_Pressure_PSI = "";

String Max_Head_ft = "";

String Outlet_In = "";

String Outside_Dia_In = "";

String Overall_Length = "";

String Shank_Dia = "";

String Thread_Length = "";

String Thread_Length_A = "";

String Thread_Length_B = "";

String Thread_Size = "";

String Voltage = "";

String Voltage_Rating = "";

String Watts = "";

String Length = "";

boolean Alias_F = false;

boolean CURRENT_CATALOG_PAGE_NO_F = false;

boolean CALIFORNIA_PROP_65_REPRODUCTIVE_HARM_F = false;

boolean GREEN_MATERIAL_FLAG_F = false;

boolean MFR_MODEL_NO_F = false;

boolean SHIP_PACK_QTY_F = false;

boolean SHORT_DESCRIPTION_F = false;

boolean WA_PRICE_F = false;

boolean LONG_DESCRIPTION_F = false;

boolean TABLE_MFR_MODEL_NO_F = false;

boolean M_NPT_Inlet_In_F = false;

boolean M_NPT_Outlet_In_F = false;

boolean Amps_F = false;

boolean Amps_Watts_F = false;

boolean Barrel_Dia_F = false;

boolean Barrel_Length_F = false;

boolean Base_F = false;

boolean Bore_Dia_In_F = false;

boolean Brand_F = false;

boolean Eye_Inside_Dia_In_F = false;

boolean Eye_Inside_Dia_F = false;

boolean Eye_Outside_Dia_In_F = false;

boolean Eye_Outside_Dia_F = false;

boolean Fuse_Amps_F = false;

boolean Groove_F = false;

boolean HP_F = false;

boolean HP_Required_F = false;

boolean Inlet_In_F = false;

boolean Inlet_Outlet_NPTF_In_F = false;

boolean Inlet_Outlet_In_F = false;

boolean Inside_Length_F = false;

boolean Inside_Width_F = false;

boolean Lamp_Base_F = false;

boolean Material_F = false;

boolean Max_Pressure_PSI_F = false;

boolean Max_Head_ft_F = false;

boolean Outlet_In_F = false;

boolean Outside_Dia_In_F = false;

boolean Overall_Length_F = false;

boolean Shank_Dia_F = false;

boolean Thread_Length_F = false;

boolean Thread_Length_A_F = false;

boolean Thread_Length_B_F = false;

boolean Thread_Size_F = false;

boolean Voltage_F = false;

boolean Voltage_Rating_F = false;

boolean Watts_F = false;

boolean Length_F = false;

boolean pid = false;

boolean pname = false;

boolean pcrid = false;

boolean pcrt = false;

boolean acrid = false;

boolean dbid = false;

boolean vid = false;

boolean value = false;

public void startElement(String uri, String localName,
String qName, Attributes attributes)
throws SAXException {

if (qName.equalsIgnoreCase("Product")) {
if (dbid == true) {
// System.out.println("Insert MySQL Code here");
System.out.println("SKU" + SKU + "BrandID"
+ BrandID + "AssetID" + AssetID
+ "SupportingAssetID" + SupportingAssetID
+ "CURRENT_CATALOG_PAGE_NO"
+ CURRENT_CATALOG_PAGE_NO
+ "CALIFORNIA_PROP_65_REPRODUCTIVE_HARM"
+ CALIFORNIA_PROP_65_REPRODUCTIVE_HARM
+ "GREEN_MATERIAL_FLAG"
+ GREEN_MATERIAL_FLAG + "MFR_MODEL_NO"
+ MFR_MODEL_NO + "SHIP_PACK_QTY"
+ SHIP_PACK_QTY + "SHORT_DESCRIPTION"
+ SHORT_DESCRIPTION + "WA_PRICE" + WA_PRICE
+ "LONG_DESCRIPTION" + LONG_DESCRIPTION
+ "TABLE_MFR_MODEL_NO" + TABLE_MFR_MODEL_NO
+ "M_NPT_Inlet_In" + M_NPT_Inlet_In
+ "M_NPT_Outlet_In" + M_NPT_Outlet_In
+ "Amps" + Amps + "Amps_Watts" + Amps_Watts
+ "Barrel_Dia" + Barrel_Dia
+ "Barrel_Length" + Barrel_Length + "Base"
+ Base + "Bore_Dia_In" + Bore_Dia_In
+ "Brand" + Brand + "Eye_Inside_Dia_In"
+ Eye_Inside_Dia_In + "Eye_Inside_Dia"
+ Eye_Inside_Dia + "Eye_Outside_Dia_In"
+ Eye_Outside_Dia_In + "Eye_Outside_Dia"
+ Eye_Outside_Dia + "Fuse_Amps" + Fuse_Amps
+ "Groove" + Groove + "HP" + HP
+ "HP_Required" + HP_Required + "Inlet_In"
+ Inlet_In + "Inlet_Outlet_NPTF_In"
+ Inlet_Outlet_NPTF_In + "Inlet_Outlet_In"
+ Inlet_Outlet_In + "Inside_Length"
+ Inside_Length + "Inside_Width"
+ Inside_Width + "Lamp_Base" + Lamp_Base
+ "Material" + Material
+ "Max_Pressure_PSI" + Max_Pressure_PSI
+ "Max_Head_ft" + Max_Head_ft + "Outlet_In"
+ Outlet_In + "Outside_Dia_In"
+ Outside_Dia_In + "Overall_Length"
+ Overall_Length + "Shank_Dia" + Shank_Dia
+ "Thread_Length" + Thread_Length
+ "Thread_Length_A" + Thread_Length_A
+ "Thread_Length_B" + Thread_Length_B
+ "Thread_Size" + Thread_Size + "Voltage"
+ Voltage + "Voltage_Rating"
+ Voltage_Rating + "Watts" + Watts);

Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "grainger";
String driver = "com.mysql.jdbc.Driver";

try {
Class.forName(driver);
con = DriverManager.getConnection(url + db,
"root", "welcome");

try {
Statement st = con.createStatement();
String query = "INSERT INTO products (SKU,AssetID, SupportingAssetID, Brand, Title, Description, Category_ID, Price, Alias, Current_Catalog_Page_No, Ship_Pack_Qty, Green_Material_Flag, California_Reproductivity_Flag, MFR_MODEL_NO, M_NPT_Inlet_In, M_NPT_Outlet_In, Amps, Amps_Watts, Barrel_Dia, Barrel_Length, Base, Bore_Dia_In, Eye_Inside_Dia_In, Eye_Inside_Dia, Eye_Outside_Dia_In, Eye_Outside_Dia, Fuse_Amps, Groove, HP, HP_Required, Inlet_In, Inlet_Outlet_NPTF_In, Inlet_Outlet_In, Inside_Length, Inside_Width, Lamp_Base, Material, Max_Pressure_PSI, Max_Head_ft, Outlet_In, Outside_Dia_In, Overall_Length, Shank_Dia, Thread_Length, Thread_Length_A, Thread_Length_B, Thread_Size, Voltage, Voltage_Rating, Watts, Length)VALUES ('"
+ SKU
+ "','"
+ AssetID
+ "','"
+ SupportingAssetID
+ "','"
+ BrandID
+ "','"
+ SHORT_DESCRIPTION
+ "','"
+ LONG_DESCRIPTION
+ "','"
+ Category_ID
+ "','"
+ WA_PRICE
+ "','"
+ Alias
+ "','"
+ CURRENT_CATALOG_PAGE_NO
+ "','"
+ SHIP_PACK_QTY
+ "','"
+ GREEN_MATERIAL_FLAG
+ "','"
+ CALIFORNIA_PROP_65_REPRODUCTIVE_HARM
+ "','"
+ MFR_MODEL_NO
+ "','"
+ M_NPT_Inlet_In
+ "',"
+ M_NPT_Outlet_In
+ "','"
+ Amps
+ "','"
+ Amps_Watts
+ "','"
+ Barrel_Dia
+ "','"
+ Barrel_Length
+ "','"
+ Base
+ "','"
+ Bore_Dia_In
+ "','"
+ Eye_Inside_Dia_In
+ "','"
+ Eye_Inside_Dia
+ "','"
+ Eye_Outside_Dia_In
+ "','"
+ Eye_Outside_Dia
+ "','"
+ Fuse_Amps
+ "','"
+ Groove
+ "','"
+ HP
+ "','"
+ HP_Required
+ "','"
+ Inlet_In
+ "','"
+ Inlet_Outlet_NPTF_In
+ "','"
+ Inlet_Outlet_In
+ "','"
+ Inside_Length
+ "','"
+ Inside_Width
+ "','"
+ Lamp_Base
+ "','"
+ Material
+ "','"
+ Max_Pressure_PSI
+ "','"
+ Max_Head_ft
+ "','"
+ Outlet_In
+ "','"
+ Outside_Dia_In
+ "','"
+ Overall_Length
+ "','"
+ Shank_Dia
+ "','"
+ Thread_Length
+ "','"
+ Thread_Length_A
+ "','"
+ Thread_Length_B
+ "','"
+ Thread_Size
+ "','"
+ Voltage
+ "','"
+ Voltage_Rating
+ "','"
+ Watts + "','" + Length + "')";

System.out
.println("query======================================"
+ query);
st.executeUpdate(query);
count++;
System.out.println("Rows Inserted: "
+ count);
} catch (SQLException s) {
s.printStackTrace();
System.out
.println("SQL statement is not executed!");
}
} catch (Exception e) {
e.printStackTrace();
}
}
pid = true;
}
if (attributes.getValue("ID") != null) {

System.out.println("\n" + "SKU :"
+ attributes.getValue("ID"));
SKU = attributes.getValue("ID");

}
if (qName.equalsIgnoreCase("Name")) {
pname = true;
}
if (qName.equalsIgnoreCase("ProductCrossReference")) {
pcrid = true;
}
if (attributes.getValue("ProductID") != null
&& attributes.getValue("Type").equals("Brand")) {
System.out.println("ProductID : "
+ attributes.getValue("ProductID") + " Type :"
+ attributes.getValue("Type"));
BrandID = attributes.getValue("ProductID");
}
if (qName.equalsIgnoreCase("AssetCrossReference")) {
acrid = true;
}
if (attributes.getValue("AssetID") != null
&& attributes.getValue("Type").equals(
"Primary Image")) {
AssetID = attributes.getValue("AssetID");
}
if (attributes.getValue("AssetID") != null
&& attributes.getValue("Type").equals(
"Supporting Image")) {
SupportingAssetID = attributes.getValue("AssetID");
}
if (qName.equalsIgnoreCase("Values")) {
vid = true;
}
if (attributes.getValue("AttributeID") != null) {
if (attributes.getValue("AttributeID").equals(
"CURRENT_CATALOG_PAGE_NO")) {
CURRENT_CATALOG_PAGE_NO_F = true;
}
if (attributes.getValue("AttributeID").equals("ALIAS")) {
System.out.println("ALIAS");
Alias_F = true;
}
if (attributes.getValue("AttributeID").equals(
"CALIFORNIA_PROP_65_REPRODUCTIVE_HARM")) {
CALIFORNIA_PROP_65_REPRODUCTIVE_HARM_F = true;
}
if (attributes.getValue("AttributeID").equals(
"GREEN_MATERIAL_FLAG")) {
System.out.println("GREEN_MATERIAL_FLAG");
GREEN_MATERIAL_FLAG_F = true;
}
if (attributes.getValue("AttributeID").equals(
"MFR_MODEL_NO")) {
System.out.println("MFR_MODEL_NO");
MFR_MODEL_NO_F = true;
}
if (attributes.getValue("AttributeID").equals(
"SHIP_PACK_QTY")) {
System.out.println("SHIP_PACK_QTY");
SHIP_PACK_QTY_F = true;
}
if (attributes.getValue("AttributeID").equals(
"SHORT_DESCRIPTION")) {
System.out.println("SHORT_DESCRIPTION");
SHORT_DESCRIPTION_F = true;
}
if (attributes.getValue("AttributeID").equals(
"WA_PRICE")) {
System.out.println("WA_PRICE");
WA_PRICE_F = true;
}
if (attributes.getValue("AttributeID").equals(
"LONG_DESCRIPTION")) {
System.out.println("LONG_DESCRIPTION");
LONG_DESCRIPTION_F = true;
}
if (attributes.getValue("AttributeID").equals(
"TABLE_MFR_MODEL_NO")) {
System.out.println("TABLE_MFR_MODEL_NO");
TABLE_MFR_MODEL_NO_F = true;
}
if (attributes.getValue("AttributeID").equals(
"100013_ATTR")) {
System.out.println("100013_ATTR");
M_NPT_Inlet_In_F = true;
}
if (attributes.getValue("AttributeID").equals(
"100014_ATTR")) {
System.out.println("100014_ATTR");
M_NPT_Outlet_In_F = true;
}
if (attributes.getValue("AttributeID").equals(
"140961_ATTR")) {
System.out.println("140961_ATTR");
Amps_F = true;
}
if (attributes.getValue("AttributeID").equals(
"100221_ATTR")) {
System.out.println("100221_ATTR");
Amps_Watts_F = true;
}
if (attributes.getValue("AttributeID").equals(
"139229_ATTR")) {
System.out.println("139229_ATTR");
Barrel_Dia_F = true;
}
if (attributes.getValue("AttributeID").equals(
"139708_ATTR")) {
System.out.println("139708_ATTR");
Barrel_Length_F = true;
}
if (attributes.getValue("AttributeID").equals(
"110500_ATTR")) {
System.out.println("110500_ATTR");
Base_F = true;
}
if (attributes.getValue("AttributeID").equals(
"100311_ATTR")) {
System.out.println("100311_ATTR");
Bore_Dia_In_F = true;
}
if (attributes.getValue("AttributeID").equals(
"113947_ATTR")) {
System.out.println("113947_ATTR");
Brand_F = true;
}
if (attributes.getValue("AttributeID").equals(
"101254_ATTR")) {
System.out.println("101254_ATTR");
Eye_Inside_Dia_In_F = true;
}
if (attributes.getValue("AttributeID").equals(
"139880_ATTR")) {
System.out.println("139880_ATTR");
Eye_Inside_Dia_F = true;
}
if (attributes.getValue("AttributeID").equals(
"101256_ATTR")) {
System.out.println("101256_ATTR");
Eye_Outside_Dia_In_F = true;
}
if (attributes.getValue("AttributeID").equals(
"139883_ATTR")) {
System.out.println("139883_ATTR");
Eye_Outside_Dia_F = true;
}
if (attributes.getValue("AttributeID").equals(
"101556_ATTR")) {
System.out.println("101556_ATTR");
Fuse_Amps_F = true;
}
if (attributes.getValue("AttributeID").equals(
"127140_ATTR")) {
System.out.println("127140_ATTR");
Groove_F = true;
}
if (attributes.getValue("AttributeID").equals(
"101908_ATTR")) {
System.out.println("101908_ATTR");
HP_F = true;
}
if (attributes.getValue("AttributeID").equals(
"112999_ATTR")) {
System.out.println("112999_ATTR");
HP_Required_F = true;
}
if (attributes.getValue("AttributeID").equals(
"102002_ATTR")) {
System.out.println("102002_ATTR");
Inlet_In_F = true;
}
if (attributes.getValue("AttributeID").equals(
"102015_ATTR")) {
System.out.println("102015_ATTR");
Inlet_Outlet_NPTF_In_F = true;
}
if (attributes.getValue("AttributeID").equals(
"102012_ATTR")) {
System.out.println("102012_ATTR");
Inlet_Outlet_In_F = true;
}
if (attributes.getValue("AttributeID").equals(
"139881_ATTR")) {
System.out.println("139881_ATTR");
Inside_Length_F = true;
}
if (attributes.getValue("AttributeID").equals(
"139182_ATTR")) {
System.out.println("139182_ATTR");
Inside_Width_F = true;
}
if (attributes.getValue("AttributeID").equals(
"113327_ATTR")) {
System.out.println("113327_ATTR");
Lamp_Base_F = true;
}
if (attributes.getValue("AttributeID").equals(
"102227_ATTR")) {
System.out.println("102227_ATTR");
Material_F = true;
}
if (attributes.getValue("AttributeID").equals(
"113714_ATTR")) {
System.out.println("113714_ATTR");
Max_Pressure_PSI_F = true;
}
if (attributes.getValue("AttributeID").equals(
"102340_ATTR")) {
System.out.println("102340_ATTR");
Max_Head_ft_F = true;
}
if (attributes.getValue("AttributeID").equals(
"102969_ATTR")) {
System.out.println("102969_ATTR");
Outlet_In_F = true;
}
if (attributes.getValue("AttributeID").equals(
"102970_ATTR")) {
System.out.println("102970_ATTR");
Outside_Dia_In_F = true;
}
if (attributes.getValue("AttributeID").equals(
"114607_ATTR")) {
System.out.println("103033_ATTR");
Overall_Length_F = true;
}
if (attributes.getValue("AttributeID").equals(
"139842_ATTR")) {
System.out.println("139842_ATTR");
Shank_Dia_F = true;
}
if (attributes.getValue("AttributeID").equals(
"116399_ATTR")) {
System.out.println("116399_ATTR");
Thread_Length_F = true;
}
if (attributes.getValue("AttributeID").equals(
"138821_ATTR")) {
System.out.println("138821_ATTR");
Thread_Length_A_F = true;
}
if (attributes.getValue("AttributeID").equals(
"138822_ATTR")) {
System.out.println("138822_ATTR");
Thread_Length_B_F = true;
}
if (attributes.getValue("AttributeID").equals(
"103754_ATTR")) {
System.out.println("103754_ATTR");
Thread_Size_F = true;
}
if (attributes.getValue("AttributeID").equals(
"116924_ATTR")) {
System.out.println("116924_ATTR");
Voltage_F = true;
}
if (attributes.getValue("AttributeID").equals(
"103953_ATTR")) {
System.out.println("103953_ATTR");
Voltage_Rating_F = true;
}
if (attributes.getValue("AttributeID").equals(
"117016_ATTR")) {
System.out.println("117016_ATTR");
Watts_F = true;
}
if (attributes.getValue("AttributeID").equals(
"102124_ATTR")) {
Length_F = true;
}
}
}

public void endElement(String uri, String localName,
String qName) throws SAXException {

}

public void characters(char ch[], int start, int length)
throws SAXException {
if (pid) {
pid = false;
dbid = true;
}
if (pname) {
pname = false;
}
if (pcrid) {
pcrid = false;
}
if (acrid) {
acrid = false;
}
if (vid) {
vid = false;
}
if (value) {
String data = new String(ch, start, length);
System.out.println("data:" + data);
value = false;
}
if (CURRENT_CATALOG_PAGE_NO_F) {
CURRENT_CATALOG_PAGE_NO = new String(ch, start, length);
CURRENT_CATALOG_PAGE_NO_F = false;
}
if (CALIFORNIA_PROP_65_REPRODUCTIVE_HARM_F) {
CALIFORNIA_PROP_65_REPRODUCTIVE_HARM = new String(ch,
start, length);
CALIFORNIA_PROP_65_REPRODUCTIVE_HARM_F = false;
}
if (GREEN_MATERIAL_FLAG_F) {
GREEN_MATERIAL_FLAG = new String(ch, start, length);
GREEN_MATERIAL_FLAG_F = false;
}
if (MFR_MODEL_NO_F) {
MFR_MODEL_NO = new String(ch, start, length);
MFR_MODEL_NO_F = false;
}
if (SHIP_PACK_QTY_F) {
SHIP_PACK_QTY = new String(ch, start, length);
SHIP_PACK_QTY_F = false;
}
if (SHORT_DESCRIPTION_F) {
SHORT_DESCRIPTION = new String(ch, start, length);
SHORT_DESCRIPTION_F = false;
}
if (WA_PRICE_F) {
WA_PRICE = new String(ch, start, length);
WA_PRICE_F = false;
}
if (LONG_DESCRIPTION_F) {
LONG_DESCRIPTION = new String(ch, start, length);
LONG_DESCRIPTION_F = false;
}
if (TABLE_MFR_MODEL_NO_F) {
TABLE_MFR_MODEL_NO = new String(ch, start, length);
TABLE_MFR_MODEL_NO_F = false;
}
if (Alias_F) {
Alias = new String(ch, start, length);
Alias_F = false;
}
if (M_NPT_Inlet_In_F) {
M_NPT_Inlet_In = new String(ch, start, length);
M_NPT_Inlet_In_F = false;
}
if (M_NPT_Outlet_In_F) {
M_NPT_Outlet_In = new String(ch, start, length);
M_NPT_Outlet_In_F = false;
}
if (Amps_F) {
Amps = new String(ch, start, length);
Amps_F = false;
}
if (Amps_Watts_F) {
Amps_Watts = new String(ch, start, length);
Amps_Watts_F = false;
}
if (Barrel_Dia_F) {
Barrel_Dia = new String(ch, start, length);
Barrel_Dia_F = false;
}
if (Barrel_Length_F) {
Barrel_Length = new String(ch, start, length);
Barrel_Length_F = false;
}
if (Base_F) {
Base = new String(ch, start, length);
Base_F = false;
}
if (Bore_Dia_In_F) {
Bore_Dia_In = new String(ch, start, length);
Bore_Dia_In_F = false;
}
if (Brand_F) {
Brand = new String(ch, start, length);
Brand_F = false;
}
if (Eye_Inside_Dia_In_F) {
Eye_Inside_Dia_In = new String(ch, start, length);
Eye_Inside_Dia_In_F = false;
}
if (Eye_Inside_Dia_F) {
Eye_Inside_Dia = new String(ch, start, length);
Eye_Inside_Dia_F = false;
}
if (Eye_Outside_Dia_In_F) {
Eye_Outside_Dia_In = new String(ch, start, length);
Eye_Outside_Dia_In_F = false;
}
if (Eye_Outside_Dia_F) {
Eye_Outside_Dia = new String(ch, start, length);
Eye_Outside_Dia_F = false;
}
if (Fuse_Amps_F) {
Fuse_Amps = new String(ch, start, length);
Fuse_Amps_F = false;
}
if (Groove_F) {
Groove = new String(ch, start, length);
Groove_F = false;
}
if (HP_F) {
HP = new String(ch, start, length);
HP_F = false;
}
if (HP_Required_F) {
HP_Required = new String(ch, start, length);
HP_Required_F = false;
}
if (Inlet_In_F) {
Inlet_In = new String(ch, start, length);
Inlet_In_F = false;
}
if (Inlet_Outlet_NPTF_In_F) {
Inlet_Outlet_NPTF_In = new String(ch, start, length);
Inlet_Outlet_NPTF_In_F = false;
}
if (Inlet_Outlet_In_F) {
Inlet_Outlet_In = new String(ch, start, length);
Inlet_Outlet_In_F = false;
}
if (Inside_Length_F) {
Inside_Length = new String(ch, start, length);
Inside_Length_F = false;
}
if (Inside_Width_F) {
Inside_Width = new String(ch, start, length);
Inside_Width_F = false;
}
if (Lamp_Base_F) {
Lamp_Base = new String(ch, start, length);
Lamp_Base_F = false;
}
if (Material_F) {
Material = new String(ch, start, length);
Material_F = false;
}
if (Max_Pressure_PSI_F) {
Max_Pressure_PSI = new String(ch, start, length);
Max_Pressure_PSI_F = false;
}
if (Max_Head_ft_F) {
Max_Head_ft = new String(ch, start, length);
Max_Head_ft_F = false;
}
if (Outlet_In_F) {
Outlet_In = new String(ch, start, length);
Outlet_In_F = false;
}
if (Outside_Dia_In_F) {
Outside_Dia_In = new String(ch, start, length);
Outside_Dia_In_F = false;
}
if (Overall_Length_F) {
Overall_Length = new String(ch, start, length);
Overall_Length_F = false;
}
if (Shank_Dia_F) {
Shank_Dia = new String(ch, start, length);
Shank_Dia_F = false;
}
if (Thread_Length_F) {
Thread_Length = new String(ch, start, length);
Thread_Length_F = false;
}
if (Thread_Length_A_F) {
Thread_Length_A = new String(ch, start, length);
Thread_Length_A_F = false;
}
if (Thread_Length_B_F) {
Thread_Length_B = new String(ch, start, length);
Thread_Length_B_F = false;
}
if (Thread_Size_F) {
Thread_Size = new String(ch, start, length);
Thread_Size_F = false;
}
if (Voltage_F) {
Voltage = new String(ch, start, length);
Voltage_F = false;
}
if (Voltage_Rating_F) {
Voltage_Rating = new String(ch, start, length);
Voltage_Rating_F = false;
}
if (Watts_F) {
Watts = new String(ch, start, length);
Watts_F = false;
}
if (Length_F) {
Length = new String(ch, start, length);
Length_F = false;
}
}

public void endDocument() {
System.out.println("SKU" + SKU + "BrandID" + BrandID
+ "AssetID" + AssetID + "SupportingAssetID"
+ SupportingAssetID + "CURRENT_CATALOG_PAGE_NO"
+ CURRENT_CATALOG_PAGE_NO
+ "CALIFORNIA_PROP_65_REPRODUCTIVE_HARM"
+ CALIFORNIA_PROP_65_REPRODUCTIVE_HARM
+ "GREEN_MATERIAL_FLAG" + GREEN_MATERIAL_FLAG
+ "MFR_MODEL_NO" + MFR_MODEL_NO + "SHIP_PACK_QTY"
+ SHIP_PACK_QTY + "SHORT_DESCRIPTION"
+ SHORT_DESCRIPTION + "WA_PRICE" + WA_PRICE
+ "LONG_DESCRIPTION" + LONG_DESCRIPTION
+ "TABLE_MFR_MODEL_NO" + TABLE_MFR_MODEL_NO
+ "M_NPT_Inlet_In" + M_NPT_Inlet_In
+ "M_NPT_Outlet_In" + M_NPT_Outlet_In + "Amps"
+ Amps + "Amps_Watts" + Amps_Watts + "Barrel_Dia"
+ Barrel_Dia + "Barrel_Length" + Barrel_Length
+ "Base" + Base + "Bore_Dia_In" + Bore_Dia_In
+ "Brand" + Brand + "Eye_Inside_Dia_In"
+ Eye_Inside_Dia_In + "Eye_Inside_Dia"
+ Eye_Inside_Dia + "Eye_Outside_Dia_In"
+ Eye_Outside_Dia_In + "Eye_Outside_Dia"
+ Eye_Outside_Dia + "Fuse_Amps" + Fuse_Amps
+ "Groove" + Groove + "HP" + HP + "HP_Required"
+ HP_Required + "Inlet_In" + Inlet_In
+ "Inlet_Outlet_NPTF_In" + Inlet_Outlet_NPTF_In
+ "Inlet_Outlet_In" + Inlet_Outlet_In
+ "Inside_Length" + Inside_Length + "Inside_Width"
+ Inside_Width + "Lamp_Base" + Lamp_Base
+ "Material" + Material + "Max_Pressure_PSI"
+ Max_Pressure_PSI + "Max_Head_ft" + Max_Head_ft
+ "Outlet_In" + Outlet_In + "Outside_Dia_In"
+ Outside_Dia_In + "Overall_Length"
+ Overall_Length + "Shank_Dia" + Shank_Dia
+ "Thread_Length" + Thread_Length
+ "Thread_Length_A" + Thread_Length_A
+ "Thread_Length_B" + Thread_Length_B
+ "Thread_Size" + Thread_Size + "Voltage" + Voltage
+ "Voltage_Rating" + Voltage_Rating + "Watts"
+ Watts);
}

};

saxParser.parse("Product.xml", handler);

} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("The end product will be inserted into DB");
// System.out.println("SKU"+SKU+"BrandID"+BrandID+"AssetID"+
// AssetID+"SupportingAssetID"+
// SupportingAssetID+"CURRENT_CATALOG_PAGE_NO"+
// CURRENT_CATALOG_PAGE_NO+"CALIFORNIA_PROP_65_REPRODUCTIVE_HARM"+
// CALIFORNIA_PROP_65_REPRODUCTIVE_HARM+"GREEN_MATERIAL_FLAG"+
// GREEN_MATERIAL_FLAG+"MFR_MODEL_NO"+ MFR_MODEL_NO+"SHIP_PACK_QTY"+
// SHIP_PACK_QTY+"SHORT_DESCRIPTION"+ SHORT_DESCRIPTION+"WA_PRICE"+
// WA_PRICE+"LONG_DESCRIPTION"+
// LONG_DESCRIPTION+"TABLE_MFR_MODEL_NO"+
// TABLE_MFR_MODEL_NO+"M_NPT_Inlet_In"+
// M_NPT_Inlet_In+"M_NPT_Outlet_In"+ M_NPT_Outlet_In+"Amps"+
// Amps+"Amps_Watts"+ Amps_Watts+"Barrel_Dia"+
// Barrel_Dia+"Barrel_Length"+ Barrel_Length+"Base"+
// Base+"Bore_Dia_In"+ Bore_Dia_In+"Brand"+
// Brand+"Eye_Inside_Dia_In"+ Eye_Inside_Dia_In+"Eye_Inside_Dia"+
// Eye_Inside_Dia+"Eye_Outside_Dia_In"+
// Eye_Outside_Dia_In+"Eye_Outside_Dia"+
// Eye_Outside_Dia+"Fuse_Amps"+ Fuse_Amps+"Groove"+ Groove+"HP"+
// HP+"HP_Required"+ HP_Required+"Inlet_In"+
// Inlet_In+"Inlet_Outlet_NPTF_In"+
// Inlet_Outlet_NPTF_In+"Inlet_Outlet_In"+
// Inlet_Outlet_In+"Inside_Length"+ Inside_Length+"Inside_Width"+
// Inside_Width+"Lamp_Base"+ Lamp_Base+"Material"+
// Material+"Max_Pressure_PSI"+ Max_Pressure_PSI+"Max_Head_ft"+
// Max_Head_ft+"Outlet_In"+ Outlet_In+"Outside_Dia_In"+
// Outside_Dia_In+"Overall_Length"+ Overall_Length+"Shank_Dia"+
// Shank_Dia+"Thread_Length"+ Thread_Length+"Thread_Length_A"+
// Thread_Length_A+"Thread_Length_B"+ Thread_Length_B+"Thread_Size"+
// Thread_Size+"Voltage"+ Voltage+"Voltage_Rating"+
// Voltage_Rating+"Watts"+ Watts);
}
}
}

Advertisements

One thought on “SAX Parser Application

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s