How do I create XML output as string without the ?xml ? tag

I need to create xml from a database query result. I am able to do this but it includes the <?xml ?> header tag. I need to create the xml without the header tag <?xml ?>. Please advise.
Here is my source:
package sql_test;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import javax.xml.transform.dom.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.sql.*;
public class SQLConnector {
     java.sql.Connection conn;
     public SQLConnector()
            conn = null;
             try {
                     Class.forName("com.mysql.jdbc.Driver").newInstance();
                     conn = DriverManager.getConnection("jdbc:mysql://localhost/test", "admin", "admin");
                   } catch(Exception e) {
                     System.err.println("Exception: " + e.getMessage());
     public String getTestData()
          Document doc = null;
          Statement s = null;
          ResultSet rs = null;
          String str = null;
          try {
               DocumentBuilderFactory factory =
              DocumentBuilderFactory.newInstance();
              DocumentBuilder builder = factory.newDocumentBuilder();
              doc = builder.newDocument();
              Element results = doc.createElement("Results");
              doc.appendChild(results);
               s = conn.createStatement();
               s.executeQuery("select * from test_table");
               rs = s.getResultSet ();
              ResultSetMetaData rsmd = rs.getMetaData();
              int colCount = rsmd.getColumnCount();
                while (rs.next()) {
                    Element row = doc.createElement("Row");
                    results.appendChild(row);
                    for (int ii = 1; ii <= colCount; ii++) {
                       String columnName = rsmd.getColumnName(ii);
                       Object value = rs.getObject(ii);
                       Element node = doc.createElement(columnName);
                       node.appendChild(doc.createTextNode(value.toString()));
                       row.appendChild(node);
              str = getDocumentAsXml(doc);
         catch (Exception e) {
             e.printStackTrace();
         finally {
           try {
             if (conn != null) conn.close();
             if (s != null) s.close();
             if (rs != null) rs.close();
           catch (Exception e) {
         return str;
     public static String getDocumentAsXml(Document doc) throws TransformerConfigurationException, TransformerException
          DOMSource domSource = new DOMSource(doc);
          TransformerFactory tf = TransformerFactory.newInstance();
          Transformer transformer = tf.newTransformer();
          transformer.setOutputProperty(OutputKeys.INDENT, "yes");
          java.io.StringWriter sw = new java.io.StringWriter();
          StreamResult sr = new StreamResult(sw);
          transformer.transform(domSource, sr);
          return sw.toString();
}

OutputKeys.OMIT_XML_DECLARATION

Similar Messages

  • How can I create files in unicode format without "byte order mark"?

    Hello together,
    I have to export files in UTF-8 format and have to send them to another partner system which works with linux as operating system.
    I have tried the different possibities to create files with ABAP. But nothing works 100% how I want.
    Some examples:
    1.)
    OPEN DATASET [filename] FOR OUTPUT IN TEXT MODE ENCODING UTF-8.
    If I create a file in this way and download it from application server to local system the result for file format in a unicode text edior like NotePad is "ANSI AS UTF-8". This means I have no BYTE ORDER MARK inside.
    But it is also possible that the file format is only ANSI if the file contains no "special characters", isn't it?
    In my test cases I create 3 files. 2 of them has format "ANSI AS UTF-8", and one only "ANSII".
    After transfer to Linux I get as result 2 times UTF8 and one time ASCII as file format.
    2.)
    OPEN DATASET [filename] FOR OUTPUT IN TEXT MODE ENCODING UTF-8 WITH BYTE ORDER MARK.
    With this syntax the result in local editor looks like ok. I get as format really "UTF-8".
    But I get problems with the system which receives the files.
    All files has the file format UTF-8 on Linux but the interface / script can not read the file with BYTE ORDER MARK.
    This is a very big problem for me.
    Do anybody of you know if it possible to force creation in UTF-8 without a BYTE ORDER MARK?
    This means more or less the first example but all files should have UTF-8 format!
    Thanks in advance
    Christian

    This means it is not possible to create a pure unicode file without the byte order mark?
    You wouldn't happen to know how a file with byte order mark should read on a Linux system?
    Or if this possible or not?
    Regards
    Christian

  • How do you create a new apple id on the iphone

    how do you create a new apple id on the iphone 4?

    Why do you want to do that?

  • HT4623 how can i create an apple ID  account without a credit card???

    how can i create an apple ID account without a credit card?

    Try the More Like This  section on the right
    Also, Please See item 3 Here  >  Community etiquette

  • Hi i do not have a job or bank account. i am a student. how can i create a free apple account. without giving a credit or debit card number.

    how do i create a free apple account without giving a credit card number.because i am still in school.

    These are user-to-user forums, you are not talking to iTunes Support nor Apple.
    The link that rmgman gave has instructions for how to create an account without giving credit card details - if you use them when creating an account then you will be able to download items from the store without having to give card details.

  • It wants to verify my account and won't take the password, how can I create a new one or verify the existing one?

    I cloud wants to verify my account and won't take the password, how can I create a new one or verify the one it won't take?

    If you can't remember the password, reset it at...
    iForgot.com

  • How can I create a form for users wherein the text field will expand to accommodate additional text?

    How can I create a form for users wherein the text field will expand to accommodate additional text?

    You need to use LiveCycle (PC Only) to create a dynamic form like that.
    The best you can do with Acrobat to view all of the text in a field is to set the field to multiline, and set the size to "Auto" (If you don't set the size to 'Auto', you can enter as much text as you wish, but the user will need to use the scrollbar to view all of the text.)

  • HT4191 iPhone Local Storage "My iPhone" - How do you create this folder for use by the Notes app on a iPhone or iPad?  If I want to keep some notes only on my device and not in a cloud environment associated with an e-mail account.

    iPhone Local Storage "My iPhone" - How do you create this folder for use by the Notes app on a iPhone or iPad?  If I want to keep some notes only on my device and not in a cloud environment associated with an e-mail account.  I've seen reference to the  "My iPhone" local storage put no mention on how you create this folder or access this folder within the Notes app.  I realize storing information in a local storage like this provides no syncing between other iDevices but that is exactly what I'm looking for.  I'm running iOS7.0.4 on a iPhone 5S, and a iPad Air.  Any help would be greatly appreciated.

    If you go to Settings > Notes > Default Account you will see "On My iPhone" as the default account and the only choice if you have not enabled syncing Notes in Settings >iCloud or Settings > Mail, Contacts, Calendars. If you have enabled syncing you can still select "On My iPhone" as the default account. When you are in the Notes app you won't see any accounts listed if you have not enabled syncing because they are all in the On My iPhone account and that is the only place possible. It is not a folder that you create.

  • How can I edit my website from another computer? and how can I create a new website next to the one, I have already? Can anyone help, please?

    How can I edit my website from another computer? and how can I create a new website next to the one, I already have? Can anyone help, please?

    Move the domain.sites file from one computer to the other.
    The file is located under User/Library/Application Support/iWeb/domain.sites.  Move this file to the same location on the other computer and double click and iWeb will open it.  Remember, it is your User Library that you want and not your System Library, as you will not find iWeb there.
    Just create a new site on the same domain file and it will appear below the other site.  If you want them side by side then duplicate your domain file and have one site per a domain file and they can then be side by side.

  • I have all my pictures in an external drive, how do i create a library in iphoto without using my internal drive space?

    i have all my pictures in an external drive (around 1tb), how do i create a library in iphoto without using my internal drive space? thanks!

    In iPhoto use the command "File > Switch to Library" and then click "Create New" in the Library Chooser panel.
    Select a folder on your external drive as the destination.
    You can also get to this panel by holding down the alt/options key when you launch iPhoto.

  • How can I create a long employment form without making the form widget drag?

    How can I create a long employment form without making the form widget drag?

    Sorry Sachin, I mean that I created a simple form on the page from the widget and started adding fields to it. The more fields I add the slower the delay becomes in creating a new field. Even when I try to select and drag or move an item, there's a huge delay and sometimes the program feezes,  loose what i've done and have ot restart.
    I'm doing an enployment form that has more than 20 fields, at least, and I need to be able to build the fields in separate categories, like Education, Past Employment, etc... quickly without delay issues.
    I can probably send you a snap shot of what I'm talking about if I cna post it or attach it here..?
    ~Andy

  • HT2506 how do I create a signature for preview without camera? (I have a Mac Mini)

    How do I create a signature in preview without icamera? I hava a Mac Mini.

    You can't, but if you create a signature on another Mac with a built-in camera, or an Apple display with a camera, you can move the signature to the mini.

  • I wish to install adobe Flash player , I do not know my pass word .How do I create a new one or retrieve the original one?

    I wish to install adobe Flash player , I do not know my pass word .How do I create a new one or retrieve the original one?

    Hi Don,
    DON RICE wrote:
    I wish to install adobe Flash player , I do not know my pass word .How do I create a new one or retrieve the original one?
    Which password are you referring to in your statement? You can download flash player using this Link - https://get2.adobe.com/flashplayer/
    Regards,
    Rahul

  • How do I create and use a ringtone without syncing and without jailbreaking?

    How do I create and use a ringtone without syncing and without jailbreaking?

    You create ringtones on your computer and sync them to your iphone.
    You can buy ringtones from the ringtones section (at the bottom of the screen when you open itunes) of the itunes app on your iphone.
    There may be apps that will do this - not sure.

  • HT2731 I wana creat an apple I'd , but they are asking me for my credit card detail. How do i creat an apple I'd without giving any credit card detail

    I wana creat an apple I'd , but they are asking me for my credit card detail. How do i creat an apple I'd without giving any credit card detail

    Read this knowledge base article for help with that.

Maybe you are looking for