Strange problem in converting between XML to string and vice versa

i have an application that needs to send an XML document
over the wire. For this reason, I need to convert the
doc into a String at the sending side and back to Doc
at the receiving side. This document is stored in a "CLOB"
column in a table in the database. I use XDK to retrieve
this entire row (including the CLOB - hence this is an XML
document which has a column that itself is an xml document in
string format - this is just the clob read in by XDK).
Thus the row looks like
<ROWSET>
<ROW>
<col1> A <col1>
<CLOB_COL> ..clob value of an xml doc..</CLOB_COL>
</ROW>
</ROWSET>
When I convert this document into String and back, one of the "<"
tags in the clob column document gets changed to "&lt;" and hence
the parsing fails! I have used the latest label of the XDK build
to get the latest parser jar but still i have the same problem.
I am using the following routines for the conversion.
/* for converting document to string */
public static String convertToString(XMLDocument xml) throws
IOException
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
xml.print(pw);
String result = sw.toString();
return result;
/* for converting string to document */
public static XMLDocument convertToXml(String xmlStr)
throws
IOException,SAXException
ByteArrayInputStream inStream = new
ByteArrayInputStream(xmlStr.getBytes());
DOMParser parser = new DOMParser();
parser.setPreserveWhitespace(false);
parser.parse(inStream);
return parser.getDocument();

How do you get the XML document? Do you use XSU? You can use:
String str = qry.getXMLString();
to get the result XML document in String.
XSU will escape all of the < and >. Or the the XML document in
one of the column will make the result XML doc not well-formed.
Not quite understand your problem. You can send me your test
case.
i have an application that needs to send an XML document
over the wire. For this reason, I need to convert the
doc into a String at the sending side and back to Doc
at the receiving side. This document is stored in a "CLOB"
column in a table in the database. I use XDK to retrieve
this entire row (including the CLOB - hence this is an XML
document which has a column that itself is an xml document in
string format - this is just the clob read in by XDK).
Thus the row looks like
<ROWSET>
<ROW>
<col1> A <col1>
<CLOB_COL> ..clob value of an xml doc..</CLOB_COL>
</ROW>
</ROWSET>
When I convert this document into String and back, one of the "<"
tags in the clob column document gets changed to "<" and hence
the parsing fails! I have used the latest label of the XDK build
to get the latest parser jar but still i have the same problem.
I am using the following routines for the conversion.
/* for converting document to string */
public static String convertToString(XMLDocument xml) throws
IOException
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
xml.print(pw);
String result = sw.toString();
return result;
/* for converting string to document */
public static XMLDocument convertToXml(String xmlStr)
throws
IOException,SAXException
ByteArrayInputStream inStream = new
ByteArrayInputStream(xmlStr.getBytes());
DOMParser parser = new DOMParser();
parser.setPreserveWhitespace(false);
parser.parse(inStream);
return parser.getDocument();

Similar Messages

  • Convert char to ascii code and vice versa

    HI
    Is there any function module to convert char to ascii code and vice versa.
    Thanks in advance

    Hi,
    be careful if you have unicode running in your system. URL_ASCII_CODE_GET is platform-dependent so it will return the internal HERX representation of the character in your system - which is hopefully and in most cases ASCII.
    Under unicode, we use double-byte characters here. I tried this function and the result CHAR_CODE is '00' regardless what character I specify for TRANS_CHAR. But the coding is so simple I corrected resultig in this sample code:
    [P]
    convert p_form to ASCII (internal) representation
      DATA:
        l_ofs TYPE syfdpos,
        l_len TYPE sy-linsz,
        l_ascii TYPE i.
      FIELD-SYMBOLS:
        <x> TYPE x.
      l_len = STRLEN( p_ascii ).
      DO l_len TIMES.
        l_ofs = sy-index - 1.
        ASSIGN p_ascii+l_ofs(1) TO <x> CASTING.
        l_ascii = <x>.
        WRITE: l_ascii.
      ENDDO.
    [/P]
    Here, for each character of string p_ascii, the internal (ASCII) representation is determined and written to the output list.
    Regards,
    Clemens

  • How to convert XML doc to string and vice versa?

    Assume I have a XML doc and I want to convert it into a string (and put it into a string variable).
    How can I do this?
    How can I do the opposite: Convert a string content into a XML doc?
    Peter

    Use:
    ParseEscapedXML() and ora:getContentAsString()
    See
    http://www.codeguru.com/cpp/sample_chapter/article.php/c10789__7/
    Marc

  • How to convert ascii value into character and vice versa

    Hello the java world people,
    I want to convert each characters from my array into their corespondent ascii value and vice versa, how can I do that ?

    The term "ASCII" is often used very loosely.
    Java char values are UNICODE and the ASCII codes are indentical to UNICODE characters in the range 0 .. 127. UNICODE values 128 and above don't have coresponding ASCII values, though 128-255 corespond to ISO-8859-1 which is one of the encodings often called "extended ASCII".
    As shown above you can covert between chars and coresponding int value simply with a cast, but you should be aware that the more exotic characters will not give you sensible values.

  • Xml to dom and vice versa

    Hello
    I want to modify my current program in order to parse the created dom to a new xml file
    Can anyone explain how / help me to do that?
    Thanks in advance !
    //the code below parse an xml to dom
    import java.io.File;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import java.util.*;
    public class XMLReader {
            public static void main(String argv[]) {
                    try {
                            File file = new File("personnel.xml");
                            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                            DocumentBuilder db = dbf.newDocumentBuilder();
                            Document doc = db.parse(file);
                            doc.getDocumentElement().normalize();
                            System.out.println("Personnel" + doc.getDocumentElement().getNodeName());
                            NodeList nodeLst = doc.getElementsByTagName("person id");
                            System.out.println("Information of all employees");
                            ArrayList<Employee> empList = new ArrayList<Employee> ();
                            for (int s = 0; s < nodeLst.getLength(); s++) {
                                Employee emp = new Employee ();
                                    Node fstNode = nodeLst.item(s);
                                    if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
                                            Element fstElmnt = (Element) fstNode;
                                            NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("firstname");
                                            Element fstNmElmnt = (Element) fstNmElmntLst.item(0);
                                            NodeList fstNm = fstNmElmnt.getChildNodes();
                                            System.out.println("First Name : " + ((Node) fstNm.item(0)).getNodeValue());
                                            emp.firstName = ((Node) fstNm.item(0)).getNodeValue();
                                            NodeList lstNmElmntLst = fstElmnt.getElementsByTagName("lastname");
                                            Element lstNmElmnt = (Element) lstNmElmntLst.item(0);
                                            NodeList lstNm = lstNmElmnt.getChildNodes();
                                            System.out.println("Last Name : " + ((Node) lstNm.item(0)).getNodeValue());
                                            emp.lastName = ((Node) fstNm.item(0)).getNodeValue();
                    } catch (Exception e) {
                            e.printStackTrace();
    class Employee {
        public String person_id;
        public String firstName;
        public String lastName;
        public Address address;
        public String phone;
    class Address {
        public String street;
        public String house_number;
        public String town;
        public String zip;
    }

    Oops sorry i just want to create a method which saves the created dom document as an xml file.
    Thanks in advance !

  • Converting PC data to AppleWorks and vice versa

    Background: I am working with a high school reunion class administrator who has emailed me a mailing list file in a PC Excell spreadsheet format. I can read this in AppleWorks (6). He is asking me to put this in a database format where we can use this for mailing labels. He is asking me to send this back to him in MS Works format (He has PC MS Works not Mac MS Works) however he is using an Intel Mac preferring the Windows XP over OSX. I do not have MS Works only AppleWorks. Is all the above possible with AppleWorks? Can I put the data from the spreadsheet into a database format, and does that require I cut and paste everything? Once I get it into an AppleWorks database how do I put it into MS Works database format or something he can read into MS Works database format, and email it to him? First time experimenting with this and hope it will work out. Thanks in advance for any help. CAB
    Mac mini Intel/iBook G3   Mac OS X (10.4.5)   Mac OSX (10.3.5) for iBook

    My open question is how to take Excel data (.xls) and make a Apple Works database file? Must I cut and paste each name, address, phone #, email from Excel to Appleworks DB? Is there any other way?
    You should be able to copy and paste the entire data set in one move, provided you have an AppleWorks DB set up to receive the data.
    Create the AW DB, adding the fields in the same order as the columns of the Excel spreadsheet.
    Open the spreadsheet in Excel or as an AppleWorks spreadsheet.
    Select and copy all of the block of cells containing data.
    Click on the first (empty) record of the database document so the the whole record is highlighted (ie. click on the record, but not in a field, or in List view, click on the small square to the left of the first row), then Paste.
    Your data should be pasted in, creating one record in the DB for each line on the spreadsheet.
    Regards,
    Barry

  • How to convert from UNICODE (UTF16) to UTF8 and vice-versa in JAVA.

    Hi
    I want to insert a string in format UTF16 to the database. How do I convert from UTF16 to UTF8 and vice- versa in JAVA?. What type must the database field be? Do I need a special set up for the database (oracle 8.i)?
    thanks
    null

    I'm not sure if this is the correct topic, but we are having problems accessing our Japanese data stored in UTF-8 in our Oracle database using the JDBC thin driver. The data is submitted and extracted correctly using ODBC drivers, but inspection of the same data retrieved from the GetString() call using the JDBC thin driver shows frequent occurrences of bytes like "FF", which are not expected in either UTF8 or UCS2. My understanding is that accessing UTF8 in Java should involve NO NLS translation, since we are simply going from one Unicode encoding to another.
    We are using Oracle version 8.0.4.
    Can you tell me what we are doing wrong?
    null

  • Problem in converting ASCII value in Dev. and Production

    Hi...
    The ASCII values for # differ in the development and the production system.
    The code below (value 0009 ) populates # in the variable lv_sep.
    DATA: lv_sep TYPE x.
    FIELD-SYMBOLS : <field> TYPE x.
    ASSIGN lv_sep TO <field> CASTING TYPE x.
    <field> = 0009.
    The the development # = 0009 and in production # = 1000.
    Need to know why is this happening.

    How do you get the XML document? Do you use XSU? You can use:
    String str = qry.getXMLString();
    to get the result XML document in String.
    XSU will escape all of the < and >. Or the the XML document in
    one of the column will make the result XML doc not well-formed.
    Not quite understand your problem. You can send me your test
    case.
    i have an application that needs to send an XML document
    over the wire. For this reason, I need to convert the
    doc into a String at the sending side and back to Doc
    at the receiving side. This document is stored in a "CLOB"
    column in a table in the database. I use XDK to retrieve
    this entire row (including the CLOB - hence this is an XML
    document which has a column that itself is an xml document in
    string format - this is just the clob read in by XDK).
    Thus the row looks like
    <ROWSET>
    <ROW>
    <col1> A <col1>
    <CLOB_COL> ..clob value of an xml doc..</CLOB_COL>
    </ROW>
    </ROWSET>
    When I convert this document into String and back, one of the "<"
    tags in the clob column document gets changed to "<" and hence
    the parsing fails! I have used the latest label of the XDK build
    to get the latest parser jar but still i have the same problem.
    I am using the following routines for the conversion.
    /* for converting document to string */
    public static String convertToString(XMLDocument xml) throws
    IOException
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    xml.print(pw);
    String result = sw.toString();
    return result;
    /* for converting string to document */
    public static XMLDocument convertToXml(String xmlStr)
    throws
    IOException,SAXException
    ByteArrayInputStream inStream = new
    ByteArrayInputStream(xmlStr.getBytes());
    DOMParser parser = new DOMParser();
    parser.setPreserveWhitespace(false);
    parser.parse(inStream);
    return parser.getDocument();

  • Where's the best place to get code converted between ActionScript 2.0 and 3.0?

    Where's the best place to get code converted between ActionScript 2.0 and 3.0?
    If I just have occasional (very small) projects, what's the best way to get them done really fast by somebody who knows both 2.0 and 3.0?
    Thanks, Dan

    You have pretty much answered your own question... hire someone who has fairly thorough knowledge of both AS2 and AS3.
    I have heard there are some tools for converting between AS2 and AS3, but I have no knowledge of them other than having heard that they cannot convert all things.... which makes sense because there is not always a one-to-one relationship to how things ae done with AS2 and how they get done with AS3.

  • How to convert a data set into a xml data and vice versa

    i am new to oracle with xml..
    my aim is to convert a data set into a xml data and vice versa..
    my work is as follows...
    my query:
    select rggpk,rggcode,rggname from ms_regiongeo
    to convert a data set into a xml*
    select XMLType(trim(replace(dbms_xmlgen.getXML('select rggpk,rggcode, rggname from ms_regiongeo'),'<?xml version="1.0"?>',''))) XML_DATA from dual;
    (this works fine and output of this query is as follows..)
    <ROWSET>
    <ROW>
      <RGGPK>201</RGGPK>
      <RGGCODE>Asia</RGGCODE>
      <RGGNAME>Asia</RGGNAME>
    </ROW>
    <ROW>
      <RGGPK>1</RGGPK>
      <RGGCODE>OTH</RGGCODE>
      <RGGNAME>Others</RGGNAME>
    </ROW>
    <ROW>
      <RGGPK>21</RGGPK>
      <RGGCODE>COB</RGGCODE>
      <RGGNAME>Africa and Yemen</RGGNAME>
    </ROW>
    <ROW>
      <RGGPK>2</RGGPK>
      <RGGCODE>AUS</RGGCODE>
      <RGGNAME>Australia</RGGNAME>
    </ROW>
    <ROW>
      <RGGPK>23</RGGPK>
      <RGGCODE>IND</RGGCODE>
      <RGGNAME>Indian Sub Continent</RGGNAME>
    </ROW>
    <ROW>
      <RGGPK>24</RGGPK>
      <RGGCODE>TVM</RGGCODE>
      <RGGNAME>North America</RGGNAME>
    </ROW>
    </ROWSET>
    and to reverse this process, I tried a query like this..*
    select EXTRACTVALUE (XML_DATA,'ROWSET/ROW/RGGPK') as EMP_ID
    from(
            select XMLType(trim(replace(dbms_xmlgen.getXML('select rggpk,rggcode, rggname from ms_regiongeo'),'<?xml version="1.0"?>',''))) XML_DATA from dual
    )tab1but failed.. and raised with an eror: ORA-19025
    help me..
    regards,
    john

    Hi-
    my aim is to convert a data set into a xml data  You can refer to the below posts
    Adding namespace to XML output
    Re: how to convert table data in xml format based on the xsd.

  • HT1296 I'm having difficulty syncing my iCal between my home computer and iPhone.  New entries from my home are not syncing with the phone and vice-versa.  I didn't have any problems with this before until the latest phone update.  Any suggestions?

    I'm having difficulty syncing my iCal between my home computer and iPhone.  New entries from my home are not syncing with the phone and vice-versa.  I didn't have any problems with this before until the latest phone update.  Any suggestions?

    It could be that the existing wire in your appartment is not clean enough to provision DSL only. When combined with the phone possibly it has a higher line voltage and worked before. Now that the line is to be provisioned without phone service it may be giving them trouble that did not show before they came out and ran the new line test. So a new jack dedecated for your DSL line may require a new wire be run to your appartment. Also the account for internet only used to require direct billing to a credit card or something else. This was a number of years ago. Most accounts are linked to a phone number, and without a voice number it adds to the confusion.
    If you are getting the voice and everything turned on as before, then I am at a loss for words.

  • Help needed XML to Internal table and vice versa

    Hello frnds, I need to convert Internal table to XML and Vice versa.
    Now I am able to most of the part except for this...
    the xml which I have to generate looks something like this...
    - <trade_dt>
    - <![CDATA[ 20111108000000:20111108235959
      ]]>
      </trade_dt>
    its a range I think
    And then the reponse which I get back the XML is like
    - <lockinfo>
    - <![CDATA[
    TRD_HEADER     1045     1          2
    ACT_CASHFLOW     1042               1
    TRD_TERM     1045               2
      ]]>
      </lockinfo>
    Is there any provision in class cl_ixml or class if_ixml_element to handle this part.....
    Edited by: Amit Sawant on Dec 28, 2011 3:51 PM

    Hello Amit,
    I would suggest you, to use the XSL-Transformations, which can be inbound used in ABAP.
    For example:
    DATA:
      l_xml       TYPE string,
      lt_flights  TYPE TABLE OF SFLIGHT.
    SELECT * FROM SFLIGHT INTO TABLE LT_FLIGHT.
    CALL TRANSFORMATION id
      SOURCE DATA = lt_flights
      RESULT XML l_xml.
    Now, you have a XML-String which is in the ABAP-XML Notation, which means, that ABAP can move this XML-Data back into an internal table/structure.
    For the backward, you have to use the following statement:
    CALL TRANSFORMATION id
      SOURCE XML l_xml
      RESULT DATA = lt_flights.
    As you will see, it is very easy. The Transformation "id" is just one example and build in. When you have to transform the data, or do not want to have the ASX-Notation in it, you should at least define your own transformations with the transaction XSLT_TOOL and use it similar to the transformation "id".
    Kind Regards,
    Hendrik

  • How to convert SOAPEnvelope or SOAPBody to org.w3c.dom.Node and vice versa?

    How to convert javax.xml.soap.SOAPEnvelope or javax.xml.soapSOAPBody to org.w3c.dom.Node and vice versa?If this convertion is very diffcult , how to convert String to org.w3c.dom.Node?
    Thanks a lot

    vj008 wrote:
    while parsing a DOM i want to convert
    org.w3c.dom.Element to xml string and after certain processing on that xml string i want to convert back it to
    org.w3c.dom.Element.[This might help. xml transformations in java. |http://tejaspurohit.blogspot.com/2009/08/xml-transformations-in-java.html]

  • PDF to Word.doc Converter and vice versa

    Hello!
    I am in need of a program capable to convert PDF files to Word documents and vice versa (eventually, a program for each way). The converter needs GUI and must handle images, tables etc. (not just plain text). Does anyone have any tip concering which
    program I should use? It has to be free as my working place has not budgeted with buying 100 licenses. :-)
    Thanks in advance!

    Free? You'll be lucky. Your best bet to achieve your requirements is a PDF compatible OCR application such as Finereader. Free it ain't!
    <IKT-kr> wrote in message news:[email protected]...
    Hello!
    I am in need of a program capable to convert PDF files to Word documents and vice versa (eventually, a program for each way). The converter needs GUI and must handle images, tables etc. (not just plain text). Does anyone have any tip concering which program
    I should use? It has to be free as my working place has not budgeted with buying 100 licenses. :-)
    Thanks in advance!
    Graham Mayor - Word MVP
    www.gmayor.com
    Posted via the Communities Bridge
    http://communitybridge.codeplex.com/

  • Data transfer between SAP & Java and Vice versa using IDOC Process

    Dear Experts,
            We are working on one of the good requirement related to data transfer between SAP and Java software. Client requirement is, they want to transfer the data in both the ways (from SAP --> Java and Vice versa also).
    In detail is, after sales order creation using one custom program loading plan details will be calculated. Once loading dates are confirmed then, user will release the sales document to transfer the data from SAP to Java using "Outbound IDOC processing". Similarly in that JAVA software some shipment details will be performed, once completed from JAVA software again details needs to be pumped back to SAP as "Inbound IDOC Processing".
    For this fields are already identified from external software SAP and we are looking for the same to perform the steps in SAP.
    At this stage, I need your expert opinion  / feedback how to go  about at this stage.
    Meaning,  
                     1. What are the customizing steps needs to be done in SAP..?
                     2. How to trigger the :Outbound IDOC process" once the documents are "Released" from custom transaction
                     3. How to create the link between SAP and JAVA to transfer the data between these 2 software
                     4. How to trigger the "Inbound IDOC Process" from JAVA software to SAP and how to store the data in SAP
    Experts, please give your feedback in terms of reply or by sending the step by step process to fulfill this client requirement.
    Thanks for your cooperation.
    Regards,
    Ramesh

    Maybe too many open questions in the same document.
    Maybe you should repost a more specific question in a technical forum.
    This looks like a small project where you already know what you want, maybe you should contract a technical specialist so he proceeds to the implementation!

Maybe you are looking for

  • How do i change my default player from spotfity to iTunes

    Hi i downloaded sportify and for some reason or another it appears to be my default , so if i try to burn something on disc it keeps coming up can someone please tell me how to change back to itunes, as i have been clicking on every song the open wit

  • Difference between initial upload & delta upload.

    Hi experts, Please tell me the difference between Initial upload & delta upload. please tell me the characteritics of each upload. Thanks & Regards prajith P

  • Acrobat 9 Pro Callout Tool Font Problem

    I am using Adobe Acrobat Pro 9.  I'm trying to change the font and center the text in a callout tool box.  I've tried everything and can't get the font properties to appear.  When I select the properties all I can change are properties related to the

  • Fatal error: fail to load library dxva2.dll

    My PC has Windows XP Professional SP3 and I installed the latest version of Skype. Installation was OK but when I tried to open Skype, the error I've described in the topic's subject appears (the same as the image). How can I fix this problem? Attach

  • Import of SAPK-60301INEAAPPL in the phase DDIC_ACTIVATION broke up

    Hello, while importing the support packages SAPAH60301, SAPKGPID12, SAPK-60301INFICA, SAPK-60301INFICAX i get following error: Error in phase: DDIC_ACTIVATION Reason for error: TP_STEP_FAILURE Return code: 0008 Error message: OCS Package SAPK-60301IN