UTF-8 files with BOM chrashes DOMParser?

Hi.
We are storing XML-documents in an 8i databse with UTF-8 encoding (in CLOBS).
Problem: If the Unicode XML-document contains a BOM the oracle.xml.parser.v2.DOMParser's
parse()-method throws an exception.
I get the following output when using the ParseXMLFromURL.java class supplied in JDeveloper 3.2 samples directory:
Sample output >>>>
System Output: XML parse error in file http://localhost/UTF-8_With_BOM.xml
System Output: at line 1, character 1
System Output: Start of root element expected.
<<<<<<< Sample output
If I change the XML-file not to include a BOM the parser works fine.
(I set/unset the BOM using EmEditor from http://www.emurasoft.com/ if you'd like to try for yourselves).
To me it looks like DOMParser interprets the BOM at the start of the XML-file as XML-content instead of a Unicode signature.
IE 5.5 can handle both formats, shouldn't DOMParse also be able to handle that?
Any ideas how I can get DOMParse to work with UTF-8(BOM) XML-files?
Regards,
Jan-Erik
Sample XML:
<?xml version="1.0" encoding='UTF-8'?>
<newsdoc>
<news>
<newstitle>
Document contains no BOM
</newstitle>
<introduction>
See http://www.unicode.org/unicode/faq/utf_bom.html for info on BOM
</introduction>
</news>
</newsdoc>
null

I have the same problem when trying to store UTF-8 encoded XML files with BOM marks in iFS version 1.1.9.0.7.
The database is 8.1.7.1.1 created with UTF-8 charset.
I have loaded the XDK for PLSQL 9.0.2.0.0A into the database and replaced the original %ORACLE_HOME%\lib\xmlparserv2.jar with the one distributed in this XDK.
I get the following error message:
Wed Aug 01 10:10:06 GMT+02:00 2001: \public\CV-Bank\CV_Patrik_Johansson_intDTD_BOM.xml:
oracle.ifs.common.IfsException: IFS-12608: Error while pre-parsing with the SAXParser: at line (1), column (1): oracle.xml.parser.v2.XMLParseException: Start of root element expected.
at oracle.ifs.beans.parsers.IfsXmlParser.preParse(IfsXmlParser.java, Compiled Code)
at java.lang.Exception.<init>(Exception.java, Compiled Code)
at oracle.ifs.common.IfsException.<init>(IfsException.java, Compiled Code)
at oracle.ifs.common.IfsException.<init>(IfsException.java, Compiled Code)
at oracle.ifs.beans.parsers.IfsXmlParser.preParse(IfsXmlParser.java, Compiled Code)
at oracle.ifs.beans.parsers.IfsXmlParser.getParserName(IfsXmlParser.java, Compiled Code)
at oracle.ifs.beans.parsers.IfsXmlParser.parse(IfsXmlParser.java, Compiled Code)
at oracle.ifs.beans.parsers.IfsXmlParser.parse(IfsXmlParser.java, Compiled Code)
at oracle.ifs.utils.common.ParserHelper.parseExistingDocument(ParserHelper.java, Compiled Code)
at oracle.ifs.protocols.ntfs.server.FileProxy.parseFile(FileProxy.java, Compiled Code)
at oracle.ifs.protocols.ntfs.server.FileProxy.cleanupFile(FileProxy.java, Compiled Code)
at oracle.ifs.protocols.ntfs.server.FileProxy.runFileProxy(Native Method)
at oracle.ifs.protocols.ntfs.server.FileProxy.run(FileProxy.java, Compiled Code)
This is a serious problem since we use an XML editor that adds BOM's.
Regards
Patrik Johansson

Similar Messages

  • UTF 16 BE with BOM

    Hi,
    i need to write a file in UTF16 BE format to a NFS share. But i could not manage to force XI to write BOM (Byte order mark) Fe FF at the beginning of the file. Its always without BOM.
    How can i force XI to write the BOM? Which entry in the file processing parameters/encoding box should i enter?

    UTF-16BE does not use a BOM, as the BE states the byte order already.
    http://en.wikipedia.org/wiki/UTF-16
    What happens if you just mention the file encoding as UTF-16?
    Edited by: Stefan Grube on Mar 8, 2010 4:11 PM

  • Encoding Issue: Change UTF8 with BOM char file to UTF16LE without BOM char.

    i am trying to read UTF 8 file with BOM char .. if BOM mark present then i want to remove that BOM char
    and write same file with UTF16LE with out BOM char ..
    Please suggest solution on this .
    FileInputStream fis = new FileInputStream(file);
                   long size = file.length();
                   byte[] b = new byte[(int) size];
                   int bytesRead = fis.read(b, 0, (int) size);
                   if (bytesRead != size) {
                        throw new IOException("cannot read file");
                   byte[] srcBytes = b;
                            int b0 = srcBytes[0] & 0xff;
                   int b1 = srcBytes[1] & 0xff;
                   int b2 = srcBytes[2] & 0xff;
                   int b3 = srcBytes[3] & 0xff;
                   if (b0 == 0xef && b1 == 0xbb && b2 == 0xbf) {
                        System.out.println("Hint: the file starts with a UTF-8 BOM.");
                             String srcStr = new String(b ,"UTF8");
                     String      encoding= "UnicodeLittle";
                            writeFile(filePath, srcStr,encoding);// Here is writing file with UTF16LE
         But files gets written with BOM char .
    how do i remove this .
    Please suggest solution on this

    'uncle_alice' - in the OP's other thread on this topic I posted a decorated InputStream class that will strip of any (well any I could find definitions of) BOM prefix. Using this it is almost trivial for the OP to convert a file from one encoding to another without worrying about the BOM. I showed him the water but I can't make him drink.

  • Files with ByteOrder Mark

    Hi Guys
    The source files are coming with Byte Order Mark (BOM). Because of this the Header Key field value is not being detected and the mapping fails.Is there a way to get rid of this BOM?
    Thanks!

    Hi
    Pls check the following threads for BOM
    Re: Reading a UTF-8 File with BOM (Byte Order Mark) with the File Adapter
    How to remove BOM[FF FE] from the input flat file in XI
    Regards
    Abhijit

  • Manually adding BOM to UTF-16LE file?

    hi.
    i have a bash script that needs to preform something on a string from standard input, save it in a file and convert the file to UTF-16LE with BOM for further processing by another application.
    i use iconv to convert the text file to UTF-16LE, but iconv actually creates a little-endian file WITHOUT the bom. (converting to UTF-16 creates a big endian file WITH bom)
    i see no way of creating LE with BOM with iconv, so i thought maybe i could simply add the byte-order marks (FF FE) to the beginning of the unicode file. how can i do that?
    many thanks in advance
    tench

    If you want to do everything from within bash script, then you can use something like
    {code}
    #!/bin/sh
    # I think xpg_echo is ON by default, but just in case...
    shopt -s xpg_echo
    cat > infile
    # assume the input is in UTF-8
    (echo '\xFF\xFE\c'
    iconv -f UTF-8 -t UTF-16LE infile) > outfile
    {code}
    Of course use of infile can be omitted if you don't need it.

  • Translation - XLF file with the UTF-8 BOM at the head of the file

    Using APEX 3.2, I'm trying to get translations loaded for an application that I'm working on. We are going through the process of generating XLIFF files, sending them to a translator to translate, and then importing the data back in rather than manually editing the translations.
    This works perfectly when I use my text editor to enter the (very poor) translations in the file. Our translator, however, uses a tool that adds a byte-order mask BOM at the head of the XLIFF file when it saves it in order to identify it as a UTF-8 encoded file. This appears to be a valid way for the tool to indicate the encoding being used though, obviously, the encoding in the header overrides it and the BOM is not the preferred method of specifying the encoding of an XML file. However, when we import the file in APEX, and hit the Apply XLIFF button, we get an error
    ORA-31011: XML parsing failed ORA-19202: Error occurred in XML processing LPX-00210: expected '<' instead of '¿' Error at line 1
    The third byte of the UTF-8 BOM (0xEF,0xBB,0xBF), if interpreted as an ISO-8859-1, would be the upside down question mark character in the error message. So it appears that the APEX importer is interpreting the BOM using the ISO-8859-1 character set and throwing an error that the file is not valid. That is not my reading of the proper XML parser behavior.
    Obviously, we can work around the problem either by asking our translator to use a different tool or by opening up the files we get back in a hex editor and removing the BOM. Is there anything we can do to resolve the issue that doesn't involve adding an additional manual step to the process or the translator changing the tool being used? Or is there something I'm missing that would indicate that a file with the BOM in the first three bytes should not be considered a valid XML file?
    Justin

    Hello Justine,
    >> Are you stating that that APEX translation engine more or less requires the database character set to be AL32UTF8 in order to work properly …
    Not exactly.
    The APEX translation engine uses the XML DB parser, and this one needs a legal XML file. The problem is that in your specific case, the encoding of the XLIFF file doesn’t match the database character set, hence a character set conversion process is involved in the middle. This conversion process – from UTF-8 to WE8MSWIN1252 embeds illegal XML characters in your stored XML file, right where the BOM is. If, for example, your XLIFF file were encoded in Windows-1252, no character conversion would be necessary and the final (database stored) version of the XLIFF would have been remained legal (assuming it started this way). In this case, the APEX translation mechanism will work just fine, even with a database character set of WE8MSWIN1252 (as you can see when you are using your own XLIFF files, which don’t include the (offending) BOM byte).
    >> … even if an alternate character set encodes all the characters we need?
    With your current database configuration, it seems that the alternate character set you are talking about can’t really encode all the characters that you need, as it can’t cope with the UTF-8 BOM conversion. It very well may be the only character it can’t handle, but that is enough.
    As we need to be practical, and a database character set conversion is most likely out of the question, the simple solution is probably asking your translator to save your XLIFF files without including the BOM. I’m not familiar with the professional XLIFF editors you mentioned, however, as UTF-8 encoding doesn’t really need a BOM, saving a UTF-8 file without it should be an option (just like Keith mentioned with regards to very simple editors like the windows’ Notepad, or Notepad++).
    Regards,
    Arie.
    &diams; Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.
    &diams; Author of Oracle Application Express 3.2 – The Essentials and More

  • Byte Order Mark (BOM) not found in UTF-8 file download from XI

    Hi Guys,
    Facing difficulty in downloading file from XI in UTF-8 format with byte order mark.
    Receiver File adapter has been configured to download the file in UTF-8 file format. But the byte order mark is missing. Same works well for UTF-16. Could see the byte order mark at the beginning of  file "FEFF" for UTF-16BE - Unicode big endian.
    As per SAP help, UTF-8 supposed to be the default encoding for TEXT file type.
    Configuring the Receiver File/FTP Adapter in the SAP help link.
    http://help.sap.com/saphelp_nw04/helpdata/en/d2/bab440c97f3716e10000000a155106/frameset.htm
    Could you please advice on how to achieve BOM in UTF-8 file as it is very important for the outbound file to get loaded in our vendor system.
    Thanks.
    Best Regards
    Thiru

    Hi!<br>
    <br>
    Had the same problem. But here, we create a "CSV"-File which must have the BOM otherwise it will not be recogniced as UTF-8.
    <br>
    Therefore I've done the folowing:
    Created a simple destination-structure which represents the CSV and done the mapping with the graphical-mapper. The destination-Structure looks like:
    <br>
    (?xml version="1.0" encoding="UTF-8"?)<br>
    (ONLYLINES)<br>
         (LINE)<br>
              (ENTRY)Hello I'm line 1(/ENTRY)<br>
         (/LINE)<br>
         (LINE)<br>
              (ENTRY)and I'm line 2(/ENTRY)<br>
         (/LINE)<br>
    (/ONLYLINES)
    As you can see, the "ENTRY"-Element holds the data.<br>
    <br>
    Now I've created the folowing Java-Mapping and added that mapping within the Interface-Mapping as second step after the graphical mapping:<br>
    <br>
    ---cut---<br>
    package sfs.biz.xi.global;<br>
    <br>
    import java.io.InputStream;<br>
    import java.io.OutputStream;<br>
    import java.util.Map;<br>
    <br>
    import javax.xml.parsers.DocumentBuilder;<br>
    import javax.xml.parsers.DocumentBuilderFactory;<br>
    <br>
    import org.w3c.dom.Document;<br>
    import org.w3c.dom.Element;<br>
    import org.w3c.dom.NodeList;<br>
    <br>
    import com.sap.aii.mapping.api.StreamTransformation;<br>
    import com.sap.aii.mapping.api.StreamTransformationException;<br>
    <br>
    public class OnlyLineConvertAddingBOM implements StreamTransformation {<br>
    <br>
         public void execute(InputStream in, OutputStream out) throws StreamTransformationException {<br>
              try {<br>
                   byte BOM[] = new byte[3];<br>
                   BOM[0]=(byte)0xEF;<br>
                   BOM[1]=(byte)0xBB;<br>
                   BOM[2]=(byte)0xBF;<br>
                   String retString=new String(BOM,"UTF-8");<br>
                   Element ServerElement;<br>
                   NodeList Server;<br>
                   <br>
                DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();<br>
                DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();<br>
                Document doc = docBuilder.parse(in);<br>
                doc.getDocumentElement().normalize();<br>
                NodeList ConnectionList = doc.getElementsByTagName("ENTRY");<br>
                int count=ConnectionList.getLength();<br>
                for (int i=0;i<count;i++) {<br>
                    ServerElement = (Element)ConnectionList.item(i);<br>
                    Server = ServerElement.getChildNodes();<br>
                    retString += Server.item(0).getNodeValue().trim() + "\r\n";<br>
                }<br>
                <br>
                out.write(retString.getBytes("UTF-8"));<br>
                   <br>
              } catch (Throwable t) {<br>
                   throw new StreamTransformationException(t.toString());<br>
              }<br>
         }<br>
    <br>
         public void setParameter(Map arg0) {<br>
              // TODO Auto-generated method stub<br>
              <br>
         }<br>
    <br>
    /*<br>
         public static void main(String[] args) {<br>
              File testfile=new File("c:\\instance.xml");<br>
              File testout=new File("C:\\testout.txt");<br>
              FileInputStream fis = null;<br>
              FileOutputStream fos= null;<br>
              OnlyLineConvertAddingBOM myFI=new OnlyLineConvertAddingBOM();<br>
              try {<br>
                    fis = new FileInputStream(testfile);<br>
                     fos = new FileOutputStream(testout);<br>
                    myFI.setParameter(null);<br>
                    myFI.execute(fis, fos);<br>
              } catch (Exception e) {<br>
                   e.printStackTrace();<br>
              }<br>
                    <br>
                    <br>
         }<br>
         */<br>
    <br>
    }<br>
    --cut---
    <br>
    This Mapping searches all "ENTRY"-Tags within the XML-Strucure and creates a big string which startes with the UTF-8-BOM and than combined each ENTRY-Element, separated by CR/LF.<br>
    <br>
    We use this as Payload for an Mail-Adapter (sending via SMTP) but it should also work on File-Adapter.<br>
    <br>
    Hope it helps.<br>
    Rene<br>
    <br>
    Besides: could someone tell SAP that this editor is the WORSEST editor I've ever seen. Maybe this guys should copy somethink from wikipedia :-((
    Edited by: Rene Pilz on Oct 8, 2009 5:06 PM

  • Export SQL View to Flat File with UTF-8 Encoding

    I've setup a package in SSIS to export a SQL view to a flat file and it's working fine.  I now need to make that flat file UTF-8 encoded.  The package executes but still shows the files as ANSI encoded.
    My package consists of a Source (SQL View) -> Derived Column (casts the fields to DT_WSTR) -> Destination Flat File (Set to output UTF-8 file).
    I don't get any errors to help me troubleshoot further.  I'm running SQL Server 2005 SP2.

    Unless there is a Byte-Order-Marker (BOM - hex file prefix: EF BB BF) at the beginning of the file, and unless your data contains non-ASCII characters, I'm unsure there is a technical difference in the files, Paul.
    That is, even if the file is "encoded" UTF-8, if your data is only ASCII values (decimal values 0-127, hex 00-7F), UTF-8 doesn't really serve a purpose over ANSI encoding.  Now if you're looking for UTF-8 with specifically the BOM included, and your data is all standard ASCII, the Flat File Connection Manager can't do that, it seems.
    What the flat file connection manager is doing correctly though, is encoding values that are over decimal 127/hex 7F in UTF-8 when the encoding of the connection manager is set to 65001 (UTF-8).
    Example:
    Input data built with a script component as a source (code at the bottom of this post) and with only one WSTR output column hooked to a flat file destination component:
    a string containing only decimal value 225 (german Eszett character - ß)
    Encoding set to ANSI 1252 looks like:
    E1 0D 0A (which is the ANSI encoding of the decimal character value 225 (E1) and a CR-LF (0D 0A)
    Encoding set to UTF-8 65001 looks like:
    C3 A1 0D 0A  (which is the UTF-8 encoding of the decimal character value 225 (C3 A1) and a CR-LF (0D 0A)
    Note that for values over decimal 127, UTF-8 takes at least two bytes and up to four for the remaining values available.
    So, I'm comfortable now, after sitting down and going through this, that the flat file connection manager is working correctly, unless you need a BOM.
    1
    Imports System  
    2
    Imports System.Data  
    3
    Imports System.Math  
    4
    Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper  
    5
    Imports Microsoft.SqlServer.Dts.Runtime.Wrapper  
    6
    7
    Public Class ScriptMain  
    8
        Inherits UserComponent  
    9
    10
        Public Overrides Sub CreateNewOutputRows()  
    11
            Output0Buffer.AddRow()  
    12
            Output0Buffer.col1 = ChrW(225)  
    13
        End Sub 
    14
    15
    End Class 
    Phil

  • [svn:fx-trunk] 7661: Change from charset=iso-8859-1" to charset=utf-8" and save file with utf-8 encoding.

    Revision: 7661
    Author:   [email protected]
    Date:     2009-06-08 17:50:12 -0700 (Mon, 08 Jun 2009)
    Log Message:
    Change from charset=iso-8859-1" to charset=utf-8" and save file with utf-8 encoding.
    QA Notes:
    Doc Notes:
    Bugs: SDK-21636
    Reviewers: Corey
    Ticket Links:
        http://bugs.adobe.com/jira/browse/iso-8859
        http://bugs.adobe.com/jira/browse/utf-8
        http://bugs.adobe.com/jira/browse/utf-8
        http://bugs.adobe.com/jira/browse/SDK-21636
    Modified Paths:
        flex/sdk/trunk/templates/swfobject/index.template.html

    same problem here with wl8.1
    have you sold it and if yes, how?
    thanks

  • Probs with read-in of UTF-16LE file

    hi all,
    the following code works only on a small UTF-16LE file, but not on a file of say > 100 KB... with such a file the first isr.read() causes the program to hang...! wrapping with BufferedReader does not solve the prob...
    InputStreamReader isr = new InputStreamReader( new FileInputStream("filename"), "UTF-16LE");
    for( int i = 0; i < 50; i++ ){
    int ch = isr.read();
    System.out.println( "char " + i + ": " + ch );
    FLUMMOXED... PLS HELP!!

    Simple example
    try {
            BufferedReader in = new BufferedReader(new FileReader("FileName.txt"));
            String str;
            while ((str = in.readLine()) != null) {
                //do whatever whith str       
            in.close();
        } catch (IOException e) {
            //Handle Exception...

  • Encoding Problem - can't read UTF-8 file correctly

    Windows XP, JDK 7, same with JDK 6
    I can't read a UTF-8 file correctly:
    Content of File (utf-8, thai string):
    &#3648;&#3617;&#3655;&#3604;&#3648;&#3621;&#3639;&#3629;&#3604;&#3586;&#3634;&#3623;
    When opened in Editor and copy pasted to JTextField, characters are displayed correctly:
    String text = jtf.getText();
    text.getBytes("utf-8");
    -32 -71 -128 -32 -72 -95 -32 -71 -121 -32 -72 -108 -32 -71 -128 -32 -72 -91 -32 -72 -73 -32 -72 -83 -32 -72 -108 -32 -72 -126 -32 -72 -78 -32 -72 -89
    Read file with FileReader/BufferedReader:
    line = br.readLine();
    buffs = line.getBytes("utf-8"); //get bytes with UTF-8 encoding
    -61 -65 -61 -66 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
    buffs = line.getBytes(); // get bytes with default encoding
    -1 -2 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
    Read file with:
    FileInputStream fis...
    InputStreamReader isr = new InputStreamReader(fis,"utf-8");
    BufferedReader brx = new BufferedReader(isr);
    line = br.readLine();
    buffs = line.getBytes("utf-8");
    -17 -65 -67 -17 -65 -67 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
    buffs = line.getBytes();
    63 63 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
    Anybody has an idea? The file seems to be UTF-8 encoded. What could be wrong here?

    akeiser wrote:
    Windows XP, JDK 7, same with JDK 6
    I can't read a UTF-8 file correctly:
    Content of File (utf-8, thai string):
    &#3648;&#3617;&#3655;&#3604;&#3648;&#3621;&#3639;&#3629;&#3604;&#3586;&#3634;&#3623;
    When opened in Editor and copy pasted to JTextField, characters are displayed correctly:
    String text = jtf.getText();
    text.getBytes("utf-8");
    -32 -71 -128 -32 -72 -95 -32 -71 -121 -32 -72 -108 -32 -71 -128 -32 -72 -91 -32 -72 -73 -32 -72 -83 -32 -72 -108 -32 -72 -126 -32 -72 -78 -32 -72 -89 These values are the bytes of your original string "&#3648;&#3617;&#3655;&#3604;&#3648;&#3621;&#3639;&#3629;&#3604;&#3586;&#3634;&#3623;" utf-8 encoded with no BOM (Byte Order Marker) prefix.
    >
    Read file with FileReader/BufferedReader:
    line = br.readLine();
    buffs = line.getBytes("utf-8"); //get bytes with UTF-8 encoding
    -61 -65 -61 -66 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
    buffs = line.getBytes(); // get bytes with default encoding
    -1 -2 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
    Read file with:
    FileInputStream fis...
    InputStreamReader isr = new InputStreamReader(fis,"utf-8");
    BufferedReader brx = new BufferedReader(isr);
    line = br.readLine();
    buffs = line.getBytes("utf-8");
    -17 -65 -67 -17 -65 -67 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14
    buffs = line.getBytes();
    63 63 32 0 64 14 33 14 71 14 20 14 64 14 37 14 55 14 45 14 20 14 2 14 50 14 39 14 These values are the bytes of your original string UTF-16LE encoded with a UTF-16LE BOM prefix.
    This means that there is nothing wrong (the String has been read correctly) with the code and that your default encoding is UTF-16LE .
    Edited by: sabre150 on Aug 1, 2008 5:48 PM

  • Parsing XML file with different languages (Xerces)

    How do we code or program to an XML file with different
    languages , say english and spanish. WHen we parse such a document with the default locale , the presence of special characters throws errors .For eg when I use xerces and use
    DOMParser parser = new DOMParser();
    try
    // Parse the XML Document
    parser.parse(xmlFile);
    catch (SAXException se)
    se.printStackTrace();
    org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0xfc) was found in the element content of the document.
    System Error:          void org.apache.xerces.framework.XMLParser.parse(org.xml.sax.InputSource)
    So what locale do we set before we parse ?How to handle this problem

    You need an encoding attribute in the xml declaration. If you don't, the parser assumes UTF-8, which are ASCII characters up to 127 - useful (only) for English.
    So, something like this would allow you to use characters above 127, ISO-8859-1 is the encoding used by standard PCs.
    <?xml version="1.0" encoding="ISO-8859-1"?>
    You can find a (offical) list of encodings at:
    http://www.iana.org/assignments/character-sets
    I'm not sure about mixing various encodings. I think you have to resort external parsed entities, which can have their own encoding, but I think you cannot mix encodings in one XML file.
    Good luck.

  • Upload multiple files WITH correct pairs of form fields into Database

    In my form page, I would like to allow 3 files upload and 3 corresponding text fields, so that the filename and text description can be saved in database table in correct pair. Like this:
    INSERT INTO table1 (filename,desc) VALUES('photo1.jpg','happy day');
    INSERT INTO table1 (filename,desc) VALUES('photo2.jpg','fire camp');
    INSERT INTO table1 (filename,desc) VALUES('photo3.jpg','christmas night');
    However, using the commons fileupload, http://commons.apache.org/fileupload/, I don't know how to reconstruct my codes so that I can acheieve this result.
    if(item.isFormField()){
    }else{
    }I seems to be restricted from this structure.
    The jsp form page
    <input type="text" name="description1" value="" />
    <input type="file" name="sourcefile" value="" />
    <input type="text" name="description2" value="" />
    <input type="file" name="sourcefile" value="" />The Servlet file
    package Upload;
    import sql.*;
    import user.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.Map;
    import java.util.HashMap;
    import java.util.Date;
    import java.util.List;
    import java.util.Iterator;
    import java.io.File;
    import java.io.PrintWriter;
    import java.io.IOException;
    import java.text.SimpleDateFormat;
    import org.apache.commons.fileupload.servlet.ServletFileUpload;
    import org.apache.commons.fileupload.disk.DiskFileItemFactory;
    import org.apache.commons.fileupload.*;
    public class UploadFile extends HttpServlet {
    private String fs;
    private String category = null;
    private String realpath = null;
    public String imagepath = null;
    public PrintWriter out;
    private Map<String, String> formfield = new HashMap<String, String>();
      //Initialize global variables
      public void init(ServletConfig config, ServletContext context) throws ServletException {
        super.init(config);
      //Process the HTTP Post request
      public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        Thumbnail thumb = new Thumbnail();
        fs = System.getProperty("file.separator");
        this.SetImagePath();
         boolean isMultipart = ServletFileUpload.isMultipartContent(request);
         if(!isMultipart){
          out.print("not multiple part.");
         }else{
             FileItemFactory factory = new DiskFileItemFactory();
             ServletFileUpload upload = new ServletFileUpload(factory);
             List items = null;
             try{
                items = upload.parseRequest(request);
             } catch (FileUploadException e) {
                e.printStackTrace();
             Iterator itr = items.iterator();
             while (itr.hasNext()) {
               FileItem item = (FileItem) itr.next();
               if(item.isFormField()){
                  String formvalue = new String(item.getString().getBytes("ISO-8859-1"), "utf-8");
                  formfield.put(item.getFieldName(),formvalue);
                  out.println("Normal Form Field, ParaName:" + item.getFieldName() + ", ParaValue: " + formvalue + "<br/>");
               }else{
                 String itemName = item.getName();
                 String filename = GetTodayDate() + "-" + itemName;
                 try{
                   new File(this.imagepath + formfield.get("category")).mkdirs();
                   new File(this.imagepath + formfield.get("category")+fs+"thumbnails").mkdirs();
                   //Save the file to the destination path
                   File savedFile = new File(this.imagepath + formfield.get("category") + fs + filename);
                   item.write(savedFile);
                   thumb.Process(this.imagepath + formfield.get("category") +fs+ filename,this.imagepath + formfield.get("category") +fs+ "thumbnails" +fs+ filename, 25, 100);
                   DBConnection db = new DBConnection();
                   String sql = "SELECT id from category where name = '"+formfield.get("category")+"'";
                   db.SelectQuery(sql);
                    while(db.rs.next()){
                      int cat_id = db.rs.getInt("id");
                      sql = "INSERT INTO file (cat_id,filename,description) VALUES ("+cat_id+",'"+filename+"','"+formfield.get("description")+"')";
                      out.println(sql);
                      db.RunQuery(sql);
                 } catch (Exception e){
                    e.printStackTrace();
            HttpSession session = request.getSession();
            UserData k = (UserData)session.getAttribute("userdata");
            k.setMessage("File Upload successfully");
            response.sendRedirect("./Upload.jsp");
      //Get today date, it is a test, actually the current date can be retrieved from SQL
      public String GetTodayDate(){
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        String today = format.format(new Date());
        return today;
      //Set the current RealPath which the file calls for this file
      public void SetRealPath(){
        this.realpath = getServletConfig().getServletContext().getRealPath("/");
      public void SetImagePath(){
        this.SetRealPath();
        this.imagepath = this.realpath + "images" +fs;
    }Can anyone give me some code suggestion? Thx.

    When one hits the submit button - I then get a 404 page error.What is the apaches(?) error log saying? Mostly you get very useful information when looking into the error log!
    In any case you may look at how you are Uploading Multiple Files with mod_plsql.

  • Create xml file with values from context

    Hi experts!
    I am trying to implement a WD application that will have some input fields, the value of those input fields will be used to create an xml file with a certain format and then sent to a certain application.
    Apart from this i want to read an xml file back from the application and then fill some other context nodes with values from the xml file.
    Is there any standard used code to do this??
    If not how can i do this???
    Thanx in advance!!!
    P.S. Points will be rewarded to all usefull answers.
    Edited by: Armin Reichert on Jun 30, 2008 6:12 PM
    Please stop this P.S. nonsense!

    Hi,
    you need to create three util class for that:-
    XMLHandler
    XMLParser
    XMLBuilder
    for example in my XML two tag item will be there e.g. Title and Organizer,and from ur WebDynpro view you need to pass value for the XML tag.
    And u need to call buildXML()function of builder class to generate XML, in that i have passed bean object to get the values of tags. you need to set the value in bean from the view ui context.
    Code for XMLBuilder:-
    Created on Apr 4, 2006
    Author-Anish
    This class is to created for having function for to build XML
    and to get EncodedXML
      and to get formated date
    package com.idb.events.util;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import com.idb.events.Event;
    public class XMLBuilder {
    This attribute represents the XML version
         private static final double VERSION_NUMBER = 1.0;
    This attribute represents the encoding
         private static final String ENCODING_TYPE = "UTF-16";
         /*Begin of Function to buildXML
    return: String
    input: Event
         public String buildXML(Event event) {
              StringBuffer xmlBuilder = new StringBuffer("<?xml version=\"");
              xmlBuilder.append(VERSION_NUMBER);
              xmlBuilder.append("\" encoding=\"");
              xmlBuilder.append(ENCODING_TYPE);
              xmlBuilder.append("\" ?>");
              xmlBuilder.append("<event>");
              xmlBuilder.append(getEncodedXML(event.getTitle(), "title"));
              xmlBuilder.append(getEncodedXML(event.getOrganizer(), "organizer"));
              xmlBuilder.append("</event>");
              return xmlBuilder.toString();
         /End of Function to buildXML/
         /*Begin of Function to get EncodedXML
    return: String
    input: String,String
         public String getEncodedXML(String xmlString, String tag) {
              StringBuffer begin = new StringBuffer("");
              if ((tag != null) || (!tag.equalsIgnoreCase("null"))) {
                   begin.append("<").append(tag).append(">");
                   begin.append("<![CDATA[");
                   begin.append(xmlString).append("]]>").append("</").append(
                        tag).append(
                        ">");
              return begin.toString();
         /End of Function to get EncodedXML/
         /*Begin of Function to get formated date
    return: String
    input: Date
         private final String formatDate(Date inputDateStr) {
              String date;
              try {
                   SimpleDateFormat simpleDateFormat =
                        new SimpleDateFormat("yyyy-MM-dd");
                   date = simpleDateFormat.format(inputDateStr);
              } catch (Exception e) {
                   return "";
              return date;
         /End of Function to get formated date/
    Code for XMLParser:-
    Created on Apr 12, 2006
    Author-Anish
    This is a parser class
    package com.idb.events.util;
    import java.io.ByteArrayInputStream;
    import java.io.IOException;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
    import org.xml.sax.InputSource;
    import org.xml.sax.SAXException;
    import org.xml.sax.XMLReader;
    import com.idb.events.Event;
    import com.sap.tc.webdynpro.progmodel.api.IWDMessageManager;
    public class XMLParser {
    Enables namespace functionality in parser
         private final boolean isNameSpaceAware = true;
    Enables validation in parser
         private final boolean isValidating = true;
    The SAX parser used to parse the xml
         private SAXParser parser;
    The XML reader used by the SAX parser
         private XMLReader reader;
    This method creates the parser to parse the user details xml.
         private void createParser()
              throws SAXException, ParserConfigurationException {
              // Create a JAXP SAXParserFactory and configure it
              SAXParserFactory saxFactory = SAXParserFactory.newInstance();
              saxFactory.setNamespaceAware(isNameSpaceAware);
              saxFactory.setValidating(isValidating);
              // Create a JAXP SAXParser
              parser = saxFactory.newSAXParser();
              // Get the encapsulated SAX XMLReader
              reader = parser.getXMLReader();
              // Set the ErrorHandler
    This method is used to collect the user details.
         public Event getEvent(
              String newsXML,
              XMLHandler xmlHandler,
              IWDMessageManager mgr)
              throws SAXException, ParserConfigurationException, IOException {
              //create the parser, if not already done
              if (parser == null) {
                   this.createParser();
              //set the parser handler to extract the
              reader.setErrorHandler(xmlHandler);
              reader.setContentHandler(xmlHandler);
              InputSource source =
                   new InputSource(new ByteArrayInputStream(newsXML.getBytes()));
              reader.parse(source);
              //return the results of the parse           
              return xmlHandler.getEvent(mgr);
    Code for XMLHandler:-
    Created on Apr 12, 2006
    Author-Anish
    This is a parser class
    package com.idb.events.util;
    import java.io.ByteArrayInputStream;
    import java.io.IOException;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
    import org.xml.sax.InputSource;
    import org.xml.sax.SAXException;
    import org.xml.sax.XMLReader;
    import com.idb.events.Event;
    Created on Apr 12, 2006
    Author-Anish
    *This handler class is created to have constant value for variables and function for get events,
        character values for bean variable,
        parsing thr date ......etc
    package com.idb.events.util;
    import java.sql.Timestamp;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Locale;
    import org.xml.sax.Attributes;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    import org.xml.sax.helpers.DefaultHandler;
    import java.util.*;
    import com.idb.events.Event;
    import com.sap.tc.webdynpro.progmodel.api.IWDMessageManager;
    public class XMLHandler extends DefaultHandler {
         private static final String TITLE = "title";
         private static final String ORGANIZER = "organizer";
         IWDMessageManager manager;
         private Event events;
         private String tagName;
         public void setManager(IWDMessageManager mgr) {
              manager = mgr;
    This function is created to get events
         public Event getEvent(IWDMessageManager mgr) {
              manager = mgr;
              return this.events;
    This function is created to get character for setting values through event's bean setter method
         public void characters(char[] charArray, int startVal, int length)
              throws SAXException {
              String tagValue = new String(charArray, startVal, length);
              if (TITLE.equals(this.tagName)) {
                   this.events.setTitle(tagValue);
              if (ORGANIZER.equals(this.tagName)) {
                   String orgName = tagValue;
                   try {
                        orgName = getOrgName(orgName);
                   } catch (Exception ex) {
                   this.events.setOrganizer(orgName);
    This function is created to parse boolean.
         private final boolean parseBoolean(String inputBooleanStr) {
              boolean b;
              if (inputBooleanStr.equals("true")) {
                   b = true;
              } else {
                   b = false;
              return b;
    This function is used to call the super constructor.
         public void endElement(String uri, String localName, String qName)
              throws SAXException {
              super.endElement(uri, localName, qName);
         /* (non-Javadoc)
    @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
    This function is used to call the super constructor.
         public void fatalError(SAXParseException e) throws SAXException {
              super.fatalError(e);
    This function is created to set the elements base on the tag name.
         public void startElement(
              String uri,
              String localName,
              String qName,
              Attributes attributes)
              throws SAXException {
              this.tagName = localName;
              if (ROOT.equals(tagName)) {
                   this.events = new Event();
         public static void main(String a[]) {
              String cntry = "Nigeria";
              XMLHandler xml = new XMLHandler();
              ArrayList engList = new ArrayList();
              engList = xml.getCountries();
              ArrayList arList = xml.getArabicCountries();
              int engIndex = engList.indexOf(cntry);
              System.out.println("engIndex  :: " + engIndex);
              String arCntryName = (String) arList.get(engIndex);
              System.out.println(
                   ">>>>>>>>>>>>>>>>>>>>" + xml.getArabicCountryName(cntry));
    Hope that may help you.
    If need any help , you are most welcome.
    Regards,
    Deepak

  • How to create multiple files with Receiver File Adapter in SAP PI 7.31 Java Stack

    Dear Friends,
    I am using Sender JDBC Adapter and Receiver File Adapter in Integration Flow in SAP PI 7.3 EHP 1 SP08 Java Stack environment. The requirement is that we need to create multiple files based on the row count in jdbc resultset. If there are 5 rows in resultset, we need to create 5 XML files with one row elements in one file. Similarly if there are 10 rows, we need to create 10 XML files.
    So how can we create multiple files in this scenario. I tried placing a for loop in the Java Mapping as below in the transform method:
    DynamicConfiguration conf = arg0.getDynamicConfiguration();
    StringBuffer sbFileData = new StringBuffer();
    for (int i =0; i < record.size(); i++ {
         . // Create XML for each row and Marshal the object into to the String Buffer
         String strFileName = "DC_" + new SimpleDateFormat("ddMMyyyyHHmm").format(new java.util.Date())+"_"+i+".xml";
         conf.put(KEY_FILENAME, strFileName);
         arg1.getOutputPayload().getOutputStream().write(sbFileData.toString().getBytes("UTF-8"));
         arg1.getOutputPayload().getOutputStream().flush();
    So here I'm flushing the OutputStream for each record. But it's not creating the multiple file, instead it creates only one file will all record XMLs appended to each other.
    Please let me know if I missing something or need to do some thing else.
    Regards,
    Shreyansh Shah

    Hi
    You can easily achieve this using graphical mapping.  Create your target message type like below
    MT_Target
      Details  0 to 1
          Data  0 to 1
    Source sample structure
    <resultset>
    <row>
    <column-name>column-value</ column-name>
    </row>
    Then do the message mapping like below
    map <row> with  MT_Target
    contant ----> Deatils
    column-name ------>Data
    In the signature tab of message mapping, choose the occurrence of your target message type as
    0 to unbounded.
    This will generate multiple files from multiple rows.
    Let me know if you have any doubt.

Maybe you are looking for

  • [JS] How to break link to paragraph style from script?

    I don't found the command break link to paragraph style from script. I want "unapply" the style from the text, but leave the formatting intact. Can help me?

  • Instantiate class with a private constructor

    How do you call a class that happens to have a private constructor. how would one instantiate such a class? Generally constructors are supposed to be public. But in many cases the constructor for a class can be private, so how to call such a class?

  • Scheduled TMS_ # TMS_TP_IMPORT  background jobs fail with error code 0232

    Is anyone else having the problem we've just encountered since upgrading to ECC 6.0 and CRM 2007, where once setting up the automatic import ALL background jobs, to have all of the Transport Change Requests imported into the Q-Prod testing systems au

  • How can I customize a number format?

    In the previous numbers release (Numbers 9) there was a menu were you were able to customize a number format similar to what you can do with Excel. Have they drop this functionality in the new release?

  • Changing URL for E_BUSINESS system

    Hi, how to change URL for E_BUSINESS system ? Should we only edit contexte .xml files and launch autoconfig? Which parameteres ? Many thanks.