JAXB duplicates database records in the output XML file

I am trying to export a database through XML file using JAXB. But i get an XML file having my records with the @XMLElement name i gave it (SMS_Database) and also another one following it with <list/> as the RootElement name. I don't know where it's coming from. Here is the code:
import java.io.*;
import java.sql.*;
import java.util.ArrayList;
import javax.xml.bind.*;
public class Parse2Xml {
  static final String XMLBASE = "./SMS_Database.xml";
  static ArrayList<Intermed> dataList = new ArrayList<Intermed>();
  static Connection con = null;
  static PreparedStatement ps = null;
  static ResultSet rs = null;
  public static void main(String[] args) throws JAXBException, IOException {
        con = getConnection();
        try{
          ps = con.prepareStatement("SELECT * FROM SMS_Log");
          rs = ps.executeQuery();
          while (rs.next()) {
              dataList.add(getData(rs));
          rs.close();
          ps.close();
          con.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
        DataStore SMS_Database = new DataStore();
        SMS_Database.setList(dataList);
        JAXBContext context = JAXBContext.newInstance(DataStore.class);
     Marshaller m = context.createMarshaller();
     m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
     Writer w = null;
     try {
          w = new FileWriter(XMLBASE);
          m.marshal(SMS_Database, w);
     } finally {
          try {
               w.close();
          } catch (Exception e) {
    static Connection getConnection(){
        String sqlURL = "jdbc:mysql://localhost:3306/SMSDB";
        String username = "SUNNYBEN";
        String password = "drowssap";
        try {
            try {
                Class.forName("com.mysql.jdbc.Driver").newInstance();
            } catch (InstantiationException ex) {
                ex.printStackTrace();
            } catch (IllegalAccessException ex) {
                ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        try {
            con = DriverManager.getConnection(sqlURL, username, password);
        } catch (SQLException ex) {
           ex.printStackTrace();
        return con;
    static Intermed getData(ResultSet rs) throws SQLException {
            Intermed mediator = new Intermed();
            mediator.setSms_id(rs.getString("sms_id"));
            mediator.setSender_id(rs.getString("sender_id"));
            mediator.setMessage(rs.getString("message"));
            mediator.setPhone_no(rs.getString("phone_no"));
            mediator.setDate_sent(rs.getString("date_sent"));
            mediator.setSchedule_date(rs.getString("schedule_date"));
            mediator.setUsername(rs.getString("username"));
            mediator.setResponse(rs.getString("response"));
            return mediator;
import java.util.ArrayList;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(namespace = "SMS_Database")
class DataStore {
    @XmlElement(name = "SMS_Log")
    ArrayList<Intermed> dataList = new ArrayList<Intermed>();
    public ArrayList<Intermed> getList() {
        return dataList;
    public void setList(ArrayList<Intermed> dataList) {
        this.dataList = dataList;
import javax.xml.bind.annotation.*;
@XmlRootElement(name = "SMS_Log")
@XmlType(propOrder = {"sms_id", "sender_id", "message", "phone_no", "date_sent", "schedule_date", "username", "response"})
public class Intermed {
    private String sms_id;
    private String sender_id;
    private String message;
    private String phone_no;
    private String date_sent;
    private String schedule_date;
    private String username;
    private String response;
    public String getSms_id() {
        return sms_id;
    public void setSms_id(String sms_id) {
        this.sms_id = sms_id;
    public String getSender_id() {
        return sender_id;
    public void setSender_id(String sender_id) {
        this.sender_id = sender_id;
    public String getMessage() {
        return message;
    public void setMessage(String message) {
        this.message = message;
    public String getPhone_no() {
        return phone_no;
    public void setPhone_no(String phone_no) {
        this.phone_no = phone_no;
    public String getDate_sent() {
        return date_sent;
    public void setDate_sent(String date_sent) {
        this.date_sent = date_sent;
    public String getSchedule_date() {
        return schedule_date;
    public void setSchedule_date(String schedule_date) {
        this.schedule_date = schedule_date;
    public String getUsername() {
        return username;
    public void setUsername(String username) {
        this.username = username;
    public String getResponse() {
        return response;
    public void setResponse(String response) {
        this.response = response;
}

Dear All
my requirement is to generate an xml file which looks similar to
<?xml version="1.0" encoding="UTF-8"?>
<?TestLine?>
<test_mt>
<field1>123</field1>
<field2>234</field2>
</test_mt>
how to add <?TestLine?>  tag?
Hi shabrasish and rajashekar
i am new to java and xslt mapping can you guide me  or give me links which are similar to my requirement how to proceed with this kind of mapping
thanks
uday

Similar Messages

  • Convert the Database records to a standard XML file format?

    Hai,
    i want to convert the Database records to a standard XML file
    format which includes the schema name, table name, field name
    and field value. i am using Oracle 8.1.7. Is there any option
    please help me
    Thanks in advance.

    You could put the files somewhere and I can export them as QuickTime. Or you could find anyone you know who has Director. Or do the 30 day trial download
    Another approach would be to play the DCR in a browser window, and do a screen recording. But that’s unlikely to give the perfect frame rate that you would get by exporting from Director.

  • Junk Characters in the output XML file after Parsing

    Hi
    I am using DOM parser to parse an XML file.
    After parsing the input XML file, i am fetching some contents
    from the same and also putting the same contents in the parsed output file which is also an XML file.
    The problem here is that the after putting the contents to the output XML file from the input XML file,
    some junk character appears at the end of each and every tag in the outputfile.
    The junk character is some thing like this : " ampersand hash thirteen and a semicolon "
    (*THE MESSAGE DID NOT ACCEPT THE SYMBOLS KINDLY TRANSLATE THE ABOVE WORDINGS*
    INTO SYMBOLS)
    This character gets appended at the end of each and every tag in the output file due to which the output file
    is not recognised as an XML file.
    Please let me know as to why is this character appearing and also please suggest some solution
    for the same.
    -Thanks in Advance.
    Edited by: itskarthik on Oct 10, 2008 7:16 AM
    Edited by: itskarthik on Oct 10, 2008 7:18 AM
    Edited by: itskarthik on Oct 10, 2008 7:19 AM
    Edited by: itskarthik on Oct 10, 2008 7:19 AM
    Edited by: itskarthik on Oct 10, 2008 7:23 AM
    Edited by: itskarthik on Oct 10, 2008 7:23 AM

    Wierd.
    Try this piece of code. (You can always change it to use input file and output file instead of string if you want)
    What is your output?
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.Result;
    import javax.xml.transform.Source;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import org.w3c.dom.Document;
    public class XMLTest {
         public static void main(String[] args) throws Exception {
              String input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" +
                                  "<test>\r\n" +
                                  "</test>";
              System.out.println("Input:");
              lookForCR(input);
              DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
              Document doc = factory.newDocumentBuilder().parse( new ByteArrayInputStream(input.getBytes()) );
              Source source = new DOMSource(doc);
              ByteArrayOutputStream bArrOut = new ByteArrayOutputStream();
              Result result = new StreamResult( new StripOutputStream( bArrOut ) );
              Transformer xformer = TransformerFactory.newInstance().newTransformer();
              xformer.transform(source, result);     
              System.out.println("\nResult:");
              lookForCR(bArrOut.toString());
              System.out.println("\nDone");
         public static void lookForCR(String input) throws Exception {
              char[] chars =input.toCharArray();
              for ( char chr : chars ) {
                   if (chr == 13 ) {
                        System.out.println("Has 0x0D character!!");
    class StripOutputStream extends OutputStream {
         OutputStream out = null;
         public StripOutputStream(OutputStream out) {
              this.out = out;
         @Override
         public void write(int b) throws IOException {
              if ( b != 13 )
                   out.write(b);
    }- Roy

  • Not receiving the output xml file from BPM

    Hello
    I am doing a scenario where I'd be sending two files in text format to the BPM workflow which would be using Fork and Correlation to merge these two files into one file and send the output xml file as receiver. Problem is that the two files are successfully converted into the xml messages and are displayed in SXMB_MONI but the output file which would be received from BPM engine as receiver is not being generated and displayed in SXMB_MONI as well as RWB. Please suggest any probable solution.
    Thanks.

    I don't think you can manipulate .ai files in Flex /
    AIR.

  • Fixing duplicate database entries for the same audio file

    My iTunes Media folder is stored on a network accessible storage server. Since upgrading to 11.1.x, my computer seems to be duplicating database entries for the same audio files - for some albums, I have 4 entries for every song, each one pointing to the exact same file. The only difference between entries is rating info and play counts, which are specific to a particular entry (I think). Has anyone else seen this behavior? Is there an obvious way to stop this from happening? I can delete and rebuild the database from media files, but that starts getting old if I have to do it every week or so. Is there a script to delete duplicate database entries? (I found a VB script on the iTunes for Windows community, but the offending machine is a Mac).
    Thank you for any assistance!
    K

      Select the photo stack under the People tab and click the rename icon (bottom left)

  • Add an extra line in the output xml file

    Dear All
    My scenarios is idoc to xml file.For the resultant xml file i have to append a line  <?Test Line?> after
    <?xml version="1.0" encoding="UTF-8" ?>  while passing it to  legacy system ?
    How generate such a xml file in xi?
    Any help would be appreciated
    Thanks and regards
    uday

    Dear All
    my requirement is to generate an xml file which looks similar to
    <?xml version="1.0" encoding="UTF-8"?>
    <?TestLine?>
    <test_mt>
    <field1>123</field1>
    <field2>234</field2>
    </test_mt>
    how to add <?TestLine?>  tag?
    Hi shabrasish and rajashekar
    i am new to java and xslt mapping can you guide me  or give me links which are similar to my requirement how to proceed with this kind of mapping
    thanks
    uday

  • Validating against schema file for the output XML file

    Hi,
      I am using XSLT for mapping. The output message is generated according to the mappings but it is not validate aganist schema of target . I am using xsd file from external defination section as target. Can any body help me in this regard.
    Thanks,
    Mallikarjun.M

    hi,
    if you talk about the schema of a target message type
    than validation only works if you use graphical
    message mapping
    not with: xslt,java, abap
    Regards,
    michal
    <a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions">XI FAQ - Frequently Asked Questions</a>

  • Choose encoding of the output XML FILE

    I use XSU to generate an XML file in PL/SQL using the getXML method but I don't know how to choose the encoding.
    Can somebody help me ?

    I use XSU to generate an XML file in PL/SQL using the getXML method but I don't know how to choose the encoding. Can somebody help me ? Using XSU you can set the Encoding Tag by:
    PROCEDURE setEncodingTag(ctxHdl IN ctxType, enc IN VARCHAR2 := DB_ENCODING);
    Do you have use case that you want to do the character set conversion?

  • How to remove namespace link from the output XML

    i have to remove 'xmlns:xdoxslt="http://www.oracle.com/XSL/Transform/java/oracle.apps.xdo.template.rtf.XSLTFunctions"' (namespace) from the output xml file which is generated from the BIP. I need my output XML file without that namespace link, this namespace link is coming for each element.
    Anybody know how to do that please help.
    output xml file
    <?xml version="1.0" encoding="UTF-8" ?>
    <Reports version="2.00">
    <deliveryNote xmlns:xdoxslt="http://www.oracle.com/XSL/Transform/java/oracle.apps.xdo.template.rtf.XSLTFunctions">
    <subjectId />
    </deliveryNote>
    <deliveredReports xmlns:xdoxslt="http://www.oracle.com/XSL/Transform/java/oracle.apps.xdo.template.rtf.XSLTFunctions">
    <referDate>[Delivery note->H4]</referDate>
    </deliveredReports>
    <simpleReports xmlns:xdoxslt="http://www.oracle.com/XSL/Transform/java/oracle.apps.xdo.template.rtf.XSLTFunctions">
    <numberOfReports>2</numberOfReports>
    <nReport>
    <reportName>Xyz</reportName>
    <reportVersion>1.0</reportVersion>
    <observations>
    <numberOfObservations>15</numberOfObservations>
    <columnObservation>
    <y>9</y>
    <rO>
    <x>14</x>
    <o>11</o>
    <o>21</o>
    <o>121</o>
    </rO>
    </columnObservation>
    </observations>
    </nReport>
    </simpleReports>
    </Reports>
    my xslt file
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xdoxslt="http://www.oracle.com/XSL/Transform/java/oracle.apps.xdo.template.rtf.XSLTFunctions" >
    <xsl:output method="xml" encoding="UTF-8"/>
    <xsl:template match="/">
         <xsl:element name="Reports">
              <xsl:attribute name="version">2.00</xsl:attribute>
                   <deliveryNote>
                        <subjectId></subjectId>
                        </deliveryNote>
                   <deliveredReports>
                        <referDate>[Delivery note->H4]</referDate>
                   </deliveredReports>
                   <simpleReports>
                        <numberOfReports>2</numberOfReports>
                        <nReport>
                                  <reportName>Xyz</reportName>
                                  <reportVersion>1.0</reportVersion>
                                       <observations>
                                       <numberOfObservations>15</numberOfObservations>
                                       <columnObservation>
                                            <y>9</y>
                                            <rO>
                                                 <x>14</x>
                                                      <xsl:for-each select="TEST_XML/LIST_R1/R1">
                                                           <o><xsl:value-of select="xdoxslt:lpad(COL1,10,' ')"/></o>
                                                      </xsl:for-each>
                                            </rO>
                                       </columnObservation>
                                       </observations>
                             </nReport>
                        </simpleReports>
              </xsl:element>
    </xsl:template>
    </xsl:stylesheet>

    Please post the same in BI Publisher forum
    BI Publisher
    Thanks,
    Vino

  • The ABAP/4 Open SQL array insert results in duplicate database records

    Hi,
    Iam getting following error :
    The ABAP/4 Open SQL array insert results in duplicate database records.
    Error in ABAP application program.
    The current ABAP program "SAPLV60U" had to be terminated because one of the
    statements could not be executed.
    This is probably due to an error in the ABAP program.
    " Information on where terminated
    The termination occurred in the ABAP program "SAPLV60U" in "VBUK_BEARBEITEN".
    The main program was "SAPMSSY4 ".
    The termination occurred in line 503 of the source code of the (Include)
    program "LV60UF0V"
    of the source code of program "LV60UF0V" (when calling the editor 5030).
    Processing was terminated because the exception "CX_SY_OPEN_SQL_DB" occurred in
    the
    procedure "VBUK_BEARBEITEN" "(FORM)" but was not handled locally, not declared
    in the
    RAISING clause of the procedure.
    The procedure is in the program "SAPLV60U ". Its source code starts in line 469
    of the (Include) program "LV60UF0V "."
    Please assist how to proceed further ..
    Many thanks
    Mujeeb.

    Sorry, THe correct note is 402221.
    Description from the note
    << Please do not post SAP notes - they are copyrighed material >>
    Edited by: Rob Burbank on Feb 22, 2009 3:46 PM

  • Duplicate database records.

    Hi Gurus,
    I am trying to insert into a db table from an internal tbl. And the result return error as shown below:
    The ABAP/4 Open SQL array insert results in duplicate database records.
    How do  I solve this?
    Thank you in advanced.

    Hi,
    The following code can be used as a template to produce an ABAP which updates a particular database
    table field.
    *& Report  ZUPDATE_PRPS                                                *
    *&  Quick report to Update PRPS-FAKKZ database field                   *
    Report  ZUPDATE_PRPS.
    tables: prps.
    parameter: p_wbs like prps-pspnr,
               p_value like prps-fakkz default 'X'.
    data: wa_fakkz type prps-fakkz.
    *START-OF_SELECTION
    start-of-selection.
    call function 'CONVERSION_EXIT_ABPSP_INPUT'
         exporting
             input     = p_wbs
        importing
             output    = p_wbs
        exceptions
             not_found = 1
             others    = 2.
    select single fakkz
      into wa_fakkz
      from prps
    where pspnr eq p_wbs.
    if sy-subrc eq 0.
       update prps set fakkz = p_value where PSPNR eq p_wbs.
       if p_value is initial.
         message i999(za) with 'Billing element field has been unchecked'.
       else.
         message i999(za) with 'Billing element field has been checked'.
       endif.
    else.
      message i999(za) with 'WBS element not found'.
    endif.

  • Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the rows? Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the records?
    Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    The Oracle documentation has a good overview of the options available
    Generating XML Data from the Database
    Without knowing your version, I just picked 11.2, so you made need to look for that chapter in the documentation for your version to find applicable information.
    You can also find some information in XML DB FAQ

  • He ABAP/4 Open SQL array insert results in duplicate database records

    Dear Gurus,
    II am getting a dump when I run MD02/ MD03. (t- code to run MRP)
    Below is the message system is showing:
    Please help
    Thanks in Advance
    Best Regards
    Adhish
    Short text
    The ABAP/4 Open SQL array insert results in duplicate database records.
    What happened?
    Error in the ABAP Application Program
    The current ABAP program "SAPLM61U" had to be terminated because it has
    come across a statement that unfortunately cannot be executed.
    Error analysis
    An exception occurred that is explained in detail below.
    The exception, which is assigned to class 'CX_SY_OPEN_SQL_DB', was not caught
    in
    procedure "INSERT_MDSBI_IN_MDSB" "(FORM)", nor was it propagated by a RAISING
    clause.
    Since the caller of the procedure could not have anticipated that the
    exception would occur, the current program is terminated.
    The reason for the exception is:
    If you use an ABAP/4 Open SQL array insert to insert a record in
    the database and that record already exists with the same key,
    this results in a termination.
    (With an ABAP/4 Open SQL single record insert in the same error
    situation, processing does not terminate, but SY-SUBRC is set to 4.)
    1 *----
    2 * ARRAY-INSERT auf MDSB
    3 *----
    4 FORM INSERT_MDSBI_IN_MDSB.
    INSERT MDSB6 FROM TABLE MDSBI.
    7 ADD SY-DBCNT TO STATS-RESBI. "statistics
    8 ENDFORM.

    Hi,
    There must be inconsistency in the number range. This happens when the current number in the number range for dependent requirements is lower than the highest number in the database table of the dependent requirements RESB.
    Please check the current number in transaction OMI2. Here in the interval you can see the current number. Then please check the highest number in table RESB. If the current number in OMI2 is lower than the highest number in table RESB then this should be the reason for the dump.
    Check and revert. If that's not the case we'll look into other possibilities.
    In mean time check for SAP Note 138108.

  • ABAP/4 Open SQL array insert results in duplicate database records in SM58

    Hi Everyone,
    I am testing a file to idoc scenario in my Quality system. When I passed the input file, the mapping executed successfully and there are no entries in SMQ2 but still the idoc wasn't created in the ECC system. When I have checked in TRFC, I am getting the error  ABAP/4 Open SQL array insert results in duplicate database records for IDOC_INBOUND_AYNCHRONOUS function module. I thought this is a data issue and I have tested with a fresh data which was never used for testing in Quality but even then I am getting the same error.Kindly advise.
    Thanks,
    Laawanya

    use FM idoc_status_write_to_database to change the IDoc status from 03 to 30 and then  run WE14 or  RSEOUT00 to change the status back to 03
    resending idoc from status 03 ...is a data duplicatino issue on receiving side...why do u need to do that ?
    Use WE19 tcode to debug
    In we19
    1)U can choose your Idoc number in existing Idoc textbox
    2)Press execute
    3)u will display ur Idoc struct
    4)Dbl click on any field then u can modify its content
    5)PressStd Outbound Processing Btn to process modified Idoc
    Thats it

  • Proxy output not displayed in the output XML

    Hi,
    I have created a web service and is calling the service using SOAP UI tool. To do it i have created an RFC Fm and inported to SAP PI and activated it with the input and output parameters that i need. When i am calling the service through the SOAP UI, in debugging( in the provider class of the service interface of the sproxy transaction ) i am able to see the values filled in one of the parameters but the same is not getting displayed in the output XML.(Response). Can any one please suggest what cud be the reason.
    Thanks

    Hi,
    can give us a hint? Code output, screenshot? btw I hope your service is a Synchronous service.
    Thanks Nick.

Maybe you are looking for

  • Setup problem with acquired ipad

    When setting up a 16gb ipad I acquired from a former employee, I use my apple ID the same as for my iphone but it doesn't accept it and when selecting the "forgot password" option, I get the message Cannot Load iForgot. I'm stuck in setup right now.

  • Problems with Premier Elements 7 Opening Earlier Projects

    I have used Premier Elements 3 to create many 15-60 minute videos, most built from Photoshop Elements slide shows imported into Premier, and most with DVD output designed. After installing Version 7, I attempted to open these projects which it is sup

  • Do I get a free email account with my iPhone? If yes, how do I set it up?

    I just moved and I'm losing my email account I've had for years. I understand I have a free one that came with my iPhone but I can't fine ANYWHERE that tells me how to get it. MobileMe is ending and I don't know what the replacement is. Help! I don't

  • Unsorted Flat File into IDoc with multiple use of nodes

    Hi Experts! I am facing a little problem. I have a source flat file for a classification where some fields appear several times. My source flat file looks like this: item1; field1a item2; fieldA item3; fieldxa item1; field1b as you can see the item1

  • Want Flash movie to scale with table cell. NOT WORKING!

    Greetings; I have authored a Flash movie and it is working fine. When I use the html page output by Flash it scales fine but when I cut and paste this code into a table cell the movie will not scale (in Firefox) and not showup at all in IE 7. Help ap