Conversion from xml to csv using xsl

hi i am converting from xml to csv using xsl i am getting the extra junk character(space) in the csv file.below i written the xml file and xsl file
xml file
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl"?>
<DOCUMENTS>
     <FILE>
     <DOCUMENT>
          <BUSINESS>finance</BUSINESS>
          <PROGRAM>CM</PROGRAM>
          <PROJECT>Testing Area</PROJECT>
          <NAME>121940~1.doc</NAME>
          <TEXT>SQL</TEXT>
          <LINK>http://www.sql.org/</LINK>
     </DOCUMENT>
     <DOCUMENT>
          <BUSINESS>finance</BUSINESS>
          <PROGRAM>CM</PROGRAM>
          <PROJECT>Testing Area</PROJECT>
          <NAME>121940~1.doc</NAME>
          <TEXT>Information</TEXT>
          <LINK>http://google.com/</LINK>
     </DOCUMENT>
     <DOCUMENT>
          <BUSINESS>finance</BUSINESS>
          <PROGRAM>CM</PROGRAM>
          <PROJECT>Testing Area</PROJECT>
          <NAME>121940~1.doc</NAME>
          <TEXT>Configuration</TEXT>
          <LINK>http://msdn.microsoft.com/</LINK>
     </DOCUMENT>
     </FILE>
</DOCUMENTS>
xsl file
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" indent="yes"/>
<xsl:template match="DOCUMENTS">
<xsl:text>Business,Program,Project,DocumentName,Textforlink,Hyperlink</xsl:text>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="FILE">
<xsl:value-of select="DOCUMENT/BUSINESS"/>
<xsl:value-of select="','"/>
<xsl:value-of select="DOCUMENT/PROGRAM"/>
<xsl:value-of select="','"/>
<xsl:value-of select="DOCUMENT/PROJECT"/>
<xsl:value-of select="','"/>
<xsl:value-of select="DOCUMENT/NAME"/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="DOCUMENT">
<xsl:value-of select="','"/>
<xsl:value-of select="','"/>
<xsl:value-of select="','"/>
<xsl:value-of select="','"/>
<xsl:value-of select="TEXT"/>
<xsl:value-of select="','"/>
<xsl:value-of select="LINK"/>
</xsl:template>
</xsl:stylesheet>
for converting to csv i am using java program.
please go through it.

<xsl:value-of select="','"/>That's not the correct way to output a literal comma. Just write the comma directly, or use xsl:text. And don't put in those line breaks either. You can reduce the rule for FILE to something like this:
xsl:template match="FILE">
<xsl:value-of select="DOCUMENT/BUSINESS"/>, <xsl:value-of select="DOCUMENT/PROGRAM"/>, <xsl:value-of select="DOCUMENT/PROJECT"/>, <xsl:value-of select="DOCUMENT/NAME"/>
<xsl:apply-templates/>
</xsl:template>

Similar Messages

  • Problem in file content conversion from XML to CSV

    Hi Experts,
    I am finding problem in file content conversion. I need to convert the following XML file into CSV file:
      <?xml version="1.0" encoding="UTF-8" ?>
    - <ns0:MT_CROSS_REF xmlns:ns0="urn:dabur:idoc2file:pos">
          <Update_type>2</Update_type>
          <PLU>00000000</PLU>
          <Cross_ref_PLU>7777777</Cross_ref_PLU>
          <Capture_PLU />
          <Package_size />
          <Package_desc />
      </ns0:MT_CROSS_REF>
    The output file data has to be like:
    2,00000000,7777777,,,,
    The problem I am facing is while specifying the content conversion parameters in communication channel i dont know what recordset structure i should mention as all the records are directly under root. If I mention recordset structure as "ns0:MT_CROSS_REF" and parameters as
    ns0:MT_CROSS_REF.fieldSeparator   ,
    ns0:MT_CROSS_REF.endSeparator    'nl'
    i get error in communication channel monitoring and no file is posted.
    Please help me as to what correct parameter i should mention in my case.
    Thanks,
    Regards,
    Yash

    Hi Chirag,
    I cannot change the xml file as it comes after mapping idoc to a message type. How can I add ROOT in the xml? My message type is like MT_CROSS_REF and it has those 6 fields as in the XML (Update_type, PLU etc.). I do the mapping of these fields from a IDOC and get the XML.
    I hope you got my point.
    Thanks,
    Yash

  • Creating an XML From a Deep Structure  using XSL Transformation

    Hi ABAPers,
    I have a requirement to use XSL Transformations on an ABAP deep type structure.
    Currently i have an API that fills in this deep structure and by using CALL TRANSFORMATION ID.... i will get the BIG XML having having 100s of nodes . But actualy form the deep structure i need only some NODES (say 50)... So i tried writing an XSLT
    in the transaction STRANS.. but on using this TRANSFORMATION which i wrote i am getting an error messgae like INVALID XML...
    Am i going in right track or is there a good solution...
    My sample transformation is as below...
    <xsl:transform version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:strip-space elements="*"/>
    <xsl:template match="/">
    <xsl:value-of select="DATA/NODE_ELEMENTS/UUID_KEY/UUID"/>
    <xsl:value-of select="DATA/NODE_ELEMENTS/SEMANTICAL_NAME"/>
    <xsl:value-of select="DATA/NODE_ELEMENTS/STRUCT_CAT"/>
    <xsl:value-of select="DATA/NODE_ELEMENTS/USAGE_CAT"/>
    <xsl:value-of select="DATA/NODE_ELEMENTS/RESTRICTED_IND"/>
    <xsl:value-of select="VALUES/DATA/NODE_ID"/>.
    </xsl:template>
    </xsl:transform>
    Please help me in solving this issue....
    Thanks,
    Linda.

    Hi Linda,
        I am replying based on your sample code.
       Try the below following suggestions.
       here 'GRPHDR' is the node where I am selecting the data.
               IGRPHDR is the name of the reference.
    First calling the transformation in you program.
    TYPES: BEGIN OF tl_hdr,
               msgid(20)    TYPE c,
                 END OF tl_hdr.
    DATA : t_hdr           TYPE STANDARD TABLE OF tl_hdr.
      GET REFERENCE OF t_hdr INTO l_result_xml-value.
        l_result_xml-name = 'IGRPHDR'.
        APPEND l_result_xml TO t_result_xml.
       TRY.
            CALL TRANSFORMATION yfi_xml_read
            SOURCE XML it_xml_data
            RESULT (t_result_xml).
          CATCH cx_root INTO l_rif_ex.
            l_var_text = l_rif_ex->get_text( ).
            l_bapiret-type = 'E'.
            l_bapiret-message = l_var_text.
            APPEND l_bapiret TO errormsgs.
            EXIT.
        ENDTRY.
    in XSL transformation
       First write a block of statement to specify from which node you are taking the data.
       No matter it is a node or sub-node.
    <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <xsl:output encoding="iso-8859-1" indent="yes" method="xml" version="1.0"/>
      <xsl:strip-space elements="*"/>
    <xsl:template match="/">
          <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
          <asx:values>
            <IGRPHDR>  " reference name of internal table
              <xsl:apply-templates select="//GrpHdr"/>
            </IGRPHDR>
      </asx:values>
        </asx:abap>
    </xsl:template>
    Next select the data from the nodes under the nodes specified in the transformation.
    here msgid is the field i am selecting for value.
    <xsl:template match="GrpHdr">
        <item>
          <MSGID>  " field in the internal table t_hdr where data has to go
            <xsl:value-of select="MsgId"/>
          </MSGID>
        </item>
      </xsl:template>
    reply back if further clarification is needed.
    Thanks and regards,
    Kannan N

  • How to ignore prefix from XML while converting XML to csv using XSLT

    Hi All,
    I am trying to convert XML to csv file.
    the XML i have is like....
    <?xml version="1.0"?>
    <bulkCmConfigDataFile xmlns:es="SpecificAttributes.3.0.xsd" xmlns:un="utranNrm.xsd" xmlns:xn="genericNrm.xsd" xmlns:gn="geranNrm.xsd" xmlns="configData.xsd">
    <configData dnPrefix="Undefined">
            <xn:SubNetwork id="AU_R">
                <xn:SubNetwork id="H5RG_0501">
                    <xn:MeContext id="Firle_5070020">
                        <xn:ManagedElement id="1">
                   <un:RncFunction id="1">
                   <un:UtranCell id="50390303">
                                    <un:attributes>
                                        <un:userLabel>UtranCell 50390303</un:userLabel>
                                        <un:cId>52383</un:cId>
                                        <un:localCellId>50390303</un:localCellId>
                                        <un:uarfcnUl>9613</un:uarfcnUl>
                                        <un:uarfcnDl>10563</un:uarfcnDl>
                                        <un:primaryScramblingCode>502</un:primaryScramblingCode>
                                        <un:primaryCpichPower>287</un:primaryCpichPower>
                                        <un:maximumTransmissionPower>403</un:maximumTransmissionPower>
                                        <un:primarySchPower>-18</un:primarySchPower>
                                        <un:secondarySchPower>-20</un:secondarySchPower>
                                        <un:bchPower>-20</un:bchPower>
                                        <un:lac>50301</un:lac>
                                        <un:rac>1</un:rac>
                                        <un:sac>52383</un:sac>
                                        <un:utranCellIubLink>SubNetwork=AU_R,SubNetwork=H5RG_0501,MeContext=H5RG_0501,ManagedElement=1,RncFunction=1,IubLink=5039030</un:utranCellIubLink>
                                    </un:attributes>
                                </un:UtranCell>     
                   </un:RncFunction>
                        </xn:ManagedElement>   
                    </xn:MeContext>
             </xn:SubNetwork>
            </xn:SubNetwork>
        </configData>
    </bulkCmConfigDataFile>now when i am using XSLT functionality to convert this XML into a csv i want ignore all the prefix from this xml like "un" , "xn" etc....
    can anybody has idea how i can ignore all this value using XSLT

    I just dont understand why factory.setIgnoringElementContentWhitespace(true) did not work.That only does something if the XML has a DTD that enables it to know what whitespace can be ignored and what is significant. The API documentation for the method refers you to this document:
    http://www.w3.org/TR/REC-xml#sec-white-space

  • File conversion from text to CSV on present server without using GUI FM

    Hi Folks,
    This question may sound a bit weired but here it is. I have to convert a text file to csv using a SAP ABAP Report.
    The file is located on the presentation server and I am using FM's <b>GUI upload</b> and <b>GUI download</b> to do the same as the number of fields change and we perform some operations on the data coming from the text file. Actually, the csv file is supposed to act as a source system for SAP BI.
    Now my question is is there any other way by which we can do it without using the above function modules.
    Thanks
    Varun

    Hi,
    You upload the Text file using GUI_UPLOAD and now you will have the records in the internal table and then use GUI_DOWNLOAD to download the file in CSV format.
    Thanks
    PK

  • Help-XML report which uses XSL-FO and XSL-FO contains OAF VO

    Hello All,
    I want to know functionality of one XML report developed by Oracle.
    From one oracle form after clicking one button, it is populating PDF file output of report to open.
    Here is what Oracle has done to achieve this:
    On the click of button on oracle form, it is calling one OAF form. (fnd_function.execute(function_name=> 'ONT_PRINT').
    This OAF form contains nothing on its layout. One CO (File is attached) and AM is attached to this OAF page.
    In CO, may be it is somehow it is calling RTF file.
    I got the RTF file from XML publisher, RTF imports one XSL-FO (ONTBSAEXSL is a Template of XSL-FO type in Oracle apps in XMP Publisher administrator responsibility) file using <?import:xdo://ONT.ONTBSAEXSL.en.00/?>
    In the XSL file, OAF View Objects has been used like,
    <xsl:variable name="LinesVO" select="/*/HeaderVO/HeaderVORow/LinesVO/LinesVORow"/>
    What is the meaning of " /*/HeaderVO/HeaderVORow/LinesVO "? Does it mean LinesVO is getting called by HeadersVO. But in OAF this never happens.
    I want to add some columns in the RTF from LinesVO. But "Unit price" is not available in LinesVO.
    Do I need to extend this VO in JDeveloper and upload the .JPX and extended VO files?
    I have done extending the VO, but no use..
    So,
    In short my question is,
    If I extend the VO LinesVO by XXLinesVO, then will this <xsl:variable name="LinesVO" select="/*/HeaderVO/HeaderVORow/LinesVO/LinesVORow"/>
    statement in XSL-FO use my XXLinesVO or LinesVO?
    Regards,
    Parag

    I want to customize one RTF template by adding some columns. This RTF imports one XSL-FO stylesheet.
    RTF has tags like <?for-each:/*/HeaderVO/HeaderVORow/LinesVO/LinesVORow?>
    and XSL file has tags like <xsl:variable name="InternalOrgName" select="/*/HeaderVO/HeaderVORow/InternalOrgVO/InternalOrgVORow/Name"/>
    If I want to add one colun in LinesVO, what are all things I need to do?
    I customized it by adding the new columns through JDeveloper and extending the VO's and substituting them, importing JPX and bounced apache.
    But the XSL-FO file is very strange (attached herewith). Those changes are not reflecting in report even after extension.

  • Remove SOAP-ENV tags from xml RECEIVER RESPONSE payload (XSL needed?)

    Hi
    I need to remove some tags from the payload of a RESPONSE message in a SOAP webservice scenarion.
    The received payload looks like this:
    before -
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns="http://tempuri.org/what.xsd">
    <SOAP-ENV:Body>
      <ns:crejob-resp>
        <response-data>
          <Result>0</Result>
        </response-data>
      </ns:crejob-resp>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    after it should look like this
    after -
    <?xml version="1.0" encoding="UTF-8"?>
    <crejob-resp>
       <response-data>
          <Result>0</Result>
       </response-data>
    </crejob-resp>
    I was thinking of using XSL as a "pre-burner" step before my mapping program but need help to XSL on this.
    Hope somebody can help
    Cheers

    I am sorry to be such a pain in the a..
    But I still get the wrong result (with your first option, 2nd option is not working):
    <?xml version="1.0" encoding="UTF-8"?>
    <crejob-resp>
      <response-data>0<Result>0</Result></response-data>
    </crejob-resp>
    Hope u can help again
    and also my source can look like: (unbounded on response-data)
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns="http://tempuri.org/what.xsd">
    <SOAP-ENV:Body>
    <ns:crejob-resp>
       <response-data>
          <Result>0</Result>
       </response-data>
       <response-data>
          <Result>1</Result>
       </response-data>
       <response-data>
          <Result>2</Result>
       </response-data>
    </ns:crejob-resp>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    Edited by: Bowie on Jul 2, 2009 3:08 PM

  • XML to CSV using AF_Modules/MessageTransformBean in AF

    hi All,
    I am trying to convert an XML file to CSV using AF_Modules/MessageTransformBean  module key XML2Plain in the Communication channel.
    http://help.sap.com/saphelp_nw04/Helpdata/EN/24/4cad3baabd4737bab64d0201bc0c6c/content.htm
    My Structure looks like
    <resultset>  -- 1
    <row> -- 0 .. *
    <line>ABC</line> -- 1
    </row>
    </resultset>
    Length of line is not fixed.
    XML2Plain  Transform.Class  com.sap.aii.messaging.adapter.Conversion
    XML2Plain Transform.ContentType text/plain;charset=utf-8
    XML2Plain xml.conversionType SimpleXML2Plain
    XML2Plain xml.addHeaderLine 0
    Now what should be value of endSeparator or field separator if length is not fixed?
    If sample input is:
    <resultset> 
    <row>
    <line>ABC</line>
    </row>
    <row>
    <line>sapnetweaver</line>
    </row>
    </resultset>
    Output should be:
    ABC
    sapnetweaver
    Please help!
    Thanks,
    Mayank

    Hi,
         As mentioned output want is CSV then need to define the separator as comma...for field and end separator as newline..
    thats it...
    HTH
    Rajesh

  • Problem in transforming xml to html using xsl

    Hi everybody ,
    I am creating a xml in memory and i want to transform using xsl into an html.
    I want to embed some html code also in the data node.But when I get the html it simply writes as it is. I tried to make it cdata section but it did not worked. Pls help.
    crypticashu
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.transform.dom.DOMSource;
    import org.w3c.dom.*;
    import javax.xml.transform.*;
    import javax.xml.transform.stream.*;
    public class mytemp {
         public static void main(String args[])
         DocumentBuilder builder = null;
         Document document = null;
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
         try
         builder = factory.newDocumentBuilder();
         document = builder.newDocument();
         catch (ParserConfigurationException e)
         e.printStackTrace();
         Element root = (Element) document.createElement("REPORT");
         document.appendChild(root);
         Node child = document.createElement("DATA");
         CDATASection data = document.createCDATASection("<b>Hello World </b>");
         child.appendChild(data);
         root.appendChild(child);
         document.getDocumentElement().normalize();
         DOMSource domsource = new DOMSource(document);
              TransformerFactory tfactory = TransformerFactory.newInstance();
              File f = new File("c:/mytemp/report.xsl");
              StreamSource xsl = new StreamSource(f);
              File html = new File("c:/myhtml.html");
              try
                   Templates templates = tfactory.newTemplates(xsl);
                   Transformer transformer = templates.newTransformer();
                   transformer.transform(domsource, new StreamResult(html));
              catch(Exception e)
                   e.printStackTrace();
         }

    want to embed some html code also in the data node.But when I get the html it simply writes as it is.That statement contradicts:
    In real application i will be getting data containg html tags.I want the parser to read that data as simple text. Both cannot be true. You either want the HTML to not be parsed or you want the transformer to deal with it. Which one?
    - Saish

  • How to display xml to html using xsl?

    hi all...may i know how to display xml to html page?
    i ve included <xsl:output method="html" indent="yes" /> inside my xsl file. i clicked on output.xml file and everything is displayed correctly but the format is xml instead of html. is there anyway to transform it to html?
    below are my xsl and xml codes:
    // xsl file
    <?xml version='1.0'?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes" />
    <xsl:template match="/">
    <html>
    <body>
    <h2>Document Contents</h2>
    <table border="1">
    <tr bgcolor="#9acd32">
         <th align="center">Document Name</th>     
         <th align="center">Document ID</th>          
         <th align="center">Owner</th>               
    </tr>
    <xsl:for-each select="Document/Contents">
    <tr>
    <td><xsl:value-of select="DocumentName"/></td>
    <td><xsl:value-of select="DocumentID"/></td>
    <td><xsl:value-of select="Originator"/></td>
    </tr>
    </xsl:for-each>
    </table>
    </body>
    </html>
    // xml file
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="xsltStyleSheet.xsl"?>
    <Document>
         <Contents>
              <DocumentName>register</DocumentName>
              <DocumentID>1</DocumentID>
              <Originator>hhh</Originator>
         </Contents>
    </Document>
    </xsl:template></xsl:stylesheet>

    your XSL transforms to HTML (in fact XHTML): what more do you expect? did you expected anything different from the following output? if yes: what and why?
    <html>
         <body>
              <h2>Document Contents</h2>
              <table border="1">
                   <tr bgcolor="#9acd32">
                        <th align="center">Document Name</th>
                        <th align="center">Document ID</th>
                        <th align="center">Owner</th>
                   </tr>
                   <tr>
                        <td>register</td>
                        <td>1</td>
                        <td>hhh</td>
                   </tr>
              </table>
         </body>
    </html>

  • Converting XML in WML using XSL Processor from XMLParser v2

    When trying to concert an XML doc into WML, it seems like the XSL Processor is removing some WML tags. Below are the XML doc and XSL doc I am using :
    The XML DOC
    <?xml version="1.0"?>
    <ROWSET>
    <ROW id="1">
    <NAME>RestaurantName</NAME>
    <ADDRESS>RestaurantAddress</ADDRESS>
    <PHONE_TYPE>Fixed</PHONE_TYPE>
    <PHONE>0112345678</PHONE>
    <PRICE>60</PRICE>
    <MENU>Salad, Pizza</MENU>
    <DESCRIPTION>Very good restaurant</DESCRIPTION>
    </ROW>
    <ROW id="2">
    <NAME>SecondRestaurantName</NAME>
    <ADDRESS>SecondRestaurantAddress</ADDRESS>
    <PHONE_TYPE>Fixed</PHONE_TYPE>
    <PHONE>0187654321</PHONE>
    <PRICE>60</PRICE>
    <MENU>Salad, Fish</MENU>
    <DESCRIPTION>Godd restaurant</DESCRIPTION>
    </ROW>
    </ROWSET>
    The XSL DOC
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <WML>
    <CARD>
    <xsl:apply-templates/>
    </CARD>
    </WML>
    </xsl:template>
    <xsl:template match="ROWSET">
    <xsl:for-each select="ROW">
    <xsl:value-of select="NAME"/>
    <xsl:value-of select="ADDRESS"/>
    Phone : <xsl:value-of select="PHONE"/>
    Price of the menu : <xsl:value-of select="PRICE"/>
    You can order : <xsl:value-of select="MENU"/>
    <xsl:value-of select="DESCRIPTION"/>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>
    The
    tag are removed by the XSL Processor ; In fact it seems that any tag contained within <xsl:template match="ROWSET"> and </template> is removed. This does not occurs with other XSL processor (such as lotusxsl).
    Is there something I'm doing wrong ??

    Your examples works correctly for me using the XSLT engine that comes with release 2.0.2.6 of the Oracle XML Parser "v2" for Java.
    Are you working with this latest release?

  • XML to CSV using SAX Parser

    Hello
    I need to convert xml files to csv format using SAX Parser. The following code & outputs are as below:
    XML file:
    <Library>
    <Book>
         <Title>Professional JINI</Title>
         <Author>bs</Author>
         <Publisher>Oreilly Publications</Publisher>
    </Book>
    <Book>
         <Title>XML Programming</Title>
         <Author>java</Author>
         <Publisher>Mann Publications</Publisher>
    </Book>
    </Library>
    public class BooksLibrary extends DefaultHandler
    protected static final String XML_FILE_NAME = "C:\\library1.xml";
         public static void main (String argv [])
              // Use the default (non-validating) parser
              SAXParserFactory factory = SAXParserFactory.newInstance();
              try {
                   FileOutputStream fos=new FileOutputStream("C:/test.txt");
                   // Set up output stream
                   out = new OutputStreamWriter (fos, "UTF8");
                   // Parse the input
                   SAXParser saxParser = factory.newSAXParser();
                   saxParser.parse( new File(XML_FILE_NAME), new BooksLibrary() );
              } catch (Throwable t) {
                   t.printStackTrace ();
              System.exit (0);
         static private Writer out;
         //===========================================================
         // Methods in SAX DocumentHandler
         //===========================================================
         public void startDocument ()
         throws SAXException
              showData ("<?xml version='1.0' encoding='UTF-8'?>");
              newLine();
         public void endDocument ()
         throws SAXException
              try {
                   newLine();
                   out.flush ();
              } catch (IOException e) {
                   throw new SAXException ("I/O error", e);
         public void startElement (String name, Attributes attrs)
         throws SAXException
              showData ("<"+name);
              if (attrs != null) {
                   for (int i = 0; i < attrs.getLength (); i++) {
                        showData (" ");
                        showData (attrs.getLocalName(i)+"=\""+attrs.getValue (i)+"\"");
              showData (">");
         public void endElement (String name)
         throws SAXException
              showData ("</"+name+">");
         public void characters (char buf [], int offset, int len)
         throws SAXException
              String s = new String(buf, offset, len);
              showData (s);
         //===========================================================
         // Helpers Methods
         //===========================================================
         // Wrap I/O exceptions in SAX exceptions, to
         // suit handler signature requirements
         private void showData (String s)
         throws SAXException
              try {
                   out.write (s);
                   out.flush ();
              } catch (IOException e) {
                   throw new SAXException ("I/O error", e);
         // Start a new line
         private void newLine ()
         throws SAXException
              //String lineEnd = System.getProperty("line.separator");
              try {
                   out.write (", ");
              } catch (IOException e) {
                   throw new SAXException ("I/O error", e);
    --------------------------------------------------------------------------------------------------output is as follows:
    <?xml version='1.0' encoding='UTF-8'?>,
         Professional JINI
         bs
         Oreilly Publications
         XML Programming
         java
         Mann Publications
    Can anyone please tell me how to remove that indentation space & get the output as :
    <?xml version='1.0' encoding='UTF-8'?>, Professional JINI, bs, Oreilly Publications, XML Programming, java, Mann Publications
    Thanks

    By the way, there is a new feature in Java 5.0 (Tiger) called "Annotations."
    Since your code extneds DefaultHandler, you could specify a line with
    @Override
    before the definition of each of your methods. If you had used these, the compiler would have given an error since your methods did not override the methods of DefaultHandler.
    (If your code implemented ContentHandler, by contrast, using @Override is invalid because you need to implement all of the methods defined in the interface definition.)
    The other comment is that the safest way to handle characters() data is to use a StringBuilder/Buffer (StringBuilder is only valid in 5.0, StringBuffer has been around since Release 1.0) that you define in the startElement method. Use the append method to gather data presented to you in the characters() method and use toString() to harvest the data in the endElement method.
    Dave Patterson

  • Codepage conversion from multi-lingual table using JDBC

    Hello,
    I have an Oracle database that has been around since before any unicode was available. It is currently 9.2.0.7.0 and the charset is WE8ISO8859P1. I am trying to port all of the data in the 'Translation' table to a UTF-8 database. The problem is that each of the translated strings is stored in its own native MS Windows codepage. This table was populated over the years via OCI connections in C/C++, and this method worked. But now we need it moved to UTF-8 and are using JAVA. Obviously, all the cp1252 languages come over just fine, but all the other languages get converted to garbage by JDBC, since it is auto-converting them and assumes the source is 8859. I could do it with OCI, as I mentioned, but I am mandated to use JAVA and a web interface, so users can choose what data to move/convert to the new DB (on-demand) from a web page.
    Is there a way to force the Oracle connection to think the database is in a different codepage so that the conversion comes out correct? OR
    Is there a way to get the data from Oracle as unconverted chars, or generic binary, or something, and then have JAVA convert it to UTF-8 from the correct codepage before writing it to the new table?
    Any help is appreciated.
    Monte
    Message was edited by:
    Wookie

    ## Is there a way to force the Oracle connection to think the database is
    ## in a different codepage so that the conversion comes out correct?
    No.
    ## Is there a way to get the data from Oracle as unconverted chars,
    ## or generic binary, or something, and then have JAVA convert it
    ## to UTF-8 from the correct codepage before writing it to the new table?
    Yes. Use:
    SELECT UTL_RAW.CAST_TO_RAW(col) FROM tab;
    and retrieve the value with ResultSet.getBytes. Then convert the retrieved byte[] to java.lang.String using String(byte[] bytes, String charsetName) constructor. Note, charsetName is Java name. Then, you can use setString() on PreparedStatement containing the INSERT for the converted value.
    -- Sergiusz

  • Conversion from txt  to csv

    Hi,
    As a part of our project we are generating a text file containing the query output, it is in the following format..
    | contributor | x | url |
    ===========================================================================
    | _:b0 | "Norm Walsh" | <http://norman.walsh.name/> |
    | _:b1 | "Ebiquity research group UMBC" | <http://ebiquity.umbc.edu/v2.1/blogger/> |
    | _:b2 | "Orri Erling" | <http://www.openlinksw.com/weblogs/oerling/> |
    | _:b3 | "John Breslin" | <http://www.johnbreslin.com/blog/> |
    We need to convert this into csv file. We have tried writing a java code for this, but are facing a problem there as it is considering each space as a newline and also all the rows are not coming in a new line.
    We are running all the codes on eclipse platform.
    Relevant codes are:
              FileReader reader = new FileReader("C:\\track1.txt");
              Scanner dumpfile = new Scanner(reader);
         PrintWriter out = new PrintWriter("C:\\output.txt");
                   while (dumpfile.hasNext())
                        out.print((dumpfile.next().replace("|",",").replace('-', ' ').replace('=', ' ')));
    and
    FileReader reader1 = new FileReader("C:\\output.txt");
         Scanner dumpfile1 = new Scanner(reader1);
         PrintWriter out1= new PrintWriter("C:\\csvfile.txt");
         while (dumpfile1.hasNext())
              out1.println(dumpfile1.next().replace(",,","     "));
    Can anyone give us a solution ..pls
    Regards,

    We want the output in the following format(csv format):
    contributor , x , url
    _:b0 , "Ivan Herman",<http://ivanherman.wordpress.com/tag/work-related/semantic-web/>
    _:b1 , "Dave Beckett",<http://journal.dajobe.org/journal/>
    _:b2,"Uldis Bojars", <http://captsolo.net/info/>
    _:b3, "Peter Mika",<http://tripletalk.wordpress.com/>
    We have made a few changes to the code now.We added the following code snippet:
                      FileReader reader1 = new FileReader("C:\\output.txt");
                       Scanner dumpfile1 = new Scanner(reader1);
                      PrintWriter out1= new PrintWriter("C:\\csvfile.txt");
                      while (dumpfile1.hasNext())
                          out1.println(dumpfile1.next().replace(",,","\n"));
                      }but now for the 1st 2 rows the colomns are shifted to the right by 1 cell. The output is as follows in excel:
         contributor     x     url
         _:b0     OraLassila     <http://www.lassila.org/blog/>
    _:b1     LeighDodds <http://xmlarmyknife.org/blog/>     
    _:b2     KingsleyIdehen <http://www.openlinksw.com/blog/~kidehen/>     
    _:b3     LeighDodds <http://ldodds.com/blog/>
    In csv it is as follows:
    ,contributor,x,url,
    ,_:b0,"IvanHerman",<http://ivanherman.wordpress.com/tag/workrelated/semanticweb/>
    _:b1,"DaveBeckett",<http://journal.dajobe.org/journal/>
    _:b2,"UldisBojars",<http://captsolo.net/info/>
    _:b3,"PeterMika",<http://tripletalk.wordpress.com/>     
    Comma at the beginning in the first two lines must be removed using java code. If anyone could help me out with this, it will be very helpful for me.
    Regards

  • Conversion from XML to WML

    Hi! I am Nauman. Are there any java APIs or interfaces which can convert XML into WML. What is the simplist way ? Thankyou for telling !!!

    Use [url http://www.w3.org/TR/xslt]XSLT to convert the XML to WML. This transformation can be facilitated in a number of different ways, including but not limited to an application written in java.
    There are a number of good tutorials out there (try searching on Google). Also, a search of this forum may produce some useful information.
    &#8734; brewman &#8734;

Maybe you are looking for