How to convert Java string into XML one?

With SAX I can parse an xml file, but I should create xml file by hands.
Ok, it's simple, but how to encode java string into XML constant
like "Hello & goodby" into "Hello & goodby" ?
Is there a standard method for such special xml characters?

If you are creating your XML "by hand" then just make sure your hands know that you have to do that. It isn't difficult to write a Java method to do it, if "by hand" means "in Java code". Otherwise your XML is not well-formed. And as far as I know there is no package that takes ill-formed XML and fixes it up.

Similar Messages

  • How to convert Java Objects into xml?

    Hello Java Gurus
    how to convert Java Objects into xml? i heard xstream can be use for that but i am looking something which is good in performance.
    really need your help guys.
    thanks in advance.

    There are apparently a variety of Java/XML bindings. Try Google.
    And don't be so demanding.

  • How to convert a string into xml file

    Hi,
    i have a string . the string contain fully formated xml data. i mean my string like below
    <?xml version="1.0"?>
    <PARTS>
       <TITLE>Computer Parts</TITLE>
       <PART>
          <ITEM>Motherboard</ITEM>
          <MANUFACTURER>ASUS</MANUFACTURER>
          <MODEL>P3B-F</MODEL>
          <COST> 123.00</COST>
       </PART>
       <PART>
    ......................i want to convert it into an xml file
    can u help me?
    thank u

    Thank you Paul Clapham,
    and sorry ..
    i have some other doubt.. regarding xml
    i want to post an XML file from one server(Server_1) to other server.(Server_2)
    To generate an xml file i used DOM in Server_1.
    using xml.transform , StringWriter i converted it into String.
    I post the string to another server and there i will parse it.
    for that i write the code like below in servlet in server_1
    <form name=fn action=http://localhost:8080/server_2/parseXMl.do method=post>
    <input type=hidden name=xmlFile value="+Xmlstring+">
    <input type=submit >is this process is correct?
    Some of the turorial told that use web-services/XML-RPC
    but i new to both..
    I want to complete it using my knowledge only/
    Is it possible to do it?
    Or any other alternative?
    can help me?

  • How to convert database table into xml file

    Hi.
    How to convert database table into XML file in Oracle HTML DB.
    Please let me know.
    Thanks.

    This not really a specific APEX question... but I search the database forum and found this thread which I think will help
    Exporting Oracle table to XML
    If it does not I suggest looking at the database forum or have a look at this document on using the XML toolkit
    http://download-east.oracle.com/docs/html/B12146_01/c_xml.htm
    Hope this helps
    Chris

  • How to convert .stl file into .xml file. Subtitles to IMPORT INTO FCPro

    I have a subtitles file which was created in dvd studio pro. I exported that file and made a .stl file (which can be opened with TextEdit).
    I need to import that file into FCP to then make a quicktime file w/subs to be exported.
    I'm trying to use TitleExchange which tells you you CAN convert .stl files into .xml (FCPro type of file) but when I try to import the .stl subtitle file into TitleExchange to be converted to .xml I get the following error:
    Can't make "" into type boolean. (-1700)
    Can someone help?
    Thanks!!!
    Paula

    Can anyone help me?
    I absolutely need to import the subtitles into Final Cut and re-writing all of them manually would take forever.
    Please let me know if there is any program I need to use.
    Thanks for all tips
    Paula

  • How to convert Xls file into Xml file

    Hi,
    I am trying to convert Xls file into Xml  but there  is no any direct procedure for it
    Pls help me out to convert Xls file into Xml file
    Thanks
    Anushree

    you will require to write a module in your file adapter for the same.
    ref: /people/sap.user72/blog/2005/07/04/read-excel-instead-of-xml-through-fileadapter as mentioned in the earlier post.
    Else you can also use Conversion Agent to read the same.
    Ref: http://help.sap.com/saphelp_nw04/helpdata/en/43/4c38c4cf105f85e10000000a1553f6/content.htm

  • How to convert a string into orcle date format

    i need some information about converting string into date format.i have string like '20-SEP-05' .so we have to convert into date formate like yy-mm-dd' (2005-09-20).how can we do it.

    Here's some code to help. I can't remember what method uses what format though
      public static java.sql.Date sqlDateValueOf( String dateString ) {
        String stringDate = null;
        if ( dateString == null || dateString.length() < 10 ) return null;
        String strDay = "";
        String strMonth = "";
        String strYear = "";
        if ( dateString.substring(4,5).equals( "-" ) ) {
          strDay = dateString.substring(8, 10);
          if ( strDay.length() < 2 ) strDay = "0" + strDay;
          strMonth = dateString.substring(5, 7);
          strMonth = dateString.valueOf(Integer.parseInt(strMonth) - 1);
          if ( strMonth.length() < 2 ) strMonth = "0" + strMonth;
          strYear = dateString.substring(0, 4);
          stringDate = strDay + "-" + strMonth + "-" + strYear;
        else if ( dateString.substring(2,3).equals( "-" ) ) {
          strDay = dateString.substring(0, 2);
          if ( strDay.length() < 2 ) strDay = "0" + strDay;
          strMonth = dateString.substring(3, 5);
          strMonth = String.valueOf(Integer.parseInt(strMonth) - 1);
          if ( strMonth.length() < 2 ) strMonth = "0" + strMonth;
          strYear = dateString.substring(6, 10);
          stringDate = strDay + "-" + strMonth + "-" + strYear;
        Calendar cal = Calendar.getInstance();
        cal.set( Calendar.YEAR, Integer.parseInt( strYear ) );
        cal.set( Calendar.MONTH, Integer.parseInt( strMonth ) );
        cal.set( Calendar.DAY_OF_MONTH, Integer.parseInt( strDay ) );
        java.sql.Date outDate = new java.sql.Date( cal.getTimeInMillis() );
        return outDate;
      public static String toDateString( java.util.Date date) {
        if ( date == null || date.toString().length() < 10 ) return null;
        String outDate = "";
        SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
        outDate = df.format( date );
        return outDate;
      public static String toDateString( java.sql.Date date) {
        if ( date == null || date.toString().length() < 10 ) return null;
        String outDate = "";
        SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
        outDate = df.format( date );
        return outDate;
      public static String toDateString( java.sql.Date date, String format) {
        if ( date == null || date.toString().length() < 10 ) return null;
        String outDate = "";
        SimpleDateFormat df = new SimpleDateFormat( format );
        outDate = df.format( date );
        return outDate;
      public static String toDateString( java.sql.Timestamp date) {
        if ( date == null || date.toString().length() < 10 ) return null;
        String outDate = "";
        SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
        outDate = df.format( date );
        return outDate;
      }

  • How to convert ALV output into XML format.

    Hi all,
    I just want to know how to convert an ALV output into a XML format, this is really urgent.
    regards,
    Ruchika saini

    This program exports an internal table to an XML file. *----
    Report ZPRUEBA_MML_13 *
    Export an internal table to XML document *
    NO BORRAR ESTE CODIGO *
    REPORT ZPRUEBA_MML_13.
    PANTALLA SELECCION *
         PARAMETERS: GK_RUTA TYPE RLGRAP-FILENAME.
    PANTALLA SELECCION *
    TYPE TURNOS *
    TYPES: BEGIN OF TURNOS,
         LU LIKE T552A-TPR01,
         MA LIKE T552A-TPR01,
         MI LIKE T552A-TPR01,
         JU LIKE T552A-TPR01,
         VI LIKE T552A-TPR01,
         SA LIKE T552A-TPR01,
         DO LIKE T552A-TPR01,
    END OF TURNOS.
    TYPE TURNOS *
    TYPE SOCIO *
    TYPES: BEGIN OF SOCIO,
         NUMERO LIKE PERNR-PERNR,
         REPOSICION LIKE PA0050-ZAUVE,
         NOMBRE LIKE PA0002-VORNA,
         TURNOS TYPE TURNOS,
    END OF SOCIO.
    TYPE SOCIO *
    ESTRUCTURA ACCESOS *
    DATA: BEGIN OF ACCESOS OCCURS 0,
         SOCIO TYPE SOCIO,
    END OF ACCESOS.
    ESTRUCTURA ACCESOS *
    START OF SELECTION *
    START-OF-SELECTION.
         PERFORM LLENA_ACCESOS.
         PERFORM DESCARGA_XML.
    END-OF-SELECTION.
    END OF SELECTION *
    FORM LLENA_ACCESOS *
    FORM LLENA_ACCESOS.
    REFRESH ACCESOS.
    CLEAR ACCESOS.
    MOVE: '45050' TO ACCESOS-SOCIO-NUMERO,
                   'MOISES MORENO' TO ACCESOS-SOCIO-NOMBRE,
                   '0' TO ACCESOS-SOCIO-REPOSICION,
                   'T1' TO ACCESOS-SOCIO-TURNOS-LU,
                   'T2' TO ACCESOS-SOCIO-TURNOS-MA,
                   'T3' TO ACCESOS-SOCIO-TURNOS-MI,
                   'T4' TO ACCESOS-SOCIO-TURNOS-JU,
                   'T5' TO ACCESOS-SOCIO-TURNOS-VI,
                   'T6' TO ACCESOS-SOCIO-TURNOS-SA,
                   'T7' TO ACCESOS-SOCIO-TURNOS-DO.
    APPEND ACCESOS.
    CLEAR ACCESOS.
    MOVE: '45051' TO ACCESOS-SOCIO-NUMERO,
                   'RUTH PEÑA' TO ACCESOS-SOCIO-NOMBRE,
                   '0' TO ACCESOS-SOCIO-REPOSICION,
                   'T1' TO ACCESOS-SOCIO-TURNOS-LU,
                   'T2' TO ACCESOS-SOCIO-TURNOS-MA,
                   'T3' TO ACCESOS-SOCIO-TURNOS-MI,
                   'T4' TO ACCESOS-SOCIO-TURNOS-JU,
                   'T5' TO ACCESOS-SOCIO-TURNOS-VI,
                   'T6' TO ACCESOS-SOCIO-TURNOS-SA,
                   'T7' TO ACCESOS-SOCIO-TURNOS-DO.
    APPEND ACCESOS.
    ENDFORM.
    FORM LLENA_ACCESOS *
    FORM DESCARGA_XML *
    FORM DESCARGA_XML.
    DATA: L_DOM TYPE REF TO IF_IXML_ELEMENT,
                   M_DOCUMENT TYPE REF TO IF_IXML_DOCUMENT,
                   G_IXML TYPE REF TO IF_IXML,
                   W_STRING TYPE XSTRING,
                   W_SIZE TYPE I,
                   W_RESULT TYPE I,
                   W_LINE TYPE STRING,
                   IT_XML TYPE DCXMLLINES,
                   S_XML LIKE LINE OF IT_XML,
                   W_RC LIKE SY-SUBRC.
    DATA: XML TYPE DCXMLLINES.
    DATA: RC TYPE SY-SUBRC,
    BEGIN OF XML_TAB OCCURS 0,
                   D LIKE LINE OF XML,
    END OF XML_TAB.
    CLASS CL_IXML DEFINITION LOAD.
    G_IXML = CL_IXML=>CREATE( ).
    CHECK NOT G_IXML IS INITIAL.
    M_DOCUMENT = G_IXML->CREATE_DOCUMENT( ).
    CHECK NOT M_DOCUMENT IS INITIAL.
    WRITE: / 'Converting DATA TO DOM 1:'.
    CALL FUNCTION 'SDIXML_DATA_TO_DOM'
    EXPORTING
                   NAME = 'ACCESOS'
                   DATAOBJECT = ACCESOS[]
    IMPORTING
                   DATA_AS_DOM = L_DOM
    CHANGING
                   DOCUMENT = M_DOCUMENT
    EXCEPTIONS
                   ILLEGAL_NAME = 1
                   OTHERS = 2.
    IF SY-SUBRC = 0.
                   WRITE 'Ok'.
    ELSE.
                   WRITE: 'Err =',
                   SY-SUBRC.
    ENDIF.
    CHECK NOT L_DOM IS INITIAL.
    W_RC = M_DOCUMENT->APPEND_CHILD( NEW_CHILD = L_DOM ).
    IF W_RC IS INITIAL.
                   WRITE 'Ok'.
    ELSE.
                   WRITE: 'Err =',
                   W_RC.
    ENDIF.
    CALL FUNCTION 'SDIXML_DOM_TO_XML'
    EXPORTING
                   DOCUMENT = M_DOCUMENT
    IMPORTING
                   XML_AS_STRING = W_STRING
                   SIZE = W_SIZE
    TABLES
                   XML_AS_TABLE = IT_XML
    EXCEPTIONS
                   NO_DOCUMENT = 1
                   OTHERS = 2.
    IF SY-SUBRC = 0.
                   WRITE 'Ok'.
    ELSE.
                   WRITE: 'Err =',
                   SY-SUBRC.
    ENDIF.
    LOOP AT IT_XML INTO XML_TAB-D.
                   APPEND XML_TAB.
    ENDLOOP.
    CALL FUNCTION 'WS_DOWNLOAD'
    EXPORTING
                   BIN_FILESIZE = W_SIZE
                   FILENAME = GK_RUTA
                   FILETYPE = 'BIN'
    TABLES
                   DATA_TAB = XML_TAB
    EXCEPTIONS
                   OTHERS = 10.
    IF SY-SUBRC <> 0.
                   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    ENDFORM.
    Message was edited by:
            Hymavathi Oruganti

  • How to convert a string into an objects name?

    Hi
    I have the following problem;
    I have a string
    String a = "e1"
    and a method
    call(Event e1) that calls the "Event" class with object the name of the string a.
    How can I convert the strings name into an object so as to use it in the "call" method?
    Any ideas?
    Thanks in advance

    I don't know if this helps you, but you can do things like this.
    String a = "com.example.SomeEvent";
    //Instantiate com.example.SomeEvent
    Object o = Class.forName(a).newInstance();SomeEvent must have a non-argument constructor for this to work.
    Class that will be instantiated depens on runtime value of String a, and can be different across different executions of the program.

  • How can convert HTML file into xml file?

    Hi,
    I am receving one HTML file as an input and i want to convert that receiving(html file) into .xml file.Is there any converter (tools)to do this.Pls if any give me the details with regard.
    Regards,
    mahesh.

    Use the HTMLEditorKit to parse the html file.
    this kit is having the callback methods which
    are called wenever the tag appears in the HTML
    stream.

  • How should convert text file into XML file?

    I do a project "WEB SERVER LOG ANALYZER" using JSP. For that i copy the content of log file into the other file . how i convert it into XML file . xplain with coding

    Read this [page.|http://www.devx.com/getHelpOn/10MinuteSolution/20356]

  • How to convert text file into xml file format with and check that with DTD

    I have an text file with | seperator . I have to convert this to an xml file and check with DTD present with me..
    plz help me out

    can i get some code that how to compare the xml with dtd or just give the DTD name with an XML

  • How to convert a string into a collection of KeyEvents

    I'm working on a program that must interact with a 3rd party application (closed to me, I have no access to the code or anything like that). I have been unable to send data to the program by getting its OutputStream. The only thing that has worked was using a Robot object to send individual key events (i.e. robot.keyPress(KeyEvent.VK_A);). Therefore I'm looking to convert a string (many different strings actually) into a collection of their associated KeyEvents so I can send them to the other application. Does anyone know a good way of doing it, or is anyone able to help me with using the OutputStream?
    Thank you!
    (The 3rd party application is Attachmate InfoConnect, a Unisys terminal emulation program that I have to use to access a mainframe).

    Here is a code sample.     public void checknumber(int vsize){
    int total;
    String anum;
    anum = tf2.getText();
    validnumber = true;
    lines2combine = 1;     //default (an integer)
    recs2make = 1;          //default
    try{
    lines2combine = Integer.parseInt(anum);
    catch (NumberFormatException e){
              System.out.println("Entry for lines to combine not numeric");
         validnumber = false;
         d1Title = "Data Entry Error";
         d1Txt = "For number for lines to combine;";
         d2Txt = "Enter a number.";
         doMessage();

  • How to convert xls files into xml

    hi all,
    please tell me how to convert the xls files into xml

    Hey Sayee,
    This gives you step by step procedure to start up
    saptechnical  com/Tutorials/XI/Adapter/Index.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/8b/895e407aa4c44ce10000000a1550b0/content.htm
    Regards
    Pothana

  • How to convert DTD files into XML(template) by using Java ?

    I am a beginner to java,and want to convert a random DTD file
    into a XML template(having no data).
    any guys can give me some suggestions ?
    thanks very much

    DTD allow you to validate a XML file.
    To do so, you can use API such as dom or xalan.
    To transform an XML file from a vocabulary A to vocabulary B, you have to write a XSLT style sheet, and use xerces to perform the transformation.
    Using tools such as XSL-FO, you can transform your XML into PDF.

Maybe you are looking for