Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2009
    Posts
    28
    Rep Power
    0

    Default Displaying XML file using jsp declarations?

    I have written code for generating XML file using jsp declarations.XML file is created properly but while displaying this data in browser it has given some problems.
    Java Code:
    <%!
     public String createXmlTree(Document doc,String name,String address,String contact,String email,String billduedate,String totalamountdue) throws Exception {
    ........................
    ........................
     StringWriter sw = new StringWriter();
            StreamResult result = new StreamResult(sw);
            DOMSource source = new DOMSource(doc);
            transformer.transform(source, result);
            String xmlString = sw.toString();
            return xmlString;
    
            /*File file = new File("d:/new.xml");      .......Generating for XML file
    		
            BufferedWriter bw = new BufferedWriter(new FileWriter(file));
            bw.write(xmlString);
            bw.flush();
            bw.close();*/
    
        }%>
    <%
    String name=pageContext.getAttribute("servicenumber").toString(); 
          String address=pageContext.getAttribute("consumername").toString();
          String contact=pageContext.getAttribute("billno").toString();
          String email="ssss";
    	  String billduedate="hai";
    String totalamountdue=pageContext.getAttribute("totbillamount").toString();
    
      try
      {
          System.out.println(name);
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
            Document doc = docBuilder.newDocument();
           String xmlString = createXmlTree(doc,name,address,contact,email,billduedate,totalamountdue);
           out.println(xmlString );
    
        out.println("<b>Xml File Created Successfully</b>");
      }
      catch(Exception e)
      {
        System.out.println(e);
      }
    
      %>
    in xml file it shows in following way.
    <?xml version="1.0" encoding="UTF-8"?><XML>
    <CONNECTIONNO>VN90301000622</CONNECTIONNO>
    <CUSTOMERNAME>MANAGER TIBTAN</CUSTOMERNAME>
    <BILLNO>7800555</BILLNO>
    <BILLDATE>ssss</BILLDATE>
    <BILLDUEDATE>hai</BILLDUEDATE>
    <TOTALAMOUNTDUE>20151.00</TOTALAMOUNTDUE>
    </XML>
    this is required formate.

    but whenever i want to display in browser it shows in following way..
    VN90301000622 MANAGER TIBTAN 7800555 ssss hai 20151.00
    how to display this in above formate..thanks for help
    Last edited by srinivasmallabathula; 09-14-2012 at 10:57 AM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: Displaying XML file using jsp declarations?

    First off, take that createXmlTree method out of there.
    I'd have it called from a servlet myself, storing the result in the request, but either way it should not be there.
    Then test it.
    Because that is where your problem lies.
    What exactly is the value of that returned String (seen in a console, not on a browser).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Reg: Difference between declarations
    By rummy in forum New To Java
    Replies: 2
    Last Post: 01-27-2012, 05:20 PM
  2. In-loop declarations and performance question ...
    By XmisterIS in forum New To Java
    Replies: 1
    Last Post: 09-15-2010, 12:02 PM
  3. When I mix JSTL 1.0 and 1.1 taglib declarations, it causes a ParseException. Why?
    By sangfroid in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-01-2010, 09:27 AM
  4. Valid declarations
    By heat84 in forum New To Java
    Replies: 1
    Last Post: 12-22-2007, 02:29 AM
  5. Help with valid declarations of a float
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 10:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •