function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nitesh AgarwalNitesh Agarwal 

VF Page, Sandbox, XML

Dear All,

 Greetings of the day!

 I have created an apex class and a VF page to display some data in XML format. I have developed it in one sandbox and it was working fine on  it and sample data was getting displayed in XML format through VF page, then realised that was not a true copy of production. so I made a true  copy of production on another sandbox, and then created the same apex class and VF page with same code and same naming conventions.

 For my surprise, the VF page is not displaying anything on this sandbox.

 Can anybody suggest, what could be the reason for this. 

 Below are codes

 VF Page
<apex:page Controller="StreamExample" contentType="text/xml" showHeader="true" sidebar="false" cache="false"> </apex:page>

Apex Class Code

public class StreamExample{
public StreamExample()
{
     XmlStreamWriter writer = new XmlStreamWriter();
    
    writer.writeStartDocument('utf-8', '1.0');        
    writer.writeStartElement(null, 'DEXFileUpload', null);
    writer.writeStartElement(null, 'Clients', null);
    
  
   writer.writeEndElement(); //closing tag for Clients
  writer.writeEndElement();//closing tag for Dex
    writer.close();
     
         
}
}
 

Thanks in Advance


Regards
Nitesh
pconpcon
You aren't actually outputting anything to the page.  You need to take the writer and output the XML and then have that somewhere on the page.

Controller
public class StreamExample{
    public XmlStreamWriter writer {get; set;}

    public StreamExample() {
        this.writer = new XmlStreamWriter();
    
        this.writer.writeStartDocument('utf-8', '1.0');        
        this.writer.writeStartElement(null, 'DEXFileUpload', null);
        this.writer.writeStartElement(null, 'Clients', null);
        this.writer.writeEndElement(); //closing tag for Clients
        this.writer.writeEndElement();//closing tag for Dex
        this.writer.close();  
    }

    public String getXML() {
        return this.writer.getXMLString();
    }
}

Page
<apex:page Controller="StreamExample" contentType="text/xml" showHeader="true" sidebar="false" cache="false">
    {!XML}
</apex:page>

NOTE: When including code, please use the "Add a code sample" button (icon <>) to increase readability and make it easier to reference
Nitesh AgarwalNitesh Agarwal
Hi Pcon,


Thanks for the revert.


Howeverm the code is giving error when previewed VF page

Visualforce ErrorHelp for this Page
System.XmlException: Stream already closed 
Class.StreamExample.getXML: line 16, column 1


Thanks dear
pconpcon
I did not have time to actually test that code.  So you will need to use the following controller
 
public class StreamExample{
    public String XML {get; set;}

    public StreamExample() {
        writer = new XmlStreamWriter();
        writer.writeStartDocument('utf-8', '1.0');        
        writer.writeStartElement(null, 'DEXFileUpload', null);
        writer.writeStartElement(null, 'Clients', null);
        writer.writeEndElement(); //closing tag for Clients
        writer.writeEndElement();//closing tag for Dex
        this.XML = writer.getXMLString();
        writer.close();  
    }
}