Whats wrong with this code


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Whats wrong with this code

Hybrid View

  1. #1
    Viji Guest

    Whats wrong with this code



    Hi there,
    Viji here,Please find out the mistake in the following code and
    if any mistake is there please correct it and then send it back.

    thankx in advance.

    Viji.
    ----------------------------------------------------------------
    import java.util.*;
    import javax.servlet.http.*;
    import javax.servlet.*;
    import java.io.*;
    import java.net.*;
    import com.sun.xml.tree.*;

    public class XMLBuild_test {



    HttpSession session = req.getSession(true);

    XmlDocument doc = new XmlDocument ();

    ////////////////////////////////////////////////
    String fname = "sdfasdf";
    String mi = "asdfasdf";
    String lname = "sadfasdf";
    String add1 = "sadfasd";
    String add2 = "sdfsadf";
    String city1 = "sdsdf";
    String state_id = "sdsdaf";
    String country_id = "sddfsdaf";
    String email1 = "sdfsdf";
    String zip1 = "sdfdsf";
    String cctype = "sdfsdf";
    String cardnumber = "sdfasdf";
    String expirationmonth = "sdf";
    String expirationyear = "asdasdf";
    String ssn_1 = "asdfsd";
    String ssn_2 = "sdsd";
    String ssn_3 = "sdsdf";
    String npa_1 = "sdfsdf";
    String nxx_1 = "sdfsd";
    String line_1 = "sdfsdf";
    /////////////////////STRING DEFINITIONS////////


    ElementNode batch = (ElementNode)doc.createElement("batch");
    doc.appendChild(batch);

    ElementNode feed_id = (ElementNode)doc.createElement("feed_id");
    feed_id.setAttribute ("feed_type", "complete");
    batch.appendChild(feed_id);
    feed_id.appendChild(doc.createTextNode("testtust1"));

    ElementNode source = (ElementNode)doc.createElement("source");
    batch.appendChild(source);
    ElementNode partner = (ElementNode)doc.createElement("partner");
    ElementNode site = (ElementNode)doc.createElement("site");
    ElementNode banner = (ElementNode)doc.createElement("banner");
    source.appendChild(partner);
    partner.appendChild(doc.createTextNode("GetSponsor"));
    source.appendChild(site);
    site.appendChild(doc.createTextNode("Getsponsor.com"));
    source.appendChild(banner);
    banner.appendChild(doc.createTextNode("abcd.gif"));

    ElementNode order = (ElementNode)doc.createElement("order");
    batch.appendChild(order);

    ElementNode order_num = (ElementNode)doc.createElement("order_num");
    order.appendChild(order_num);
    order_num.appendChild(doc.createTextNode("pp00005"));

    ElementNode customer = (ElementNode)doc.createElement("customer");
    order.appendChild(customer);

    ElementNode name = (ElementNode)doc.createElement("name");
    customer.appendChild(name);

    ElementNode first = (ElementNode)doc.createElement("first");
    name.appendChild(first);
    //first.appendChild(doc.createTextNode("Ajay"));
    first.appendChild(doc.createTextNode(fname));

    ElementNode middle = (ElementNode)doc.createElement("middle");
    name.appendChild(middle);
    middle.appendChild(doc.createTextNode(mi));

    ElementNode last = (ElementNode)doc.createElement("last");
    name.appendChild(last);
    //last.appendChild(doc.createTextNode("Kumar"));
    last.appendChild(doc.createTextNode(lname));

    /////////////////////////////////////

    ElementNode address = (ElementNode)doc.createElement("address");
    customer.appendChild(address);

    ElementNode street1 = (ElementNode)doc.createElement("street1");
    address.appendChild(street1);
    //street1.appendChild(doc.createTextNode("Bayshore Road"));
    street1.appendChild(doc.createTextNode(add1));

    ElementNode street2 = (ElementNode)doc.createElement("street2");
    address.appendChild(street2);
    //street2.appendChild(doc.createTextNode("Suite 100"));
    street2.appendChild(doc.createTextNode(add2));

    ElementNode city = (ElementNode)doc.createElement("city");
    address.appendChild(city);
    //city.appendChild(doc.createTextNode("Palo Alto"));
    city.appendChild(doc.createTextNode(city1));

    ElementNode state = (ElementNode)doc.createElement("state");
    address.appendChild(state);
    //state.appendChild(doc.createTextNode("California"));
    state.appendChild(doc.createTextNode(state_id));

    ElementNode zip = (ElementNode)doc.createElement("zip");
    address.appendChild(zip);

    ElementNode code = (ElementNode)doc.createElement("code");
    zip.appendChild(code);
    //code.appendChild(doc.createTextNode("94303"));
    code.appendChild(doc.createTextNode(zip1));

    ElementNode plus4 = (ElementNode)doc.createElement("plus4");
    zip.appendChild(plus4);
    plus4.appendChild(doc.createTextNode("2003"));

    ////////////////////////////////////

    ElementNode phone = (ElementNode)doc.createElement("phone");
    customer.appendChild(phone);

    ElementNode npa = (ElementNode)doc.createElement("npa");
    phone.appendChild(npa);
    npa.appendChild(doc.createTextNode(npa_1));

    ElementNode nxx = (ElementNode)doc.createElement("nxx");
    phone.appendChild(nxx);
    nxx.appendChild(doc.createTextNode(nxx_1));

    ElementNode line = (ElementNode)doc.createElement("line");
    phone.appendChild(line);
    line.appendChild(doc.createTextNode(line_1));

    ElementNode email = (ElementNode)doc.createElement("email");
    customer.appendChild(email);
    //email.appendChild(doc.createTextNode("ajayk@yahoo.com"));
    email.appendChild(doc.createTextNode(email1));

    /////////////////////////////////////////////////////
    ElementNode ssn = (ElementNode)doc.createElement("ssn");
    customer.appendChild(ssn);

    ElementNode ssn1 = (ElementNode)doc.createElement("ssn1");
    ssn.appendChild(ssn1);
    ssn1.appendChild(doc.createTextNode(ssn_1));

    ElementNode ssn2 = (ElementNode)doc.createElement("ssn2");
    ssn.appendChild(ssn2);
    ssn2.appendChild(doc.createTextNode(ssn_2));

    ElementNode ssn3 = (ElementNode)doc.createElement("ssn3");
    ssn.appendChild(ssn3);
    ssn3.appendChild(doc.createTextNode(ssn_3));

    ElementNode order_items = (ElementNode)doc.createElement("order_items");
    order.appendChild(order_items);

    ElementNode sku = (ElementNode)doc.createElement("sku");
    order_items.appendChild(sku);
    sku.setAttribute ("quantity", "1");
    sku.appendChild(doc.createTextNode("oro7_3po"));

    ElementNode order_data = (ElementNode)doc.createElement("order_data");
    order.appendChild(order_data);

    ElementNode ld_carrier = (ElementNode)doc.createElement("ld_carrier");
    order_data.appendChild(ld_carrier);
    ld_carrier.setAttribute ("att", "att");
    ld_carrier.setAttribute ("switch_to_att", "yes");

    ElementNode credit_card = (ElementNode)doc.createElement("credit_card");
    order_data.appendChild(credit_card);
    credit_card.setAttribute ("card_type", "visa");

    ElementNode card_data = (ElementNode)doc.createElement("card_data");
    order_data.appendChild(card_data);

    ElementNode number = (ElementNode)doc.createElement("number");
    card_data.appendChild(number);
    number.appendChild(doc.createTextNode("1234567890"));

    ElementNode expiration = (ElementNode)doc.createElement("expiration");
    card_data.appendChild(expiration);

    ElementNode month = (ElementNode)doc.createElement("month");
    expiration.appendChild(month);
    month.appendChild(doc.createTextNode("01"));

    ElementNode year = (ElementNode)doc.createElement("month");
    expiration.appendChild(year);
    year.appendChild(doc.createTextNode("2001"));

    ////////////////////////////////////////////////////////
    ElementNode billing_data = (ElementNode)doc.createElement("billing_data");
    order_data.appendChild(billing_data);

    ElementNode bill_name = (ElementNode)doc.createElement("bill_name");
    billing_data.appendChild(bill_name);

    ElementNode bill_fname = (ElementNode)doc.createElement("bill_fname");
    bill_name.appendChild(bill_fname);
    //bill_fname.appendChild(doc.createTextNode("JOHN"));
    bill_fname.appendChild(doc.createTextNode(fname));

    ElementNode bill_mi = (ElementNode)doc.createElement("bill_mi");
    bill_name.appendChild(bill_mi);
    bill_mi.appendChild(doc.createTextNode(mi));

    ElementNode bill_lname = (ElementNode)doc.createElement("bill_lname");
    bill_name.appendChild(bill_lname);
    //bill_lname.appendChild(doc.createTextNode("K"));
    bill_lname.appendChild(doc.createTextNode(lname));

    ElementNode bill_address = (ElementNode)doc.createElement("bill_address");
    billing_data.appendChild(bill_address);

    ElementNode bill_street1 = (ElementNode)doc.createElement("bill_street1");
    bill_address.appendChild(bill_street1);
    //bill_street1.appendChild(doc.createTextNode("Bayshore Road"));
    bill_street1.appendChild(doc.createTextNode(add1));

    ElementNode bill_street2 = (ElementNode)doc.createElement("bill_street2");
    bill_address.appendChild(bill_street2);
    //bill_street2.appendChild(doc.createTextNode("Suite 100"));
    bill_street2.appendChild(doc.createTextNode(add2));


    ElementNode bill_city = (ElementNode)doc.createElement("bill_city");
    bill_address.appendChild(bill_city);
    //bill_city.appendChild(doc.createTextNode("Palo Alto"));
    bill_city.appendChild(doc.createTextNode(city1));


    ElementNode bill_state = (ElementNode)doc.createElement("bill_state");
    bill_address.appendChild(bill_state);
    //bill_state.appendChild(doc.createTextNode("CA"));
    bill_state.appendChild(doc.createTextNode(state_id));

    ElementNode bill_zip = (ElementNode)doc.createElement("bill_zip");
    bill_address.appendChild(bill_zip);


    ElementNode bill_code = (ElementNode)doc.createElement("bill_code");
    bill_zip.appendChild(bill_code);
    //bill_code.appendChild(doc.createTextNode("07738"));
    bill_code.appendChild(doc.createTextNode(zip1));

    ElementNode bill_plus4 = (ElementNode)doc.createElement("bill_plus4");
    bill_zip.appendChild(bill_plus4);
    bill_plus4.appendChild(doc.createTextNode("2003"));


    session.putValue("XmlObject",doc);


    out.close();




    }


  2. #2
    Anon Guest

    Re: Whats wrong with this code


    It would be helpful if you could explain
    1) exactly what you are trying to do
    2) what the error is
    3) where the error is
    4) what the output should be

    People then may be able to help you with out having to run the code.

    "Viji" <viji_kashyap@hotmail.com> wrote:
    >
    >
    >Hi there,
    > Viji here,Please find out the mistake in the following code and
    >if any mistake is there please correct it and then send it back.
    >
    >thankx in advance.
    >
    >Viji.
    >----------------------------------------------------------------
    >import java.util.*;
    >import javax.servlet.http.*;
    >import javax.servlet.*;
    >import java.io.*;
    >import java.net.*;
    >import com.sun.xml.tree.*;
    >
    >public class XMLBuild_test {
    >
    >
    >
    > HttpSession session = req.getSession(true);
    >
    > XmlDocument doc = new XmlDocument ();
    >
    > ////////////////////////////////////////////////
    > String fname = "sdfasdf";
    > String mi = "asdfasdf";
    > String lname = "sadfasdf";
    > String add1 = "sadfasd";
    > String add2 = "sdfsadf";
    > String city1 = "sdsdf";
    > String state_id = "sdsdaf";
    > String country_id = "sddfsdaf";
    > String email1 = "sdfsdf";
    > String zip1 = "sdfdsf";
    > String cctype = "sdfsdf";
    > String cardnumber = "sdfasdf";
    > String expirationmonth = "sdf";
    > String expirationyear = "asdasdf";
    > String ssn_1 = "asdfsd";
    > String ssn_2 = "sdsd";
    > String ssn_3 = "sdsdf";
    > String npa_1 = "sdfsdf";
    > String nxx_1 = "sdfsd";
    > String line_1 = "sdfsdf";
    > /////////////////////STRING DEFINITIONS////////
    >
    >
    > ElementNode batch = (ElementNode)doc.createElement("batch");
    > doc.appendChild(batch);
    >
    > ElementNode feed_id = (ElementNode)doc.createElement("feed_id");
    > feed_id.setAttribute ("feed_type", "complete");
    > batch.appendChild(feed_id);
    > feed_id.appendChild(doc.createTextNode("testtust1"));
    >
    > ElementNode source = (ElementNode)doc.createElement("source");
    > batch.appendChild(source);
    > ElementNode partner = (ElementNode)doc.createElement("partner");
    > ElementNode site = (ElementNode)doc.createElement("site");
    > ElementNode banner = (ElementNode)doc.createElement("banner");
    > source.appendChild(partner);
    > partner.appendChild(doc.createTextNode("GetSponsor"));
    > source.appendChild(site);
    > site.appendChild(doc.createTextNode("Getsponsor.com"));
    > source.appendChild(banner);
    > banner.appendChild(doc.createTextNode("abcd.gif"));
    >
    > ElementNode order = (ElementNode)doc.createElement("order");
    > batch.appendChild(order);
    >
    > ElementNode order_num = (ElementNode)doc.createElement("order_num");
    > order.appendChild(order_num);
    > order_num.appendChild(doc.createTextNode("pp00005"));
    >
    > ElementNode customer = (ElementNode)doc.createElement("customer");
    > order.appendChild(customer);
    >
    > ElementNode name = (ElementNode)doc.createElement("name");
    > customer.appendChild(name);
    >
    > ElementNode first = (ElementNode)doc.createElement("first");
    > name.appendChild(first);
    > //first.appendChild(doc.createTextNode("Ajay"));
    > first.appendChild(doc.createTextNode(fname));
    >
    > ElementNode middle = (ElementNode)doc.createElement("middle");
    > name.appendChild(middle);
    > middle.appendChild(doc.createTextNode(mi));
    >
    > ElementNode last = (ElementNode)doc.createElement("last");
    > name.appendChild(last);
    > //last.appendChild(doc.createTextNode("Kumar"));
    > last.appendChild(doc.createTextNode(lname));
    >
    > /////////////////////////////////////
    >
    > ElementNode address = (ElementNode)doc.createElement("address");
    > customer.appendChild(address);
    >
    > ElementNode street1 = (ElementNode)doc.createElement("street1");
    > address.appendChild(street1);
    > //street1.appendChild(doc.createTextNode("Bayshore Road"));
    > street1.appendChild(doc.createTextNode(add1));
    >
    > ElementNode street2 = (ElementNode)doc.createElement("street2");
    > address.appendChild(street2);
    > //street2.appendChild(doc.createTextNode("Suite 100"));
    > street2.appendChild(doc.createTextNode(add2));
    >
    > ElementNode city = (ElementNode)doc.createElement("city");
    > address.appendChild(city);
    > //city.appendChild(doc.createTextNode("Palo Alto"));
    > city.appendChild(doc.createTextNode(city1));
    >
    > ElementNode state = (ElementNode)doc.createElement("state");
    > address.appendChild(state);
    > //state.appendChild(doc.createTextNode("California"));
    > state.appendChild(doc.createTextNode(state_id));
    >
    > ElementNode zip = (ElementNode)doc.createElement("zip");
    > address.appendChild(zip);
    >
    > ElementNode code = (ElementNode)doc.createElement("code");
    > zip.appendChild(code);
    > //code.appendChild(doc.createTextNode("94303"));
    > code.appendChild(doc.createTextNode(zip1));
    >
    > ElementNode plus4 = (ElementNode)doc.createElement("plus4");
    > zip.appendChild(plus4);
    > plus4.appendChild(doc.createTextNode("2003"));
    >
    > ////////////////////////////////////
    >
    > ElementNode phone = (ElementNode)doc.createElement("phone");
    > customer.appendChild(phone);
    >
    > ElementNode npa = (ElementNode)doc.createElement("npa");
    > phone.appendChild(npa);
    > npa.appendChild(doc.createTextNode(npa_1));
    >
    > ElementNode nxx = (ElementNode)doc.createElement("nxx");
    > phone.appendChild(nxx);
    > nxx.appendChild(doc.createTextNode(nxx_1));
    >
    > ElementNode line = (ElementNode)doc.createElement("line");
    > phone.appendChild(line);
    > line.appendChild(doc.createTextNode(line_1));
    >
    > ElementNode email = (ElementNode)doc.createElement("email");
    > customer.appendChild(email);
    > //email.appendChild(doc.createTextNode("ajayk@yahoo.com"));
    > email.appendChild(doc.createTextNode(email1));
    >
    > /////////////////////////////////////////////////////
    > ElementNode ssn = (ElementNode)doc.createElement("ssn");
    > customer.appendChild(ssn);
    >
    > ElementNode ssn1 = (ElementNode)doc.createElement("ssn1");
    > ssn.appendChild(ssn1);
    > ssn1.appendChild(doc.createTextNode(ssn_1));
    >
    > ElementNode ssn2 = (ElementNode)doc.createElement("ssn2");
    > ssn.appendChild(ssn2);
    > ssn2.appendChild(doc.createTextNode(ssn_2));
    >
    > ElementNode ssn3 = (ElementNode)doc.createElement("ssn3");
    > ssn.appendChild(ssn3);
    > ssn3.appendChild(doc.createTextNode(ssn_3));
    >
    > ElementNode order_items = (ElementNode)doc.createElement("order_items");
    > order.appendChild(order_items);
    >
    > ElementNode sku = (ElementNode)doc.createElement("sku");
    > order_items.appendChild(sku);
    > sku.setAttribute ("quantity", "1");
    > sku.appendChild(doc.createTextNode("oro7_3po"));
    >
    > ElementNode order_data = (ElementNode)doc.createElement("order_data");
    > order.appendChild(order_data);
    >
    > ElementNode ld_carrier = (ElementNode)doc.createElement("ld_carrier");
    > order_data.appendChild(ld_carrier);
    > ld_carrier.setAttribute ("att", "att");
    > ld_carrier.setAttribute ("switch_to_att", "yes");
    >
    > ElementNode credit_card = (ElementNode)doc.createElement("credit_card");
    > order_data.appendChild(credit_card);
    > credit_card.setAttribute ("card_type", "visa");
    >
    > ElementNode card_data = (ElementNode)doc.createElement("card_data");
    > order_data.appendChild(card_data);
    >
    > ElementNode number = (ElementNode)doc.createElement("number");
    > card_data.appendChild(number);
    > number.appendChild(doc.createTextNode("1234567890"));
    >
    > ElementNode expiration = (ElementNode)doc.createElement("expiration");
    > card_data.appendChild(expiration);
    >
    > ElementNode month = (ElementNode)doc.createElement("month");
    > expiration.appendChild(month);
    > month.appendChild(doc.createTextNode("01"));
    >
    > ElementNode year = (ElementNode)doc.createElement("month");
    > expiration.appendChild(year);
    > year.appendChild(doc.createTextNode("2001"));
    >
    > ////////////////////////////////////////////////////////
    > ElementNode billing_data = (ElementNode)doc.createElement("billing_data");
    > order_data.appendChild(billing_data);
    >
    > ElementNode bill_name = (ElementNode)doc.createElement("bill_name");
    > billing_data.appendChild(bill_name);
    >
    > ElementNode bill_fname = (ElementNode)doc.createElement("bill_fname");
    > bill_name.appendChild(bill_fname);
    > //bill_fname.appendChild(doc.createTextNode("JOHN"));
    > bill_fname.appendChild(doc.createTextNode(fname));
    >
    > ElementNode bill_mi = (ElementNode)doc.createElement("bill_mi");
    > bill_name.appendChild(bill_mi);
    > bill_mi.appendChild(doc.createTextNode(mi));
    >
    > ElementNode bill_lname = (ElementNode)doc.createElement("bill_lname");
    > bill_name.appendChild(bill_lname);
    > //bill_lname.appendChild(doc.createTextNode("K"));
    > bill_lname.appendChild(doc.createTextNode(lname));
    >
    > ElementNode bill_address = (ElementNode)doc.createElement("bill_address");
    > billing_data.appendChild(bill_address);
    >
    > ElementNode bill_street1 = (ElementNode)doc.createElement("bill_street1");
    > bill_address.appendChild(bill_street1);
    > //bill_street1.appendChild(doc.createTextNode("Bayshore Road"));
    > bill_street1.appendChild(doc.createTextNode(add1));
    >
    > ElementNode bill_street2 = (ElementNode)doc.createElement("bill_street2");
    > bill_address.appendChild(bill_street2);
    > //bill_street2.appendChild(doc.createTextNode("Suite 100"));
    > bill_street2.appendChild(doc.createTextNode(add2));
    >
    >
    > ElementNode bill_city = (ElementNode)doc.createElement("bill_city");
    > bill_address.appendChild(bill_city);
    > //bill_city.appendChild(doc.createTextNode("Palo Alto"));
    > bill_city.appendChild(doc.createTextNode(city1));
    >
    >
    > ElementNode bill_state = (ElementNode)doc.createElement("bill_state");
    > bill_address.appendChild(bill_state);
    > //bill_state.appendChild(doc.createTextNode("CA"));
    > bill_state.appendChild(doc.createTextNode(state_id));
    >
    > ElementNode bill_zip = (ElementNode)doc.createElement("bill_zip");
    > bill_address.appendChild(bill_zip);
    >
    >
    > ElementNode bill_code = (ElementNode)doc.createElement("bill_code");
    > bill_zip.appendChild(bill_code);
    > //bill_code.appendChild(doc.createTextNode("07738"));
    > bill_code.appendChild(doc.createTextNode(zip1));
    >
    > ElementNode bill_plus4 = (ElementNode)doc.createElement("bill_plus4");
    > bill_zip.appendChild(bill_plus4);
    > bill_plus4.appendChild(doc.createTextNode("2003"));
    >
    >
    > session.putValue("XmlObject",doc);
    >
    >
    > out.close();
    >
    >
    >
    >
    >}
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center