How to convert from xml file to html using java code

How to convert from xml file to html file using java code

Get yourself Apache Xalan or Saxon or some XSLT processor
String styleSheet = "/YourXSLTStylesheet.xsl";
String dataSource = "/YourXMLDocument.xml";
InputStream stylesheetSource = TransformMe.class.getResourceAsStream(styleSheet);
InputStream dataSourceStream = TransformMe.class.getResourceAsStream(dataSource);
OutputStream transformedOut = new FileOutputStream("filename.html");
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource(stylesheetSource));
transformer.transform(new StreamSource(dataSourceStream), new StreamResult(transformedOut));You'll also need to learn XSLT if you don't already know that. Here's a good place to start
http://www.w3schools.com/xsl/

Similar Messages

  • HOW TO CONVERT A XML FILE TO HTML FILE FORMAT IN WINDOWS APPLICATION

    Hi iam a fresher iam working on a project in that i should convert the data in xml file to html file. I dont have any idea regarding this can anyone help me how to convert the xml file to a html file format. I just written the code till how to read the xml
    file. Now i stucked how to write the code for converting to html format.
    Thanks and Regards,
    Dileep.

    Hi iam a fresher iam working on a project in that i should convert the data in xml file to html file. I dont have any idea regarding this can anyone help me how to convert the xml file to a html file format. I just written the code till how to read the xml
    file. Now i stucked how to write the code for converting to html format.
    Thanks and Regards,
    Dileep.
    Hello,
    For converting xml file to html, we could refer to the way shared in the following thread which uses an XSLT stylesheet to transform the XML into another format using the
    XslTransform class.
    http://www.codeproject.com/Articles/12047/How-to-Convert-XML-Files-to-HTML
    Regards.
    Carl
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Convert XML file into DTD using Java

    Hi All,
    I want to do convert the xml file into DTD using Java.
    I read the DOM package but didnt get clear idea.
    Anyone of you have an idea please share the coding with me.
    Any suggestions greatly appreciated.
    Thanks
    Veera

    Hi All,
    I want to do convert the xml file into DTD using Java.
    I read the DOM package but didnt get clear idea.
    Anyone of you have an idea please share the coding with me.
    Any suggestions greatly appreciated.
    Thanks
    Veera

  • Does anyone know how to convert an XML file to a readable file?

    All,
    I have been using an APP called "SMS Backup & Restore" to backup my message conversations to my Laptop PC.  It works fine BUT the backup file, once in my PC, has an XML extent such as "filename.XML"
    I would like to read and/or print and/or save the text message file so does anyone know how to convert the XML file to something else so it shows all the messages without all the formatting instructions.   
    When I try to see the XML file it shows all the formatting.  If I replace the .XML with .TXT that too shows all the formatting mixed in with the text message narrative.
    When I look at the XML file in SMS Backup & Restore in the Charge phone it looks great showing all the messages just as they were on the phones display.  The problem with this is that there is no way to print or read or save the messages as they appear in the file from the phone itself.  I tried screen capture but if you have, let's say, a 28 message conversation you have to do 7 or 8 screen captures to get them all.
    If only I could convert the XML in my PC to something that is printable or savable or readable that would be the "cats meow."
    Anyone know how???
    JerryF
    PS, You might take a look at my related post.
    https://community.verizonwireless.com/message/809832#809832

    Ann154,
    You were correct again.  I deleted everything I had done to date and re-did the entire SMS backup of my 28 message conversation again and YES I was able to open it using IE-8.  It looks great and it prints great and life is good!  I am going to go make a donation.
    Thanks again for the help.  I marked this thread as answered by you.
    JerryF

  • How to convert from XML to Array ?

    how to convert from XML to Array ?
    thanks in advance

    this is a segment of the xml object:
    var myXML:XML =
    <data>
    <task>
    <taskID>2</taskID>
    <startDate>2/15/2007</startDate>
    </task>
    </data>
    i want to conver myXML into ArrayCollection: like this:
    private var expenses:Array = [
    {taskID:"1", startDate:"2/15/2007"},
    {taskID:"2", startDate:"4/15/2007"}
    how i can do it ? and tell me how to retrieve the data from
    the collection
    thanks

  • How can we get requester's user id using java code

    Hi,
    How can we get requester's user id using java code?
    eg: If i had logged in as xelsysadm and request a resource for user uid101 on the userid field it should display uid101 and not xelsysadm.
    also,
    I have a resoure "A" which on revoking should also revoke resources B and C. How can it be done. Resource A, B, and C are 3 different resource objects.
    ==Thanks,
    doki

    Ok, so there is a way, but it's not available during submission. You can use the findRequests api. From the result set, get the "Requests.Consolidated Data Value" value. In this information, you will get an xml formatted data. It provides the list of users on the request on the left side after submission. After the request is completed, this value is available. Upon completion, you could get the request information, get this value, and parse the information for user ids.
    In the same adapter, use the following API:
    formIntf.setObjectFormData(objInstanceKey, formHash)
    The formHash is a hashtable containing the field name on your object form, and the values you wish to populate it with. You could create a textarea box on your object form and populate the userids for who the request is for.
    However, this makes absolutely 0 sense. When you get a request, the list of userids are listed right there on the request.
    -Kevin

  • How to generate the XML file to HTML?

    Hi all,
    I am new to XML.
    Can I somehow see the HTML-Output of the XML-File, when I have the XSL-File too, but don't use any XML-Editor (XMLSpy) and FOP? I do not want use any additional tools - only the database tools.
    What I need for this?
    Do I need the XSLT-File too?
    ============================
    My test.xml file:
    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="test.xsl"?>
    <ROW num="1">
         <TABLE_NAME>ABR_ART_ABR_DAU_MATRIX</TABLE_NAME>
         <TABLESPACE_NAME>PS2000_STAMM</TABLESPACE_NAME>
         <PCT_FREE>10</PCT_FREE>
         <INI_TRANS>1</INI_TRANS>
         <MAX_TRANS>255</MAX_TRANS>
         <INITIAL_EXTENT>516096</INITIAL_EXTENT>
         <NEXT_EXTENT>65536</NEXT_EXTENT>
         <MIN_EXTENTS>1</MIN_EXTENTS>
         <MAX_EXTENTS>2147483645</MAX_EXTENTS>
         <PCT_INCREASE>0</PCT_INCREASE>
         <LOGGING>YES</LOGGING>
         <BACKED_UP>N</BACKED_UP>
         <NUM_ROWS>33</NUM_ROWS>
         <BLOCKS>20</BLOCKS>
         <EMPTY_BLOCKS>0</EMPTY_BLOCKS>
         <AVG_SPACE>0</AVG_SPACE>
         <CHAIN_CNT>0</CHAIN_CNT>
         <AVG_ROW_LEN>100</AVG_ROW_LEN>
         <AVG_SPACE_FREELIST_BLOCKS>0</AVG_SPACE_FREELIST_BLOCKS>
         <NUM_FREELIST_BLOCKS>0</NUM_FREELIST_BLOCKS>
         <DEGREE> 1</DEGREE>
         <INSTANCES> 1</INSTANCES>
         <CACHE> N</CACHE>
         <TABLE_LOCK>ENABLED</TABLE_LOCK>
         <SAMPLE_SIZE>33</SAMPLE_SIZE>
         <LAST_ANALYZED>1/8/2004 11:45:1</LAST_ANALYZED>
         <PARTITIONED>NO</PARTITIONED>
         <TEMPORARY>N</TEMPORARY>
         <SECONDARY>N</SECONDARY>
         <NESTED>NO</NESTED>
         <BUFFER_POOL>DEFAULT</BUFFER_POOL>
         <ROW_MOVEMENT>DISABLED</ROW_MOVEMENT>
         <GLOBAL_STATS>YES</GLOBAL_STATS>
         <USER_STATS>NO</USER_STATS>
         <SKIP_CORRUPT>DISABLED</SKIP_CORRUPT>
         <MONITORING>NO</MONITORING>
         <DEPENDENCIES>DISABLED</DEPENDENCIES>
         <COMPRESSION>DISABLED</COMPRESSION>
    </ROW>
    ============================
    ============================
    My test.xsl-file:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:output method="html"/>
    <xsl:template match="/">
    <html>
    <head>
    <title>Test XSL ALL_TABLES</title>
    </head>
    <body>
    <xsl:for-each select="ROW">
    <h2>Tabelle: <xsl:value-of select="TABLE_NAME"/></h2>
         <hr/>
         <table border="1" cellpadding="0">
                             <tr>
                             <td><xsl:value-of select="TABLESPACE_NAME"/></td>
                             <td><xsl:value-of select="PCT_FREE"/></td>
                             </tr>
                        </table>
              </xsl:for-each>          
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>
    ============================
    I am waiting for your answers, when possible with examples please.
    Regards
    Leonid Pavlov

    XSLT to convert the XML document to Html:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>
    <xsl:template match="/">
    <html>
    <head>
    <title>Test XSL ALL_TABLES</title>
    </head>
    <body>
    <table border="1" cellspacing="0">
    <tr>
    <th>TABLE NAME</th>
    <th>TABLESPACE NAME</th>
    <th>PCT FREE</th>
    </tr>
    <xsl:for-each select="ROW">
    <tr>
    <td><xsl:value-of select="TABLE_NAME"/></td>
    <td><xsl:value-of select="TABLESPACE_NAME"/></td>
    <td><xsl:value-of select="PCT_FREE"/></td>
    </tr>
    </xsl:for-each>
    </table>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>

  • How to write excel file (.xlsx) using file adapter without using java code

    Hi All,
    In soa suite 11g Is there any ways to write the data to the excel ( xlsx ) file using fileadapter and not using java code..Thanks in Advance

    Hi Siva,
    I don't think there is any way to write .xls file directly. You'll have to use some Java API (iText etc.) to create an .xls file. However, you can write .csv file that can be easily converted into .xls at the target end. In MS, it opens as Excel file if delimiter is comma *,*.
    Regards,
    Neeraj Sehgal

  • How to dynamically configure JPA setting at runtime using java code?

    Hi,
    I am new to EJB 3.0 and JPA. I am trying to help my company to deploy the use of JPA in EJB3.0. Currently, i am trying out with OpenJPA in IBM Webshpere Application Server 7.0. We have four different WAS servers running for testing, system integration testing, user testing and production respectively, and in each region, the configurations for data source, JDBC username and password, schema, etc are different. So i think i would need to configure the JPA setting during runtime using Java code that determines which is the environment. And apparently i am stuck with the limited knowledge i have.
    1) I understand that i could override the JDBC in the persistence xml by creating entity manager using entity manager factory. But is it possible that i do similar thing by using inejction of persistence context on entity manager to obtain a container managed entity manager?
    2) Alternatively, it is possible to create multiple persistence unit in the XML and inject different PU to the entity manager, am i right? But how to inject dynamically since @PersistenceContext(unitName="xxx") only accepts constant declaration.
    3) Is it possible that the JDBC username and password are read from properties file?
    Thanks for your help in advance!

    Hi
    Thanks for the reply.
    Are you saying that i have to configure the data source authentication to the backend DB2 using the JAAS-J2C? Correct me if i am mistaken. I guess i am unable to do so as the application server setup only contains one data source, and the server hosted a number of applications. Every applications has their own JDBC username and password supply to the data source (the ID supplied at the DB2 side will decide which resource can access) and thus, i have to supply the username and password at runtime. Talked to the server guy and seems that it is not feasible to have seperate datasource for each applications as considered to the volume of applications hosted inside the server.
    Any suggestion?

  • How to convert a CSV file to HTML?

    Hi I'm wondering how we can convert a CSV file to a HTML file?
    Moreover what is the best way to count the number of lines in a given file?
    Is using readlines() the best way?
    Thanks,
    Kishore

    Kishorei20 wrote:
    Hi I'm wondering how we can convert a CSV file to a HTML file? easy way: put <html> in the front and </html> at the end and yu've got an html file
    but I think what ur looking for is how to build table
    start with <table><tr><td>
    every comma becomes </td><td>
    every newline become </td></tr></tr><td>
    Moreover what is the best way to count the number of lines in a given file?
    Is using readlines() the best way?
    Thanks,
    Kishore

  • How to convert xml file to xsl using java

    Hi all,
    I have an XML file with which i need to convert(transform) it to an xsl file using java.
    I am new to converting xml file to xslt.Please send me if u have code .
    Thanks in advance
    regards
    Ram

    You seem to be asking the wrong question. An XSL file can be used to transform an XML file, but transforming an XML into an XSL does not make sense. The API for running XSL transforms on the Java platform is described here:
    http://java.sun.com/javase/6/docs/api/javax/xml/transform/package-summary.html

  • How to convert hierarchy XML to CSV format using PI/XI

    Hi All,
         I am working with SAP PI/XI for the first time and need some help file conversion of complex hierarchy XML to CSV file using PI. I have done plenty of research on SDN and could find much related to what I want to do.
    Here is the example of how my input XML would look like:
    <?xml version="1.0" encoding="UTF-8"?>
    <PartyMaster type="OrgHierarchy" name="Compass Group Owned">
        <PartyMasterHierarchy>
             <Hierarchy level="3" nodeName="Bon Appetit Sector" type="Sector" ID="A00000" refID="A00000">     
                   <Hierarchy level="4" nodeName="BA Division" type="Division" ID="AB0000" refID="AB0000" >               <Hierarchy level="5" nodeName="BA East Coast Region" type="Region" ID="ABE000" refID="ABE000">
                             <Hierarchy level="6" nodeName="Engstrom, John RVP" type="District" ID="ABE01" refID="ABE01" >
                             </Hierarchy>
                           </Hierarchy>
         </Hierarchy>
                    </Hierarchy>
                    <Hierarchy level="3" nodeName="Levy Sector" type="Sector" ID="K00000" refID="K00000".               <Hierarchy level="4" nodeName="Levy Sector Division" type="Division" ID="K90000" refID="K90000">              <Hierarchy level="5" nodeName="Levy Sector Region" type="Region" ID="K99000" refID="K99000">                   <Hierarchy level="6" nodeName="TBA Total" type="District" ID="K9901" refID="K9901">                        </Hierarchy>
              </Hierarchy>
         </Hierarchy>
                     </Hierarchy>
            </PartyMasterHierarchy>
    </PartyMaster>
    I would like to get CSV output in the format below
    *DISPLAY_NAME     DOCUMENT_DESCRIPTION      PARENT           EXTERNAL_ID     ORG_UNIT_TYPE*     
    Bon Appetit Sector     Bon Appetit Sector      constant value    A00000                       constant value
    Levy Sector          Levy Sector           constant value    K00000                 constant value
    BA Division          BA Division            A00000                 AB0000                       constant value
    Levy Sector Division         Levy Sector Division       K00000              K90000                       constant value
    BA East Coast Region     BA East Coast Region          AB0000             ABE000                        constant value
    Levy Sector Region     Levy Sector Region       K90000              K99000                        constant value
    Engstrom, John RVP     Engstrom, John RVP        ABE000               ABE01              constant value
    TBA Total                    TBA Total             K99000               K9901             constant value
    1) How do I go about this? I think I have to configure an adapter but which adapter would give me the desired result?
    2) How do I tell PI when to pick the file from and where to place it after conversion? Could this be done in adapter configuration?
    Any help will be greatly appreciated.
    Thanks.
    --Mithun

    Mithun,
    you would get lot of answers if you looking in the PI (process integration forum)... There is something calles File content coversion in XI file adapter (which can convert the xml to csv and viceversa)

  • How to read an xml file in OSB using file protocol where reading file path is dynamic.

    HI,
    We have to read a xml file from a location and write into Db.
    Here reading file location is dynamic .
    Please suggest

    Hi
    With open dataset you can open any file on the application server. So it should be working, but maybe you are looking for:
    CALL TRANSFORMATION my_transformation
           SOURCE  XML xml_string
           RESULT  ROOT1 = field1
                   ROOT2 = field2.
    Best regards,
    Guido Koopmann

  • How to overwrite  the xml file by  flash using Php

    Hi
    i am creating getting data from the xml file ... and i am
    doing some Alteration in the xml file by flash after that flash
    producing the xml file i finished upto this process...
    nw i neeed to overwrite the xml file.... using Php.....
    can any one give me some idea ... to solve this issue
    ~~SK

    Flash Player cannot write XML files at all. but using
    php+flash we could do it .

  • How to run SQL script file on Linux using Java ?

    Hi,
    I need to execute .sql file using java. I used following approach for this.
    private void runScriptEvent(java.awt.event.ActionEvent evt) {                               
            String sqlOutput = "";
            String sqlPromptLines="";
            String currentFunctionName = "";
            if(con!=null){
                String userName = jTextField4.getText();
                String password = jPasswordField1.getText();
                String databaseName = jTextField3.getText();
                try {
                    String script_location = "";
                    ProcessBuilder processBuilder =null;
                    Process process = null;
                    //File file = new File("C:/ScriptFile");
                    File file = new File("./SQL_Script");
                    //File file = new File("E:\\install\\SQL_Script");
                    if(file.exists()){
                        File [] list_files= file.listFiles(new FileFilter() {
                                        public boolean accept(File f) {
                                        if (f.getName().toLowerCase().endsWith(".sql"))
                                        return true;
                                        return false;
                    int count = 0;
                        for (int i = 0; i<list_files.length;i++){
                            script_location = "@" + list_files.getAbsolutePath();//ORACLE
    //currentFunctionName = list_files[i].getName();
    StringTokenizer st = new StringTokenizer(list_files[i].getName(), ".");
    while(st.hasMoreTokens()) {
    currentFunctionName = st.nextToken();
    String extention= st.nextToken();
    System.out.println("Function Name = "+currentFunctionName + "\t Extention = " + extention);
    processBuilder = new ProcessBuilder("sqlplus",userName+"/"+password+"@"+databaseName, script_location); //ORACLE
    processBuilder.redirectErrorStream(true);
    process = processBuilder.start();
    BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
    String currentLine = null;
    while ((currentLine = in.readLine()) != null) {
    sqlPromptLines = " "+sqlPromptLines + currentLine +"\n";
    count ++;
    System.out.println(count+" " + currentLine);
    if(currentLine.equalsIgnoreCase("Function created.")){
    sqlOutput = "\n" sqlOutput currentFunctionName + " " currentLine"\n" ;
    break;
    }// end while
    in.close();
    process.destroy();
    }//end for
    }//end if file exists
    } catch (IOException e1) {
    jTextArea1.setText(e1.getMessage());
    System.out.println("Script Done");
    jTextArea1.append(sqlOutput);
    }// end id Connection is not null
    Above code working appropriate on Windows but not on Linux.
    is there any changes needed ?
    Regards,
    Ajay
    Edited by: Ajay Sharma on Nov 21, 2012 6:43 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Hi gimbal2,
    about code
    jTextArea1.setText(e1.getMessage());I am using this code so that the user will be prompted with a message rather than stack trace.
    About the issue I am getting on linux i believe its because of following statement.
    processBuilder = new ProcessBuilder("sqlplus",userName+"/"+password+"@"+databaseName, script_location); //ORACLERegards,
    Ajay
    Edited by: Ajay Sharma on Nov 23, 2012 12:05 PM
    Edited by: Ajay Sharma on Nov 23, 2012 12:06 PM

Maybe you are looking for