How to create new XML file using retreived XML content by using SAX API?

hi all,
* How to create new XML file using retreived XML content by using SAX ?
* I have tried my level best, but output is coming invalid format, my code is follows,
XMLFileParser.java class :-
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.XMLFilterImpl;
public class PdfParser extends XMLFilterImpl {
    private TransformerHandler handler;
    Document meta_data;
    private StringWriter meta_data_text = new StringWriter();
    public void startDocument() throws SAXException {
    void startValidation() throws SAXException {
        StreamResult streamResult = new StreamResult(meta_data_text);
        SAXTransformerFactory factory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
        try
            handler = factory.newTransformerHandler();
            Transformer transformer = handler.getTransformer();
            transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            handler.setResult(streamResult);
            handler.startDocument();
        catch (TransformerConfigurationException tce)
            System.out.println("Error during the parse :"+ tce.getMessageAndLocation());
        super.startDocument();
    public void startElement(String namespaceURI, String localName,
            String qualifiedName, Attributes atts) throws SAXException {
        handler.startElement(namespaceURI, localName, qualifiedName, atts);
        super.startElement(namespaceURI, localName, qualifiedName, atts);
    public void characters(char[] text, int start, int length)
            throws SAXException {
        handler.characters(text, start, length);
        super.characters(text, start, length);
    public void endElement(String namespaceURI, String localName,
            String qualifiedName) throws SAXException {
        super.endElement("", localName, qualifiedName);
        handler.endElement("", localName, qualifiedName);
    public void endDocument() throws SAXException {
    void endValidation() throws SAXException {
        handler.endDocument();
        try {
            TransformerFactory transfactory = TransformerFactory.newInstance();
            Transformer trans = transfactory.newTransformer();
            SAXSource sax_source = new SAXSource(new InputSource(new StringReader(meta_data_text.toString())));
            DOMResult dom_result = new DOMResult();
            trans.transform(sax_source, dom_result);
            meta_data = (Document) dom_result.getNode();
            System.out.println(meta_data_text);
        catch (TransformerConfigurationException tce) {
            System.out.println("Error occurs during the parse :"+ tce.getMessageAndLocation());
        catch (TransformerException te) {
            System.out.println("Error in result transformation :"+ te.getMessageAndLocation());
} CreateXMLFile.java class :-
Sax.startDocument();
Sax.startValidation();
Sax.startElement("", "pdf", "pdf", new AttributesImpl());
Sax.startElement("", "basic-metadata", "basic-metadata", new AttributesImpl());          
String xmp_str = new String(meta_data.getByteArray(),"UTF8");
char[] xmp_arr = xmp_str.toCharArray();
Sax.characters(xmp_arr, 0, xmp_arr.length);
Sax.endElement("", "pdf", "pdf");
Sax.endValidation();
Sax.endDocument();
Sax.endElement("", "basic-metadata", "basic-metadata");* In CreateXMLFile.java
class, I have retreived the xml content in the meta_data object, after that i have converted into character array and this will be sends to SAX
* In this case , the XML file created successfully but the retreived XML content added as an text in between basic-metadata Element, that is, retreived XML content
is not an XML type text, it just an Normal text Why that ?
* Please help me what is the problem in my code?
Cheers,
JavaImran

Sax.startDocument();
Sax.startValidation();
Sax.startElement("", "pdf", "pdf", new AttributesImpl());
Sax.startElement("", "basic-metadata", "basic-metadata", new AttributesImpl());          
String xmp_str = new String(meta_data.getByteArray(),"UTF8");
char[] xmp_arr = xmp_str.toCharArray();
Sax.characters(xmp_arr, 0, xmp_arr.length);
</code><code>Sax.endElement("", "basic-metadata", "basic-metadata");</code>
<code class="jive-code jive-java">Sax.endElement("", "pdf", "pdf");
Sax.endValidation();
Sax.endDocument();     
* I HAVE CHANGED MY AS PER YOUR SUGGESTION, NOW SAME RESULT HAS COMING.
* I AM NOT ABLE TO GET THE EXACT OUTPUT.,WHY THAT ?
Thanks,
JavaImran{code}

Similar Messages

  • How to create new .dat file and its contents?

    Hi There
    Can anybody let me know the procedure of how to create new .ctl or .dat file to load data to tables.
    i working on 2day dba chapter 8. it shows me how to creat table and use .dat file to load data. but doesnot giv any clue how new .dat file and its contents can be created. please help.
    thanks in advance.

    Thanks for ur help
    I ve created txt file in notepad and saved it as dat file. tried to load that data thru Enterprise manager. used load data from User files everything went well and job was showing suceeded but dont know why that data is not showing in the table. i ve tried it now for three four times. used right table and pathe but dont know. has anybody got idea why that ll be?
    Thanks

  • How to create a flat file without any xml tags in PI 7.0

    Hi
    I would like to take the content of the tiff-tag and map it to a file, which content is the value of the tiff-tag. How do I do that?
    source:
    <sourcexml>
       <tiff>dhlflfhlfhjhfjhfakjhfkjhfkjhfahflkhflahfalhfalhfldhflkahflak</tiff>
    </sourcexml>
    resulting content of file:
    "dhlflfhlfhjhfjhfakjhfkjhfkjhfahflkhflahfalhfalhfldhflkahflak"
    The point is, the the resulting file should not contain any xml tags but only the plain value of the tiff tag in the source document.
    Do I need to specify something in the receiver file adapter?
    tiff is an image format.
    BR
    Mikael

    Hi
    after the mapping and thus as input to the File receiver  CC the message looks like this:
    <?xml version="1.0" encoding="UTF-8" ?>
    - <ns0:blob xmlns:ns0="http://dongenergy.dk/pi/zztest/milun">
      <indhold>tiffog dadada</indhold>
      </ns0:blob>
    Recordset Structure is set to "indhold,1"
    and the "lines" are
    indhold.addHeaderLine  = 0
    indhold.fieldSeparator = 'nl'
    A file is created but it is empty.
    Mikael

  • How to create a java file from an xml file

    anybody who can help me? i'm really trying to get this job in a hurry..thanks

    wondering if velocity template engine can help.
    a. parse XML
    b. construct bean (will XMLBeans help?)
    c. write java files (velocity may have helped here) from predefined template.
    Looking forward to other suitable solution.
    JSP to servlet is, I guess, such example.

  • How to create new playlist. File option greyed out

    The create playlist option is greyed out in the File menu. How do I create I new playlist? What is wrong with the new version?

    Hi;
    How to create new alertlog file. Does it require the DB bounce?Oracle will automatically create a new alert log file whenever the old one is deleted and you dont need to bounce db
    For details see:
    http://orafaq.com/wiki/Alert.log
    Regard
    Helios

  • How to create a text file or XML file  and add content through  code into it...

    Hi Everyone,
    How to create a text file and add content through the code to the text file eform javascript ......orelse can we create a text file in life cycle designer...
    Else say how to create a new XML file through the code and how some content like Example "Hello World".

    You can create a text file as a file attachment (data object) using the doc.createDataObject and doc.setDataObjectContents:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.450.html
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.528.html
    You can then export the file with the doc.exportDataObject method:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.463.html
    This won't work with Reader if it hasn't been given the file attachment usage right with LiveCycle Reader Extensions.

  • How do you create an xsd file for an xml schema in BI Publisher?

    Helllo.
    I hope this is a really daft question for somebody..
    How I create an xsd file to be used as an xml schema to attach to a Data Definition that Ive created? I've obv. got the xml and rtf files ready and attached. I've looked through the relevant docs (XML Publisher Report Designer's Guide.pdf & XML Publisher Administration and Developer's Guide.pdf) but can't find where..
    Once this has been done then I can run the template via ORACLE Financials for the reports I've converted.
    many thanks..
    Steven

    I don't think you need to have an XSD it's an optional field. If you really want to create one use this site: http://www.hitsw.com/xml_utilites/
    I believe I answered your question, don't forget to give me the points.
    Ike Wiggins
    http://bipublisher.blogspot.com

  • How to create the log file in remote system using log4j.

    Hi,
    How to create the log file in remote system using log4j. please give me a sample code or related links.The below example i used for create the log file in remote system but it return the below exception.Is there any authandication parameter for accessing the remote path? Please help.
    public class Logging
    Logger log=null;
    FileAppender fileapp=null;
    public Logging(String classname)
    try
    log = Logger.getLogger(classname);
    String path=" [\\192.168.0.14\\c$\\LOG\\d9\\May_08_2008_log.txt|file://\\192.168.0.14\\c$\\LOG\\d9\\May_08_2008_log.txt]";
    fileapp = new FileAppender(new PatternLayout("%r [%t] %-5p %c %x - %m%n"),path, true);
    log.addAppender(fileapp);
    log.info("Logger initilized");
    }catch(Exception ex)
    ex.printStackTrace();
    java.io.FileNotFoundException: \\192.168.0.14\c$\LOG\d9\May_08_2008_log.txt (The network path was not found)
    at java.io.FileOutputStream.openAppend(Native Method)
    at java.io.FileOutputStream.<init>(Unknown Source)
    at java.io.FileOutputStream.<init>(Unknown Source)
    at org.apache.log4j.FileAppender.setFile(FileAppender.java:290)
    at org.apache.log4j.FileAppender.<init>(FileAppender.java:109)
    at annwyn.logger.BioCapLogger.<init>(Logging.java:23)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Please help.
    Thanks in advance.
    Saravanan.K

    Sorry path is missing for the above request.
    path="\\192.168.0.14\c$\LOG\d9\May_08_2008_log.txt ";
    please help.
    Saravanan.K

  • How to transfer multi-input xml file to One xml file using BPM?

    Hi!
    Using BPM, We wana transfer multiful xml file to One xml at Remote FTP Server.
    I don't know how to design BPM.
    ============== samle1: input xml====================
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE Shipments SYSTEM "DTD/Shipment.dtd">
    <Shipments>
      <sendingPartnerID>XXX</sendingPartnerID>
      <receivingPartnerID>XXX_UPSTMS</receivingPartnerID>
      <receivingMessageType>TPSDLS</receivingMessageType>
      <Shipment ID="0081646547" Type="CREATE">
        <CustomerID>XXX</CustomerID>
      </Shipment>
    </Shipments>
    ============== samle2: output xml====================
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE Shipments SYSTEM "DTD/Shipment.dtd">
    <Shipments>
      <sendingPartnerID>XXX</sendingPartnerID>
      <receivingPartnerID>XXX_UPSTMS</receivingPartnerID>
      <receivingMessageType>TPSDLS</receivingMessageType>
      <Shipment ID="0081646547" Type="CREATE">
      </Shipment>
      <Shipment ID="0081886548" Type="CREATE">
      </Shipment>
      <Shipment ID="0081646999" Type="CREATE">
      </Shipment>
    </Shipments>
    Message was edited by: ChangSeop Song

    Hi,
    To convert multiple xml files into a single file, you will have to perform a N:1 mapping.
    The following tutorials are available on SAP to help you understand BPM and also to collect multiple XML messages so that they can be mapped into a single message. Check them out,
    http://help.sap.com/saphelp_nw04/helpdata/en/08/16163ff8519a06e10000000a114084/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/08/16163ff8519a06e10000000a114084/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/14/80243b4a66ae0ce10000000a11402f/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/14/80243b4a66ae0ce10000000a11402f/frameset.htm
    Regards,
    Bhavesh

  • HOw to create a Batch file for java application and whats the use of this ?

    HI,
    How to create a Batch file for java application ?
    And whats the use of creating batch file ?
    Thanks in advance

    First of all, you're OT.
    Second, you can find this everywhere in the net.
    If you got a manifest declaring main class (an classpath if needed), just create a file named whatever.bat, within same directory of jar file, containing:
    javaw -jar ./WhateverTheNameOfYourJarIs.jar %*By the way, assuming a Windows OS, you can just double click the jar file (no batch is needed).
    Otherwise use:
    javaw -cp listOfJarsAndDirectoriesSeparedBySemiColon country/company/application/package/className %*Where 'country/company/application/package/' just stands for a package path using '/' as separator instead of '.'
    Don't specify the .class extension.
    Javaw only works on Windows (you asked for batch, I assumed .BAT, no .sh), in Linux please use java.exe (path may be needed, Windows doesn't need it 'cause java's executables are copied to system32 folder in order to be always available, see PATH environment variable if you don't know what I'm talking about) and use ':' as classpath (cp) separator.
    The '%***' tail is there in order to pass all parameters, it only works on Windows, refer to your shell docs for other OSs (something like $* may work).
    This way you have a command you can call to launch your code (instead of opening NetBeans just to see your app working). You could schedule tasks on it or just call it in any command prompt (hope you know what it is 'cause there have been people in this very same forum with no clue about it, if not just hold the 'Windows button' and press 'R', then type 'cmd' and run it).
    Finally add dukes and give 'hem away.
    Bye.

  • How can I add a "Create New Text File" contextual menu?

    Hi,
    I'd like to add a "Create New Text File" contextual item. I found the "new text file" action in Automator, but I don't really know where to go from there... I want it to work on the desktop and in finder...
    Thanks

    See:
    Mac OS X Automation,
    Automated Workflow Tips,
    Introduction to Automator tutorial, and
    a four-parter on Automation in Snow Leopard by Sal Saghoian:
    Snow Leopard Services,
    Services for iPhoto,
    Safari and WebKit integration, and
    Installing and using services.
    Finally, 
    Developing AppleScript Applications and
    Apple's Automator Developer Documentation

  • How to create a flat files and how i used this

    hi Guys and gals,
    I am david. I want to know how to create a flat files. I don't know about it also. pls explain it and also pls help me to create a flat files. If u have any program for creating pls send me.
    I want to know about retrive the datas from flat files and also insert a record into it.
    pls guide me
    i need this immediately
    david

    void newMethod() throws Exception {
         // Reading from a flat file
         String data;     
         BufferedReader br = new BufferedReader(new FileReader("c:\filename1.txt"));
         while ((data = br.readLine()) != null) {
              System.out.println(data);
         // Writing to a flat file
         BufferedWriter bw = new BufferedWriter(new FileWriter("c:\filename2.txt"));
         bw.write("sample data");
         // After writing the data close the file
         bw.close();
    }

  • How to create a report from multiple dynamic XMLs

    Hi,
    I'm trying to build a consolidated report that gets data from multiple XML files and each XML file is different. Although the presentation of the data will be similar, the contents of the XMLs will vary and the number of XMLs to merge will also vary.
    What I would like to understand is the following:
    * Is it possible to generate a report template based on dynamic columns where the column names, their format and number is different for each business object?
    * Is it required to generate an XML with the entire data or can the template read information from different XML files? and if so how it can be done. Please notice that the formatting of each XML may be different.
    * Is it possible to use the services to generate the reports directly? Something around these lines was mentioned in one of the sessions but it was also mentioned that it's still WIP.
    I've been using the standalone version and although I can get the desired result, I couldn't merge data from multiple XMLs.
    Is the new BIP version available, or an enterprise version that I can use?
    Thanks in advance,

    Hi Rich,
    Even i had a similar kind of problem. I wanted to fetch data from BI through the XMLA Connector which are created in Query Designer and then i wanted to fetch these fields and rearrange them and put it in a report format by colouring certain fields. Can the same can be done in WebDynpro.

  • How to create new page in wlp in runtime

    hi,
    How to create portal pages in run time (not at the admin console) give an option to the end users to create pages and configure it.
    Thanks
    Manu

    Hi Manu
    1) Can we entitle the page created to display to some users.
    You mean the "Page(s)" created by the End User when he clicks on Customize link. If so, note that this page will be available ONLY to that user. There is no other special entitlements to be assigned to. Because every user who customizes desktop will have his own set of Books/Pages/Portlets in the backend Portal Database schema. BUT if you want to set Entitlements to the Pages created by the Adminstrator, then YES, you can always set Entitlements to that Page, so that only specific set of Users, Roles (users belong toRoles) can access those Pages.
    2) Can we change the hyperlink of the page to some other external page.
    I am not clear with this question. When we create a Page from WorkshopIDE or Portal Admin Console or through DVT, first thing is, this page will have a unique page definition label. Now assume this page is part of some Book. So When this portal (or deskop) is rendered, Portal Framework Look and Feel files, will iterate through list of all Books and for each Book list of all Pages and construct the Menu(s) which are nohting but Hyperlinks. During this process, the hyperlink will be appended with the definition labels of each Page etc which is retrieved from Database (or .portal xml file incase of filemode). So you cannot change the hyperlink to point to someother page. Worst case, if you really want, then you need to modify the portal framework menu rendering code, to change the urls for specific page. Say PageA should be reidrected to PageB. So in your custom menu rendering code, when you hit the PageA, there check for page def label of PageA and if it matches, then add a different page def label say for PageB definition label. This is complex, but can be achieved. But my very first question is why do you want to do this and what is your exact usecase.
    Note that you can always generate dynamically Links for any Portal Pages using render url tags or APIs (PostbackURL, GenericURL etc). You can have this kind of code in any JSP or Pageflows.
    PostbackURL homeURL = PostbackURL.createPostbackURL(request, response);
    homeURL.addParameter(PostbackURL.PAGE_LABEL_PARAM, "page_card_services_1"); //page_card_services_1 is a page def label of some other page that I want to redirect to
    3) Can we integrate the page creation to the BPEL workflow.
    BPEL Workflow is nothing but a WebServices. Using CustomCode, this may be possible. One way I can think of is like this. First you need to have code/logic in some Pageflow or utility class to call BPEL Workflow. As mentioned first you need to create a WebServices client JAR for this BPEL WebServices. Then add this jar to the web-content/web-inf/lib folder. Then in pageflow or utility class, get the Service, Port and invoke process method on this BPEL and pass some input parameters. Now BPEL will do some internal processing and will return the page definition labels in the response XML object based on input parameters. Then in the Pagelfow or utility class, from this response object, extract page def label and use the above code snippet to redirect to that page. This should work.
    4) is there a way allow users to create new portlets from ucm and add content to the portlets.
    When we allow customization for end users, usually they can choose from list of Look and Feels, create or edit Books/Pages. They cannot create Brand New Portlets. From existing list of Portlets, they can add or remove them from any Page. NOW, if you use latest WLP 10.3.2, you can consume WebCenter ADF Portlets using WSRP. Also I guess there is a plug in for UCM with WLP 10.3.2. I did not work in this area so do not have full details. But assume that you already have some UCM Portlets integrated into your portal application by adminstrator. Then End User can choose to add these UCM Portlets to the pages that he cretaes. NOW coming to the content of the Portlets, this is something you can handle through Portlet Preferences. Considerr default out of box WLP original pageflow portlets. You can have some search criteria in a content portlet. This search criteria can be modified using Edit icon ie. Portlet Preferences. So user can customize the search criteria and get the results he is interested in.
    Thanks
    Ravi Jegga

  • How to Create MultiSheet Excel Report Output in XML Publisher in Oracle R12

    Dear All,
    How to Create MultiSheet Excel Report Output in XML Publisher in Oracle R12.
    My Requirement is to develop RTF Template and geneate Excel output in Multiple sheet.
    plz guide me on this..
    thnx
    Khushal

    plz see
    BI Publisher: How to create Multisheet in Single Excel file using Excel Template [ID 1352000.1]
    for r12 you can use excel template
    i think it more appropriate for excel output

Maybe you are looking for