XML invalid character -  a single quote problem

Hi, I am reading in an xml file, then write the file to output. The problem is that the input file has a strange single quote character [ *�*  ] - lets call it single quoate A, which is different from [  *'*  ] , that is the key next to the [ ; ] key on an English keyboard - lets call it single quate B. And in fact there isnt a key to input single quote A, I guess the appearance of single quote A is due to encoding.
If I open the input xml file in browser, it works ok and displays the single quote A.
Once I read in the xml file into memory, by debugging I can still see that single quote A is corrected encoded;
However once I rewrite the same content to output, the single quote A character is changed, and if i open the file in browser, it says 'invalid character' because single quote A were changed when written to output and cannot be rendered.
Both input and output xml are using UTF-8 encoding. How can I solve this problem please?
The xml file looks:
<?xml version="1.0" encoding="UTF-8" ?>
<content>....1980�s (Peacock and Williams, 1986; Keay, 1984)</content> My code for reading
String _xquery ="//content/text()";
Document _xmlDoc= DocumentBuilderFactory.newInstance().newDocumentBuilder().parse("myxml.xml");
XPath _xpath = XPathFactory.newInstance().newXPath();
NodeList nodes = (NodeList) _xpath.compile(query).evaluate(_xmlDoc, XPathConstants.NODESET);
List<String> res = new ArrayList<String>(nodes.getLength());
for (int i = 0; i < nodes.getLength(); i++) {
    res.add(nodes.item(i).getNodeValue());
String valueToOuput=res.toString() //this is the value to be output to xml, it shoud look like "[....1980�s (Peacock and Williams, 1986; Keay, 1984)]"my code for writing xml
Element root=new Element("root");;
Element content= new Element("output-content")
content.setText(valueToOutput);
root.addContent(content);
PrintWriter writer = new PrintWriter(new FileWriter(f));
new XMLOutputter().output(domDocument, writer);
writer.close();

Hi, sorry I have fixed the problem... instead of using PrintWriter, I used Fileoutputstream, and it solved the problem. Thanks!

Similar Messages

  • Single quot problem

    Hi friends
    Under given code is written in JSP page and passing userid in servlet
    document.form1.action="../servlets/myServelt?userid=abc'"Please check abouve line last character is double quout(") and second last character is single quot ( ' ).
    my problem is when i pass user id in servlet i got questation mark instead of single quot.
    I have to allow single quot in userid due to some reason. so i can't remove single quot.
    please help me how can i got single quot instead of questation mark ?
    Thanks
    virendra

    I don't think you are allowed to pass a single quote (apostrophe) over URLs. Web standards limit the characters that are allowed to be used to make room for protocol features.
    My guess is that you will need to URLEncode the string:
      <% String encodedGoTo = URLEncode("../servlets/myServelt?userid=abc'", "UTF-8"); %>
      document.form1.action="<%=encodedGoTo%>";

  • Mssql single quote problem!

    Hi,
    I user servlet to update MS SQL2000. My problem is there is a single quote inside a text string!
    I can't use double quote for string, as it is not a valid statement for MSSQL. I need to use single quote, but there is single quote inside the string, how can I handle the string?
    String mstrnig="I'm a boy";
    String mSQL = "UPDATE news SET " + "title='" + mstring + "' WHERE code =" + mcode;
    Thanks

    the cleanest and easiest soln is to use preparedStatement.
    PreparedStatement ps = con.prepareStatement("update table comment=? where id = ?");
    ps.setString(1,"That's way to do it");
    ps.setInt(1,8);//some itn value
    ps.execute();

  • Single quote problem

    Hi everyone,
    I'm new to sql/plsql and having problems with the following
    and1 := ' AND CS.COMPANY_NAME LIKE ''% ' || 'information' || ' %'' ';
    or1 := ' OR CS.COMPANY_NAME LIKE '' || 'information' || ' %'' ';
    or2 := ' OR CS.COMPANY_NAME LIKE ''% ' || 'information' || '' ';
    dbms_output.put_line(and);
    dbms_output.put_line(or1);
    dbms_output.put_line(or2);
    and1,or1, or2 are declared as varchars. Its giving the following error for the second line (or1):
    83/43 PLS-00103: Encountered the symbol "information" when expecting
    one of the following:
    . ( * @ % & = - + ; < / > in mod not rem an exponent (**)
    <> or != or ~= >= <= <> and or like between is null is not ||
    is dangling
    Any help is greatly appreciated.

    Hi Alex,
    Here is what im trying to do. I am trying to loop through the tokens in company name (compName) in the below example. Lets say compName is 'company information', I need to have the following clauses in my query:
    AND ( CS.COMPANY_NAME LIKE '% company % '
    OR CS.COMPANY_NAME LIKE 'company %'
    OR CS.COMPANY_NAME LIKE '% company' )
    AND ( CS.COMPANY_NAME LIKE '% information % '
    OR CS.COMPANY_NAME LIKE 'information %'
    OR CS.COMPANY_NAME LIKE '% information' )
    At the moment I only have the and clauses and am missing the or clauses. I was having trouble with single quotes and posted the original problem to get a better idea of what was going on. I am completely new to this. Here's the code:
         WHILE end_pos <> 0 LOOP
              end_pos := instr(compName ,' ',start_pos);
              IF end_pos <> 0 THEN
              token_count := token_count + 1;
              token := substr(compName , start_pos, end_pos - start_pos);
              vSQL := vSQL || ' AND CS.COMPANY_NAME LIKE ''% ' || token || ' %'' ';
                        start_pos := end_pos + 1;
                   END IF;
              END LOOP;
              IF token_count = 0 THEN
                   token_count := 1;
                   token := compName ;
                   vSQL := vSQL || ' AND CS.COMPANY_NAME LIKE ''% ' || token || ' %'' ';
                   ELSE
                   token_count := token_count + 1;
                   token := substr(P_COMP_BUS_NAME, start_pos);
                   vSQL := vSQL || ' AND CS.COMPANY_NAME LIKE ''% ' || token || ' %'' ';
              END If;
    Any help or advice is welcome and appreciated.

  • Single Quote problem with javascript

    Hello;
    I have a custom popup search page that work very well most times. if the data that I am passing back to me calling page has a single quote in it the popup page fails. Take a look at this URL that is called and you van see why the single quote is causing the problem.
    javascript:passBackSearch('413','TOM'S GRILL')

    To make it more clear, it should be
    javascript:passBackSearch('413',"TOM'S GRILL") Patrick
    My APEX Blog: http://inside-apex.blogspot.com
    The ApexLib Framework: http://apexlib.sourceforge.net
    The APEX Builder Plugin: http://sourceforge.net/projects/apexplugin/

  • Single quotes problem with execute immediate

    Thanks for considering to solve the issue.
    [i]Situation:
    I am trying to create a procedure to perform a set of operations. As part of that, I am trying to create a table using execute immediate statement. This create table statement has a select sub query where p_LOB3 is the variable for the procedure of datatype varchar2.
    Problem :
    I need to pass the variable p_LOB3 as single quoted as it is of type Varchar2. Also I need to enclose the entire create table query within single quotes. How do I specify this as it is throwing an error when the PL/SQL engine is parsing the single quotes in the query used twice for different purposes as mention earlier.
    Query:
    execute immediate'create table test5 as select min(contract_number)as contract_number,contact_id,max(line_of_business) as line_of_business from mytable group by contact_id having min(contract_number) = max(contract_number) and max(Line_of_business) = 'p_LOB3' ';

    Thank you Todd,
    Is just worked fine.
    New issue is: I am not able to put 2 such statements in a single procedure and execute. Before I give parameters to the procedure, PL/SQL engine is actually creating a view of the mytable and naming is as test5, as a result I am not able to create a table as there is a view with the same name.
    Right now, the workaround I am using is to create three different procedures to create three such tables. I know this is not a good idea....can you please tell me if there is a better way.
    Procedure
    CREATE OR REPLACE PROCEDURE SP_CREATE_0_0(p_LOB1 IN varchar2, p_LOB2 IN varchar2)
    IS
    BEGIN
    execute immediate 'create table test5 as select min(contract_number) as
    contract_number,contact_id,max(line_of_business) as line_of_business from
    mytable group by contact_id having min(contract_number) = max(contract_number)
    and max(Line_of_business) = ' ' ' || p_LOB1 || ' ' ' ';
    execute immediate 'create table test5 as select min(contract_number) as
    contract_number,contact_id,max(line_of_business) as line_of_business from
    mytable group by contact_id having min(contract_number) = max(contract_number)
    and max(Line_of_business) = ' ' ' || p_LOB1 || ' ' ' ';
    END SP_CREATE_0_0;
    /

  • XI XML Parser: tag content with "'", single apostrophe: invalid character

    Hi all,
    we import XML-documents with the file adapter in a sender channel. everything works well.
    But if one of the XML-tag contents contains a single apostrophe ( ' ), then the XML parser stops with an error "An invalid character was found inside an entity reference. ". The message can not be processed. If I test the message content in the mapping -> no error.
    When the single apostrophe is dereferenced by an additional single apostrophe the XML-File can be processed.
    Question: does anybody know how this can be handled because it is not very nice of SAP XI to send single apostrophes in outgoing messages but cannot handle it in incoming messages from other systems? special adapter settings?
    Thank you very much
    regards
    Hans

    check bhavesh reply
    Suppress Special Character
    also check
    https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/9420 [original link is broken] [original link is broken] [original link is broken]
    Implementing a Java Mapping in SAP PI to remove Escape Sequences from a file

  • XML Publisher Report ends with Warning -- Invalid Character Error in XML

    Hi,
    I have migrated the standard report 'Invoice Print Selected Invoices' from Reports 6i to XML Publisher. It has to print a Euro(€) in the report. It does not even generate the XML File fully. It gives the below error in the XML File. When i remove the special character, it works fine.
    Please let me know the settings to ensure that XML file also accepts the special characters. How do i get the Euro symbol printed in XML File with out giving Invalid Character Error?
    ===========================================================The XML page cannot be displayed
    Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again
    later.
    An invalid character was found in text content. Error processing resource 'http://dfw1svdevapp03.ora.rackspace.com:8040/OA_...
    <C_INV_CURRENCY_SYMBOL>
    N class="m">>
    <LINE_UOM />
    <LINE_UNIT_SELLING_PRICE />
    ===========================================================
    The XML File even does not show which character set it uses. The output file starts with:
    ===========================================================
    <?xml version="1.0" ?>
    - <!-- Generated by Oracle Reports version 6.0.8.25.0
    -->
    ===========================================================

    Hi Tim,
    Thanks for your adhoc response.
    I have gone thru the Document 222663.1 and it says that the Developer 6.0.8.23 is required to handle this problem. We are using almost the updated Developer version i.e., Developer 6.0.8.25. So, this should be handled automatically, but it still errors out. Please suggest.
    Thanks,
    Kesava

  • Problem in insertion with string containing   ' (single quote)

    i have a text field in jsp.
    when i submit the content need to be inserted/updated.
    when the text field contains character's with single quote( ' )..
    i am unable to insert/update values in database..
    where as if the text field contains characters without single quote..there is no problem in Database insertion/updation.
    i am using create statement .. and oracle database..
    can any one help ...

    The usual answer for this in the JDBC forum (where this should have been posted because it's completely about JDBC) is to use a PreparedStatement.

  • Change XML declaration from single quote to double quote

    Hi all,
    i have the following problem in my File Receiver Adapter. My XML File has the declaration <?xml version='1.0' encoding='utf-8'?> (With single quotes ') and want to change it to <?xml version="1.0" encoding="utf-8" ?> (With double quotes ")
    I use the XMLAnonymizerBean but this does not change the XML declaration.
    Any ideas how to change the declaration
    Thanks Max

    Hi Suraj,
    on the Modul Tab i have the following:
    1 | AF_Modules/XMLAnonymizerBean | Local Enterprise Bean | Anonymizer
    2 | CallSapAdapter                                | Local Enterprise Bean | 0
    Anonymizer | anonymizer.acceptNamespaces | http://Post.AG/PartnerInterface/Schemas/PVSdeAt/Aviso_V1.0 ns0 http://PostAG.PartnerInterface.Schemas.PVS_deAt.AvisoHeader ns1 http://PostAG.PartnerInterface.Schemas.PVS_deAt.AvisoShipper ns2
    Anonymizer | anonymizer.quote                        | "
    That is all what i have on the module tab.
    I send the data as Text (not Binär). Thats all what i have in the adapter. Do you need any further information?
    Regards, Max

  • LPX-00217 invalid character error - Using reference characters in XML file

    Hi, I hope you will help me to understand and to fix the error I get during insert of an XML file into a table with XML Type field.
    I used Oracle documentation for this:
    1. Create table
    CREATE TABLE XMLDOC
    ( XMLCOLUMN xmltype);
    2. Create external directory
    CREATE OR REPLACE DIRECTORY FILESDIR AS 'E:\ora_xml_test\';
    3. Create function
    CREATE OR REPLACE function DSS.getClobDocument(
    filename in varchar2,
    charset in varchar2 default NULL)
    return CLOB deterministic
    is
    file bfile := bfilename('FILESDIR',filename);
    charContent CLOB := ' ';
    targetFile bfile;
    lang_ctx number := DBMS_LOB.default_lang_ctx;
    charset_id number := 0;
    src_offset number := 1 ;
    dst_offset number := 1 ;
    warning number;
    begin
    if charset is not null then
    charset_id := NLS_CHARSET_ID(charset);
    end if;
    targetFile := file;
    DBMS_LOB.fileopen(targetFile, DBMS_LOB.file_readonly);
    DBMS_LOB.LOADCLOBFROMFILE(charContent, targetFile,
    DBMS_LOB.getLength(targetFile), src_offset, dst_offset,
    charset_id, lang_ctx,warning);
    DBMS_LOB.fileclose(targetFile);
    return charContent;
    end;
    And now appears the problem when I use different character references - one of them are parsed by the XML parser and another -are not:
    test1.xml - Contains a charachter from Latin language -ă (&#x103)
    <?xml version="1.0" encoding="UTF-8"?>
    <ROWSET>
    <ROW
    <IDNO>1</IDNO>
    <NAME>aaa (&#x103)</NAME>
    </ROW>
    </ROWSET>
    --a semicolumn must be added after 103
    SQL> insert into XMLDOC values(xmltype(getClobDocument('test1.xml','UTF8')));
    1 row created.
    test2.xml - Contains a charachter from Cyrillic language -ш (&#x404)
    <?xml version="1.0" encoding="UTF-8"?>
    <ROWSET>
    <ROW>
    <IDNO>1</IDNO>
    <NAME>aaa (&#x404)</NAME>
    </ROW>
    </ROWSET>
    --a semicolumn must be added after 404
    SQL> insert into XMLDOC values(xmltype(getClobDocument('test2.xml','UTF8')));
    insert into XMLDOC values(xmltype(getClobDocument('test2.xml','UTF8')))
    ERROR at line 1:
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00217: invalid character 1028 (\u0404)
    Error at line 5
    ORA-06512: at "SYS.XMLTYPE", line 0
    ORA-06512: at line 1
    I am not familiar to Unicode and encoding maybe I ' missing something.
    Please help!!!

    Which database version are you using and what is the characterset used during its creation...?
    There is a lot on this forum which has been already answered / addressed but the database must support it, in other words the characterset must support it. Among others, see Re: XML-Document with special characters for instance.
    Conversion like you are doing (&#x103) is not needed.

  • Need Double quotes instead of Single quotes in output XML version header

    In XML output generated by XDODTEXE executable, its observed that header row looks like this:
    <?xml version = '1.0' encoding = 'UTF-8'?>
    It should look like this:
    <?xml version="1.0" encoding="UTF-8"?>
    Browsers like IE deceive. Opening the XML in Text editors show single quotes and spaces.
    Data Template and XSL template files have proper headers with double quotes.
    The output XML file is rejected by a Government Authority as parsing the header line fails.
    Are there any ways to configure this?

    I dont know if this has anything to do with my problem or not, but I thought I should add this:
    When a user is filling out the form that has the textarea,  they put whatever text they want into the textarea field.
    textarea name="text"></textarea
    Then, they click on a 'Continue' button and the system shows them a preview of what they are about to have inserted
    into the database.
    Within the code on this preview page is a hidden field, which holds the contents of their textarea data so it can be
    passed on through the process once the user verifies the preview.
    This is done using this: input type="hidden" name="text" value="<cfoutput>#text#</cfoutput>"
    Like I said, I don't know if that has anything to do with this problem, but thought it might be good to mention it
    Kudos

  • Invalid character in XML

    Hi,
    I'm trying to parse this public comment feed, which had been working until recently -
    http://www.ntia.doc.gov/broadbandgrants/btopcomments.xml
    - when I started getting this error -
    "An error occured while Parsing an XML document. An invalid XML character (Unicode: 0x14) was found in the element content of the document."
    I'm trying to strip out the character using this replace command, but it doesn't seem to be working.
    XMLText = rereplace(XMLText, chr(14),"","ALL");
    Any ideas?
    thanks!

    EDIT: You can ignore this one, I think! I was typing my response and didn't see your recent post until after I submitted. I'll leave it in case the curly quote details help at all.
    Hi, Wingo,
    I was able to get the feed to parse without the Base64 sections but I think of that more as a trouble-shooting step than a solution because I wanted to see if there was an odd character (or more) in these elements.
    A perusal skimmed the ATOM documents this morning related to Base64 (if I recall from reading the feed, it was an ATOM feed and not an RSS feed) at http://www.atomenabled.org/developers/syndication/atom-format-spec.php, indicates there should not be any issues with Base64 content in the feed.
    I also tested the feed with a PHP ATOM parser this morning. I just wanted to see if another server-side language could do it. Nope! PHP threw an invalid character at line 1243. Of course, the line number PHP/ColdFusion see does not necessarily match what we see when we copy the XML into a new file.
    After testing the feed with PHP, I downloaded the feed XML again (in case it was updated since I messed with it the other day) and started to check in the area around this line number. I saw something of potential interest: a lot of instances of what I think are curly quotes in the document.
    Search for the test "inherently competing definitions of". Immediately following the word "of " are two funny symbols and then the words 'public interest'. If looks almost like someone had curly quotes around these words and, I believe, curly quotes can cause issues in XML parsing. A document search for this 'character' revealed many of them, all in places that look like a curly quote would go (they were typically in long blocks of text.
    Sorry not to be of more help but maybe this (the curly quotes) will get things rolling...

  • XML Source error message hexadecimal invalid character

    Hi all
    I am developing a SSIS package to add data from thousands of XML files to an existing SQL Server table. 
    And I get the error message:
    The XML Source was unable to process the XML data. “”hexadecimal value 0x01 , is an invalid character.
    I know that these XML files are not well-formed (and hence not really an XML file).
    So, How to use the SSIS package to solve this problem without using the other editor?

    Thanks Visakh16
    I tried your method, but the xml task showed me an error
    [XML Task] Error: An error occurred with the following error message: 
    “”hexadecimal value 0x01 , is an invalid character.
    My xml file with an invalid
    character before ‘うce☆溪’
    <articles>
    <article>
    <message>ID:うce☆溪&lt;br /&gt;
    &lt;br /&gt</message>
    <message_id>1</message_id>
    </article>
    </articles>
    My xslt file
    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs=http://www.w3.org/2001/XMLSchema xmlns:fn="http://www.w3.org/2005/xpath-functions">
    <xsl:output method="text" version="1.0" encoding="UTF-8" indent="no"/>
    <xsl:template match="/">
    <xsl:text>message,message_id</xsl:text>
    <xsl:text>&#13;&#10;</xsl:text>
    <xsl:for-each select="articles/article">
    <xsl:text>"</xsl:text>
    <xsl:value-of select="message"/>
    <xsl:text>","</xsl:text>
    <xsl:value-of select="message_id"/>
    <xsl:text>"</xsl:text>
    <xsl:text>&#13;&#10;</xsl:text>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

  • Can I quote a single quote character so that I can use it in Replace()

    Hi. How can I quote a single quote character so that I can use it in the Replace() function below. I'm attempting to query first_name records that contain a '.
    select first_name, last_name
    from ttms.prospect
    where instr(first_name,"'") > 0
    ERROR at line 3:
    ORA-00904: "'": invalid identifier

    Hi,
    String literals are enclosed in single-quotes (not double-quotes).
    To use a single-quote within a string literal, use two of them:
    WHERE   INSTR (first_name, '''') > 0In Oacle 10 (and up) you can also use Q-Notation:
    WHERE   INSTR (first_name, q'[']') > 0but you may find this more confusing for short literals containing only one single-quote.
    Edited by: Frank Kulash on Mar 11, 2009 4:52 PM

Maybe you are looking for

  • Can't put firefox into applications

    in downloading firefox - the dmg image that shows the icon and an arrow pointing to the applications has a circle with a line through it. firefox cannot be dragged into applications - it only adds a shortcut to it in the applications folder and stays

  • IChat can't communicate with my AIM account

    Hi, every time i try go to to my ichat it automatically logs me out, and when i try to log back in, it says "iChat can't communicate with the AIM account 'aforever0203' and The AIM server has temporarily limited your account due to too much activity.

  • How do I view fps? and how do I adjust fps in final cut pro x?

    How do I view fps? and how do I adjust fps in final cut pro x?

  • CSV formatting problems

    When I spool my sql results to a csv file some of the fields will get broken up into several columns. For instance, I could have a string: "How are you?" and it would be broken between two columns like "How ar" in one column and "e you?" in another.

  • Question about Ipod/Printer Rebate

    for anyone who used the student/teacher rebates on the ipod and printer, or anyone who purchased a macbook for that matter, do you guys remember a sales receipt that came with your macbook? how about the printer? i am preparing to mail in my rebates