How to attach XSL into XML generated by XMLEncoder?

Hi everyone,
I used XMLEncoder to generate an XML file. But XMLEncoder does not provide anyway to attach XSL style sheet before generating the XML. The only way I can attach XSL style sheet is to manually edit the XML file, which I do not want to do. Is there anyway to insert the XSL sytle sheet tag using Java code? Any suggestions? thanks

I am not quite sure that this would work, but in theory (I have never tested it, and I am not a java-guru) it just might work. I havent worked a lot with piped streams either, so there might be a flaw there that I dont know about.
import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
// Making the pipes
PipedInputStream inpipe = new PipedInputStream();
PipedOutputStream outpipe = new PipedOutputStream( inpipe );
// Redirecting XML encoding to pipe
new XMLEncoder( outpipe );
// Making a transformer with xsl schema
TransformerFactory tFactory = TransformerFactory.newInstance();
StreamSource xslsource = new StreamSource( "xslsource.xsl")
Transformer transformer = tFactory.newTransformer( xslsource );
// Transforming from pipe to file
StreamSource xmlsource = new StreamSource( inpipe );
File xmlfile = new File( "xmlfile.xml" )
StreamResult xmlresult = new StreamResult( xmlfile );
transformer.transform( xmlsource, xmlresult );
...Think about it or try it out...
Good luck!
/Richard

Similar Messages

  • How to convert idoc into xml/edifact

    hi everyone just now i have started to work on edi, i want to kno how to convert idoc into xml/edifact. plz  reply asap

    Firstly, I will reply when and if I choose to. I do not require the asap nonsense at the end of your sentence.
    EDIFACT - You will need a subsystem.
    XML - I am not 100%. It may also depend on what version of SAP you are on. As I do not know if later versions of SAP can convert IDoc to XML.

  • How to convert HTML into XML

    I know I can parse XML into some HTML, but is there any tools or methods existed to parse HTML into XML?
    I have a not well-formed HTML with a lot data fields, including a lot not closed tags. This HTML is generated by some XML(as I can see), but I can't find a way to reform it into a XML, and eventually stored the data into another database.
    Anyone can help me? I appreciate!
    KIB

    As SAm has told you, you can use jTidy, for the purpose, a sample code , which can convert an html file to xml file is given at following url:
    see the documentation as well.
    http://sourceforge.net/docman/display_doc.php?docid=1298&group_id=13153
    gaurav_k1

  • How to write data into xml through web service

    Hi,
      I have a requirement to write the data into xml through a web service .send me related links and sample code if any.

    hi kiran,
      write the data into xml : We need suitable set of java Beans for handling WebService Data.
       However, there are cases when you may prefer an alternate mapping, or when there just isn't a well-defined mapping for your particular schema construct (xsd:choice is a common example). For these cases, IBM® WebSphere® has introduced a new feature called Custom Data Binding that allows you to integrate alternate data binding technologies like JAX-B, EMF/SDO and XML beans, as well to define your own XML schema to Java mappings. This article provides an overview of the technology and how you can get started integrating it into your application.
    GO THru THis Links :
    http://www-128.ibm.com/developerworks/websphere/library/
    techarticles/0601_gallardo/0601_gallardo.html.
    Hope It Helps.
    Thanks
    Varun CN

  • How to include CDATA in xml generated from XQuery

    I need to include Cdata in the xml generated from my xquery which is given below:
    I tried using XMLCDATA, but not getting the desired output. What am I doing wrong?
    SELECT XMLQuery('<InsUpdDel>
    for $crv in ora:view("RELATION")
    return
    <first>
    <eff_date>{$crv/ROW/EFF_DATE/text()}</eff_date>
    <source>{$crv/ROW/SOURCE/text()}</source>
    <key>
    <fld>
    <id>from_type</id>
    <val>XMLCDATA({$crv/ROW/FROM_ENT_TYPE/text()})</val>
    </fld>
    <fld>
    <id>from_ent_id</id>
    <val>{$crv/ROW/FROM_ENT_ID/text()}</val>
    </fld>
    </key>
    </first>}</InsUpdDel>'
    RETURNING CONTENT)
    FROM dual;
    The output I get is XMLCDATA(C), while the desired output is <![CDATA[C]]>

    Forgive me my vanity to think I can contribute by kicking doors open that are probably already wide open....I might create more confusion, but perhaps it helps some of the readers of this thread....
    In general it is not such a good idea to use "string" functions to create (serialized) XML. XML tools (including Oracle XML DB) go through a lot of effort to make sure that when a "native" XML structure is serialized to a string, the XML rules are strictly obeyed (e.g. special character escaping).
    Just assume e.g. that the $i/Reference from above contains something like ]]><
    The resulting XML would not be valid.
    More info on serializing XML in the context of XQuery is available from
    - http://www.w3.org/TR/xquery/#id-serialization
    - http://www.w3.org/TR/xslt-xquery-serialization/
    - http://www.w3.org/TR/xslt-xquery-serialization/#XML_CDATA-SECTION-ELEMENTS
    Unfortunately I do not think Oracle XML DB currently implements these parts of the spec (perhaps 11g will)...leaving the OP's question unanswered.
    Anyway, if going the route of serializing the XML through string functions, it is always good to realize the dangers of such an approach.
    Peter

  • How to insert fragment into xml column generated from query

    I'm trying to generate xml from some relational data and then insert a sub node into an xml column. Here's some sample code that obviously doesn't work.  I'm trying to figure out the syntax where the ???? exist.
    /* create test tables*/
    DECLARE @person TABLE
    id int NOT NULL PRIMARY KEY CLUSTERED,
    info xml NULL
    DECLARE @roles TABLE
    id int NOT NULL,
    role_name varchar(20) NOT NULL,
    PRIMARY KEY
    id,
    role_name
    /* insert test values */
    INSERT INTO @person (id, info)
    VALUES (1, '<person><name><first_name>Joe</first_name><last_name>Smith</last_name></name></person>'),
    (2, '<person><name><first_name>Tim</first_name><last_name>Jones</last_name></name></person>');
    INSERT INTO @roles (id, role_name)
    VALUES
    (1,'Admin'),
    (1,'User'),
    (2,'Editor'),
    (2,'User');
    /* make sure that xml comes back correctly*/
    SELECT
    role_name AS name
    FROM @roles AS role
    WHERE id = 1 -- works for each id
    FOR XML AUTO, ROOT ('roles');
    UPDATE p
    SET info.modify('insert ???? as last into (/person)[1]')
    FROM @person p
    INNER JOIN @roles r
    ON p.id = r.id
    /* desired output in the info column for id = 1*/
    <person>
    <name>
    <first_name>Joe</first_name>
    <last_name>Smith</last_name>
    </name>
    <roles>
    <role name="Admin" />
    <role name="User" />
    </roles>
    </person>
    Any ideas?

    this?
    DECLARE @person TABLE
    id int NOT NULL PRIMARY KEY CLUSTERED,
    info xml NULL
    DECLARE @roles TABLE
    id int NOT NULL,
    role_name varchar(20) NOT NULL,
    PRIMARY KEY
    id,
    role_name
    /* insert test values */
    INSERT INTO @person (id, info)
    VALUES (1, '<person><name><first_name>Joe</first_name><last_name>Smith</last_name></name></person>'),
    (2, '<person><name><first_name>Tim</first_name><last_name>Jones</last_name></name></person>');
    INSERT INTO @roles (id, role_name)
    VALUES
    (1,'Admin'),
    (1,'User'),
    (2,'Editor'),
    (2,'User');
    /* make sure that xml comes back correctly*/
    SELECT
    role_name AS name
    FROM @roles AS role
    WHERE id = 1 -- works for each id
    FOR XML AUTO, ROOT ('roles');
    UPDATE p
    SET info.modify('insert sql:column("x") as last into (/person)[1]')
    FROM @person p
    CROSS APPLY(SELECT role_name FROM @roles WHERE id = p.id FOR XML PATH(''),ROOT('roles'),TYPE)r(x)
    select * from @person
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to write settings into xml

    I?ve got a small class that returns the names of each JInternalFrame. The code is below; I have an xml file where I am saving various settings. In the xml file I have created a tag and in that tag I want to write all the name of the JInternalFrames. Can someone help me with writing a method which will write the frames names into the xml tag.
    package persisted_display_settings;
    import javax.swing.*;
    import mdi_internal_frame.FrameManager;
    import mdi_internal_frame.TSFrame;
    import state_manager.StateManager.Prerequisite;
    * The PersistDisplaySettings looks after the persisted screen settings for each frame.
    * It allows the user to save the layout settings of each screen so that the user doesn't
    * have to reconfigure layout every time they restart
    public class PersistDisplaySettings {
         * Gets the name of all TS frames and the last modified layout information and saves
         * this in a xml file
         * @param projectDir is the project directory
         public void SaveCurrentTsProfile(String projectDir) {
              System.out.println("Start Here");
              System.out.println(projectDir);
              JInternalFrame[] frames = FrameManager.getJDesktopTS().getAllFrames();
              System.out.println(frames.length);
    // Iterate through each frame that is open and get the names
              // Only get the names of the frames that are saved
              for (int noOfFrames = 0; noOfFrames < frames.length; noOfFrames++) {
                   String tsName = "";
                   boolean unsaved = true;
                   //Check to make sure the frames are TS frames
                   if (frames[noOfFrames] instanceof TSFrame) {        
                        JInternalFrame tsFrames = frames[noOfFrames];
                        if(tsFrames.getTitle().contains(":-")){
                             tsName = tsFrames.getTitle();
                             tsName = tsName.substring(17);
                             unsaved = getSavedTSNames(tsFrames);
                        else if(tsFrames.getTitle().contains("-")){
                             tsName = tsFrames.getTitle();
                             tsName = tsName.substring(16);
                             unsaved = getSavedTSNames(tsFrames);
                        if(!unsaved){
                             System.out.println(tsName);
              System.out.println("point 2");
              FrameManager.getSelectedTSFrame().isMaximum();
              System.out.println(FrameManager.getSelectedTSFrame());
              System.out.println(FrameManager.getSelectedTSFrame().isMaximum());
         * Returns all the saved TS frame names. This method is Called
         * by the SaveCurrentTsProfile method
         * @param save boolean flgg indicating if GUI should save modified test sequences
         public boolean getSavedTSNames(JInternalFrame frame) {
                        boolean[] modified = ((TSFrame)frame).stateManager
                        .getPrereqState(Prerequisite.TS_MODIFIED);
                        return modified[0];     
    }

    I have a GUI project which has frames consisting of data in table view. What i'm trying to do is save the layout of the frames into an xml file so that the user doesn't have to reconfigure layout every time they restart the application. The code which i have attached gets the names of each frame.
    I also have another class which is currently generating various other settings and writing it into the xml file. The xml file looks like this:
    <?xml version="1.0" encoding="UTF-8" ?>
    - <PTMViewProfile>
    - <viewProfile>
    <testSequences />
    - <tsName>
    <tsName tag="arefa" />
    </tsName>
    <tsStatus />
    - <columns>
    - <tcc>
    <column tag="usim" visible="false" width="75" index="-1" />
    <column tag="dev" visible="false" width="75" index="-1" />
    <column tag="tp" visible="false" width="75" index="-1" />
    <column tag="iwd" visible="false" width="75" index="-1" />
    <column tag="tdma" visible="false" width="75" index="-1" />
    <column tag="selref" visible="true" width="75" index="2" />
    <column tag="md" visible="false" width="75" index="-1" />
    <column tag="timer" visible="false" width="75" index="-1" />
    <column tag="description" visible="false" width="75" index="-1" />
    <column tag="name" visible="true" width="120" index="0" />
    <column tag="domain" visible="true" width="75" index="5" />
    <column tag="note" visible="false" width="75" index="-1" />
    <column tag="hsdpa" visible="false" width="75" index="-1" />
    <column tag="wi" visible="true" width="75" index="4" />
    <column tag="ttcn" visible="false" width="75" index="-1" />
    <column tag="approval" visible="false" width="75" index="-1" />
    <column tag="inter" visible="false" width="75" index="-1" />
    <column tag="duration" visible="false" width="75" index="-1" />
    <column tag="etsi" visible="true" width="75" index="1" />
    <column tag="hsupa" visible="false" width="75" index="-1" />
    <column tag="auto" visible="true" width="75" index="3" />
    <column tag="cipher" visible="false" width="75" index="-1" />
    <column tag="suite" visible="false" width="75" index="-1" />
    <column tag="shield" visible="false" width="75" index="-1" />
    <column tag="hop" visible="false" width="75" index="-1" />
    </tcc>
    In the - <tsName> i want to print out all the names of the frames.
    This is the method thats creating the tags in the xml file. This method is stored in a different class;
    public Element writeViewProfile(String name) {
              Message.logInfo("Saving View Profile XML Document:" + name);
              Element root = XMLManager.createNamedElement("PTMViewProfile");
              Element viewProfile = XMLManager.createNamedChildElement(root, xmlViewTag);
              Element tsNameTag = XMLManager.createNamedChildElement(viewProfile, xmlTSFrameTag);
              Element tsFrameName = XMLManager.createNamedChildElement(viewProfile, xmlFrameTag);
              writeTsFrame(tsFrameName, "Arefa");
              Element tsFrameStatus = XMLManager.createNamedChildElement(viewProfile, xmlFrameStatusTag);
              Element columns = XMLManager.createNamedChildElement(viewProfile, xmlColumnsTag);
              writeColumnSet(columns, xmlTCCColumnTag);
              writeColumnSet(columns, xmlTSColumnTag);
              writeColumnSet(columns, xmlResTCCColumnTag);
              writeColumnSet(columns, xmlResTSColumnTag);
              Element sashes = XMLManager.createNamedChildElement(viewProfile, xmlSashesTag);
              for (int i = 0; i < sashList.size(); i++) {
                   writeSash(sashes, sashList.get(i));
              return root;
         };This is the method thats writing the xml file;
    private void saveProfile(String name) {
              if (!readyToSave)
                   return;
              ViewProfile viewProfile = viewProfiles.get(currentViewProfileName);
              if (viewProfile != null) {
                   // try {
                   Element root = viewProfile.writeViewProfile("ptmProfile");
                   // create an xml document with our data
                   Document doc = new Document(root);
                   // dump the document to file
                   XMLManager.dumpXMLDocToFile(doc, "ptmProfile", FileManager.baseDir());
                   // catch (Exception ignore) {
                   // System.out.println(ignore.getMessage() + ignore.getStackTrace());
         }In the xml file how can i print the names of the frames into that <tsName> tag using the SaveCurrentTsProfile() method .
    I hope this helps you understand whats hapenning.
    Thanks!

  • Insert header into xml generated by castor

    I have several classes generated by Castor based on a schema, the xml file should look something like
    <request>
        <type>
            <sentDate>11-25-2006</sentDate>
            <sentTime>18:00:00</sentTime>
            <requestCode>price</requestCode>
        <type>
       <body>
          <content>what is the price of this item?</content>
       </body>   
    </request>now, I want to generate an other xml file based on this one, the only difference would be a header would be inserted such that
    <request>
        <header>
           <requestor>jane smith</requestor>
           <id>1234</id>
        </header>
        <type>
            <sentDate>11-25-2006</sentDate>
            <sentTime>18:00:00</sentTime>
            <requestCode>price</requestCode>
        <type>
       <body>
          <content>what is the price of this item?</content>
       </body>   
    </request>how can I make user of the existing objects and simply "insert" this header? Thanks!

    ms.arora wrote:
    I'm using castor-1.1.2.1.tar to generate XML from Java POJO. The resulting XML, however, is not well formed with the entire XML being outputted to the single line.What's wrong with that? As long as it contains all the information from the POJO, why do you care if it isn't pretty-printed? It's not meant for people to read anyway.
    Apart from this, currency symbols in the POJO are not rendered incorrectly in the XML.I expect you mean they are rendered incorrectly. My crystal ball also tells me that the XML is encoded in UTF-8 and you are looking at it with a text editor that doesn't understand that. But it could be wrong, it doesn't work very well.

  • How to fetch data into xml file trom sql table.

    Hi,
    We r now working in oracle 9iAS portal.
    We have installed xdk along with 9iAS.
    I would like to know how to and where to run an xsql file,preferably with an example to fetch data from a database table to a xml file.

    Please download the latest version of XDK for Java at:
    http://otn.oracle.com/tech/xml/xdk_java
    In the downloaded package, there are demos for XSQL Servlet. The demo "emp" and "empdept" are good start.

  • How to attach database into .exe windows application Vs 2013 Sql 2014

     i am developing a windows application project using C# ,  sql 2014 and VS 2013.
    now i want to run the application in other computers ( visual studio and MS sql server are not installed in
    these client computers).
    i can run the applications interface bu taking the .exe file inside bin. But i cannot run it properly b/c the
    database is not there.
    i have tried InstallerShiled and in every time my application can't connect with the database in other pc 

    As your question is about application deployment/data access, and not about .NET Framework setup (this forum's topic), I'll suggest two possible forums for you because your issue crosses over two topics.
    For application deployment:
    https://social.msdn.microsoft.com/Forums/en-US/winformssetup/threads
    For database issues:
    https://social.msdn.microsoft.com/Forums/en-US/vstsdb/threads
    I believe you'll get good suggestions in either forum.

  • 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 attach files in the SMTP mail?

    Hi All
    Anyone know how to how to attach files into the mail configured
    with SMTP while changing the workstatus. The SMTP mail is working
    fine, but my requirement is to attach a file which is having static information
    like instructions for users or something like that.
    Please help me on this..
    My Version of BPC is MS 7.X
    Regards,
    Baijuchandran.B

    Have you seen this thread? Not an elegant solution, but it appears to work for some bizarre reason.
    https://community.bt.com/t5/Email/Email-won-t-accept-attachments-error-18-temporary-It-isn-t/td-p/14...

  • How to attach image in BPM CustomJSP and view it

    Hello everyone im new here ,
    Is there any tutorial how to attach file into BPM Object ?
    Im using Oracle BPM Studio 10.3.1
    I have seen many tutorial how to attach file into BPM using fileChooser
    ( https://community.oracle.com/thread/880712  )
    and succeed but my next problem is how to show image that i have been uploaded before
    Thaaanks
    Regards
    Shiddiq

    Hi Shiddiq,
    You can get access to an uploaded file using the execData object.
    For example, you can use execData.attachment[1].name to retrieve the file name of your first attachment.
    Similartly use execData.attachment[1].contents to retrieve you first file contents in a base64 format.
    Antonis

  • How to attach a file in soap

    How to attach a text/xml filel in soap response. can any body explain in detail about this.

    Probably MTOM is what you need:
    http://edocs.bea.com/wls/docs100/webserv/jws.html#mtom
    But this is apparently not doable with ALSB (it would be supported just with regular web services):
    http://forums.bea.com/thread.jspa?threadID=300002302
    Note the file naming would need to be done by the SOAP client:
    http://www.jroller.com/gmazza/date/20071102 (Look at Steps #6 and #11 and Note # 7)
    HTH,
    Glen

  • Convert string into XML inside BPEL

    Hello ,
    How to convert string into xml format ? And make element and define attribute inside it ??

    There are several problems with your input:
    1. Your xml is not well-formed because the attribute values should be enclosed withing double " quotes and not single ' quotes;
    2. You use a prefix (sml) for the folowing part but you dont define the namespace:
    <ids>
    <VID ID="new"/>
    <data>
    <*sml:*attr name="std">
    <sml:value></sml:value>
    </sml:attr>
    <sml:attr name="xde">
    <sml:value></sml:value>
    </sml:attr>
    </data>
    </ids>
    Complete message should be:
    <ids xmlns:sml="somenamespace">
    <VID ID="new"/>
    <data>
    <sml:attr name="std">
    <sml:value></sml:value>
    </sml:attr>
    <sml:attr name="xde">
    <sml:value></sml:value>
    </sml:attr>
    </data>
    </ids>
    3. Do you assign this expression to a variable that is based on the schema of your message you want to parse
    Regards,
    Melvin
    * TIP Answer the question as helpful or correct if it helps you , so that someone else will be knowing that this solution helped you or worked for you and also it gives points to the person who answers the question. *

Maybe you are looking for

  • Lsmw Idoc  ......

    Hi friends,   I am working on LSMW Idoc ....after uploading the data ...The idoc got created with 53 staus successfully .   after succesfull creation Of Idoc , when i check the data in the database  its not going to updating the data base. is there a

  • LOST file sharing  with Leopard update

    BIg bummer: after Leopard update from OS 5.4.11, I lost file sharing on ethernet to my G4 (running OS 9.2.2). It was so easy to set up and access the G4 on Tiger. Now it's impossible. HELP HELP

  • Reg: MRP Run for all Materials

    Hi Abapers, I have an issue where in using MD01( Material Run), i need to raise one PR for all materials below the re-order stock. Currently system creates one PR for each material below the re-order stock. Please throw any ideas regarding this. Than

  • The max numbers of cheques shown on cheque stub

    Hi, I found that the maximum number of cheques that were shown on one cheque stub is five. Does anyone know how to print more than five cheuqe lines on one cheuqe stub? Thanks. Angela

  • Certain characters "glitch" in urxvt

    This has bothered me before. It seemed to go away at some point, but now it has come back: I'm using rxvt-unicode and the Consolas font, and the "w" character (and only ever the "w" character) is shown like this: If you can't see the picture, try her