Converting XML string to ABAP types

Hello,
I am having a requirement where i wanted to parse incoming XML string and i checked few of examples of CALL TRANSFORMATION id.
but whatever examples i checked those were simple transformation with no hierarchy.
My source structure
<record>
<firstname>XYZ</firstname>
<position>Testposition</postion>
</record>
and i used
CALL transformation id
source xml lv_xml
result firstname = lv_firstname position = lv_position.
but lv_firstname and lv_position were blank. any idea whether it can be acheived through such method?
thanks in advance.
regards
rajeev

Hello Rajeev,
Try using the following simple transformation
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
  <tt:root name="record"/>
  <tt:template name="record">
    <record>
      <firstname>
        <tt:value ref="record.firstname"/>
      </firstname>
      <position>
        <tt:value ref="record.position"/>
      </position>
    </record>
  </tt:template>
</tt:transform>
In your code you could define a structure like the following:
TYPES: BEGIN OF record,
              firstname TYPE char50,
              position  TYPE char50,
            END OF record.
And now you could use the CALL TRANSFORMATION in your code to convert the xml string into the structure and visa-versa.
CALL TRANSFORMATION zcl_test_rec
      SOURCE XML lv_string
      RESULT record = ls_test.
Where lv_string holds the xml as a string and ls_test is defined as a structure of type record (defined above).
Hope this helps.
Thank you,
Ramneek

Similar Messages

  • Converting XML string to Element Type

    Im receiving an XML document as a String.
    I have defined an element whose message type is of the same schema as the XML String.
    How can i assign this string to this element in BPEL?
    im using the setVariable function as follows:
    setVariableData("Customer","CustomerType", new String(received))
    It does not throw an error. But im unable to retrieve any of the values from this element.
    Could someone pls help me with this?

    The output seems to be fine and structured in the XML Format, when i pass the string to the Message Type(ie CustomerType) rather than the root node (CustomerElement).
    eg: in this case i have
    Customer - > CustomerType -> CustomerElement - > Name, date etc...
    When i assign the string to Customer Element, it displays it as a string.
    When i assign the string to CustomerType it displays it in the XML Structure.
    It however throws an error when i assign an element in the data to something.

  • Convert XML string into an abap format date and time

    Hi,
    Does anyone know of a method or a function module in ABAP which converts XML string into an abap format date and time.
    Here is a part of the xml that I want to convert.
    <ns2:EventDateTime>2009-07-02T10:13:45+10:00</ns2:EventDateTime>
    <ns2:EventMessageTransmissionDateTime>2009-07-02T10:13:45.987+10:00</ns2:EventMessageTransmissionDateTime>
    Currently EventDateTime and EventMessageTransmissionDateTime are type XSDDATETIME_Z and these are converted to proper dates and times. We will be changing these fields to a STRING instead of XSDDATETIME_Z. The reason for this is to make the field more versatile. The customer would be receiving dates with Zulu (2009-09-23T12:00:00Z), with offsets (2009-09-23T12:00:00+10:00/-10:00) and just local timestamp (2009-09-23T12:00:00). With this, we need to make the date fields as string
    to be able to accept the various date formats (esp. the local timestamp).
    I am looking for a standard function module or method that will convert the xml string to a proper date and time abap format.
    Would appreciate anyone's help!
    Thanks.
    Edited by: eunice ocson on Jul 13, 2009 1:49 AM
    Edited by: eunice ocson on Jul 13, 2009 1:50 AM
    Edited by: eunice ocson on Jul 13, 2009 1:51 AM
    Edited by: eunice ocson on Jul 13, 2009 1:51 AM

    Hi Eunice
    Use the FM 'SMUM_XML_PARSE'
    for more info
    [Convert XML string to ABAP|XML String to ABAP or GUI]
    hope it helps you.
    Thanks!!

  • Convert XML string into XML

    Hi All,
    Can you please let me know for any sample code in xslt/java mapping for converting XML string into XML. We use SAP Pi 7.0
    My XML string starts like this
    <?xml version="1.0" encoding="UTF-8" ?> 
    - <ns0:MT_ReceiverFileStructure <namespace>"><Output><?xml version="1.0" encoding="ISO-8859-9"?><?xml-stylesheet type="text/xsl" href="<xsl>"?><Tarih_Date Tarih="11.09.2014" Date="09/11/2014>
       Thanks,
       Pavithra

    Thanks Praveen. It worked.
    However, the xml i have is an extract from a exchange rate URL and it has the reference to a xsl in it as below
    <?xml version="1.0" encoding="ISO-8859-9"?><?xml-stylesheet type="text/xsl" href="<ABC.xsl>"?>.
    So there is an error in sxmb_moni. Is it possible to remove this.

  • Special charecters handling while Converting XML string to DOM

    Hi,
    I am using the following approach for converting XML string to DOM, but due to Special characters like "&", I am getting Exceptions:
    String xmlString;
    DocumentBuilderFactory factory =
    DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(new InputSource(new StringReader(xmlString)));
    Can anyone please help me out on how to handle the Special characters in the above code.

    If the XML doesn't parse, then the XML must be invalid. Show a sample of such a special character in the XML data. Please use \ tags to post the actual XML content and any other code.                                                                                                                                                                                                                                                                                                                                                                                           

  • Convert XML string into DOM

    Hi all,
    I have a question here regarding converting XML string into a DOM document.
    How can I do this in Java?
    The Document.Parse() methods do not have one that takes in String as its parameter.
    I'm not sure what is the best way to do this in Java.
    Any help is greatly appreciated.
    Thank you in advance.
    regards,
    Sean

    Convert XML String to Document with StringReader.
    String xmlString;
    DocumentBuilderFactory factory =
                DocumentBuilderFactory.newInstance();
                DocumentBuilder builder = factory.newDocumentBuilder();
       Document         document = builder.parse(new InputSource(new StringReader(xmlString)));

  • Xml string to abap internal  table

    HI Experts ,
    I want to parse this XML file to abap internal table ,i read as usual  the Help and i think
    that something is missing on my code.
    There is someone can help.
    The fields is type string and the value is :
    <Containers> <Container workitemid = "00000017" IsParent = "X"><Element name = "_WF" value = "USI029"/><Element name = "_WF_PRIOR" value = "5"/><Element name = "_WF_VERSION" value = "0000"/><Element name = "_WF_NESTING_LEVEL" value = ""/><Element name = "XUBNAME" value = ""/><Element name = "XUACCNT" value = ""/><Element name = "SHORTTEXT" value = ""/><Element name =
    i use the call transformation code and there i put this code:
    <?sap.transform simple?>
    <tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
    <tt:root name="XML_TAB"/>
      <tt:template>
        <Containers>
          <tt:loop name="a" ref=".XML_TAB">
            <Container>
              <tt:attribute name="Element name" value-ref="$a.name"/>
              <tt:attribute name="value" value-ref="$a.value"/>
            </Container>
          </tt:loop>
        </Containers>
      </tt:template>
    </tt:transform>
    I think that i miss something with the line :<Container workitemid = "0000007" IsParent = "X">
    the dump is:
    An exception occurred that is explained in detail below.
    The exception, which is assigned to class 'CX_ST_MATCH_ATTRIBUTE', was not
      caught and
    therefore caused a runtime error.
    The reason for the exception is:
    XML matching error
    Expected was attribute: "Elementname" [ ] Read was element-start: "Container" [
    Please help
    Regards
    Chris
    Edited by: Chris Teb on Aug 6, 2009 9:57 AM

    H Siva,
    Thanks ,
    I try exactly like u tell and i get this dump:
    An exception occurred that is explained in detail below.
    The exception, which is assigned to class 'CX_ST_MATCH_ELEMENT', was not caught
      and
    therefore caused a runtime error.
    The reason for the exception is:
    XML matching error
    Expected was element-end: "Containers" [ ] Read was element-start: "Container"
    <Containers>
        <Container>
            <tt:loop name="a" ref=".XML_TAB">
            <Element >
              <tt:attribute name="name" value-ref="$a.name"/>
              <tt:attribute name="value" value-ref="$a.value"/>
              </Element>
              </tt:loop>
            </Container>
        </Containers> ->**the dump in the debugger is here .**
      </tt:template>
    </tt:transform>
    Any Idea?
    Regards
    Chris

  • Convert XML file into ABAP Query

    Hi All,
    Can we capture a XML file generated from a Non-SAP system in SAP system and convert into ABAP Query to retreive Data from DB and post it back as a XML query to the same Non-SAP system using a Middleware. Can this process be done in cache memory level itself instead of saving in DB.
    If it is possible pls do tell the procedure and steps to be followed.
    Suggestion and Help will be much Appreciated
    Thanks & Regds.
    Ramesh

    Hi check these blogs....
    <a href="/people/r.eijpe/blog/2005/11/21/xml-dom-processing-in-abap-part-ii--convert-an-xml-file-into-an-abap-table-using-sap-dom-approach:///people/r.eijpe/blog/2005/11/21/xml-dom-processing-in-abap-part-ii--convert-an-xml-file-into-an-abap-table-using-sap-dom-approach
    <a href="/people/tobias.trapp/blog/2005/12/08/xml-processing-in-abap--part-6:///people/tobias.trapp/blog/2005/12/08/xml-processing-in-abap--part-6

  • XML: How to convert xml string into Node/Document

    I have a string in xml form.
    <name>
    <first/>
    <second/>
    </name>
    I want to convert this string into DOM Node or Document.
    How can I do this?
    Any help or pointer?
    TIA
    Sachin

    Try this :
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(new org.xml.sax.InputSource(new StringReader(strXml)));Hope this helps.

  • How to convert xml String to xml file?

    Hi,
    I got a method that do the following:
    public static String convertXmlToString(String xmlFileName) throws Exception
            File file = new File(xmlFileName);
            FileInputStream insr = new FileInputStream(file);
            byte[] fileBuffer = new byte[(int)file.length()];
            insr.read(fileBuffer);
            insr.close();
            return new String(fileBuffer);
         }The return String is the contents of an existing xml file and one example is shown below:
    <object type="server.WOXReference" id="0"><field name="actualPathObj"><object type="java.lang.String" id="1">C:\restClient\actualXMLObjects\812856084.xml</object></field><field name="object"><object type="server.WOXConstructor" id="2"><field name="className"><object type="java.lang.String" id="3">rec.SimpleRecognizer</object></field><field name="types"><array type="java.lang.String" length="3" id="4"><object type="java.lang.String" id="5">double[].class</object><object type="java.lang.String" id="6">double.class</object><object idref="6" /></array></field><field name="args"><array type="java.lang.Object" length="3" id="7"><array type="double" length="5" id="8">22.33 33.22 33.33 22.0 11.0</array><object type="java.lang.Double" id="9">2.2</object><object type="java.lang.Double" id="10">3.3</object></array></field><field name="retType"><object type="java.lang.String" id="11">act</object></field></object></field></object>
    and I want to change the above string to xml file like below:
    <object type="server.WOXReference" id="0"><field name="actualPathObj"><object type="java.lang.String" id="1">C:\restClient\actualXMLObjects\812856084.xml</object></field><field name="object"><object type="server.WOXConstructor" id="2"><field name="className"><object type="java.lang.String" id="3">rec.SimpleRecognizer</object></field><field name="types"><array type="java.lang.String" length="3" id="4"><object type="java.lang.String" id="5">double[].class</object><object type="java.lang.String" id="6">double.class</object><object idref="6" /></array></field><field name="args"><array type="java.lang.Object" length="3" id="7"><array type="double" length="5" id="8">22.33 33.22 33.33 22.0 11.0</array><object type="java.lang.Double" id="9">2.2</object><object type="java.lang.Double" id="10">3.3</object></array></field><field name="retType"><object type="java.lang.String" id="11">act</object></field></object></field></object>How to I change the above xml String back to xml file again? The appropriate tags must be taken care of like > must be > and < must be <.
    Please advice and can give me some sample code.
    Thanks.

    By writing some code that runs through the file and adds a new line for a new element using these methods here...
    http://java.sun.com/j2se/1.4.2/docs/api/org/xml/sax/ContentHandler.html
    i.e.
    startDocument()
    startElement(String namespaceURI, String localName, String qName, Attributes atts)
    endDocument()

  • Converting XML string to internal table

    Hello everyone,
    I am trying to convert an XML string to an internal table. The format of the XML string is as follows:
    <node label="Compressors" NODE_ID="783" checked="1" expandStatus="false">
       <node label="Nail guns" NODE_ID="78543" checked="1" expandStatus="false"/>
       <node label="Spray guns" NODE_ID="855" checked="0" expandStatus="false"/>
       <node label="Cleaning equipment" NODE_ID="9" checked="1" expandStatus="false"/>
    </node>
    What I need is an internal table with the fields NODE_ID and checked filled. The hierarchy here doesn't matter, so I just need an internal table of a structure with 2 fields. The whole XML is hierarchical and contains only the <node> tag, which can be self-closing or not with the attributes within the tag.
    What is the best way to accomplish this?
    Performance here is quite important too, as this XML can contain over 100,000 nodes.
    Should it be done with an xpath expression, with a regex, with the iXML parser, an XSLT call transformation?
    Any help is greatly appreciated!
    Best regards,
    Vincent

    Use this FM to get into internal table
                CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'
                  EXPORTING
                    im_xstring = zl_attcntx
                  IMPORTING
                    ex_string  = zl_attcont.
       SPLIT zl_attcont AT cl_abap_char_utilities=>newline INTO TABLE zit_legacy.

  • Converting XML String to MessageElement array

    Hi,
    I am trying to call a .NET web service from my Java client. I used WSDL2Java to generate the java classes for calling the .NET web service. The generated classes to call the service expects an array of org.apache.axis.message.MessageElement objects. I have a string representing an XML document which looks like this:
    String xmlString = "<Results><Adjustments><Adjustment><RebuildAdjustmentID>16</RebuildAdjustmentID><IsBasicAdjustment>true</IsBasicAdjustment><AdjustmentType>stone/AdjustmentType><Title>External walls</Title></Adjustment></Adjustments></Results>"
    I have tried converting the string into an array of MessageElement objects by the following way:
    MessageElement[] m = new MessageElement[1];
    Document XMLDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(result2.toString())));
    m[0] = XMLDoc.getDocumentElement();
    However I keep getting the following message returned from the service:
    "Object reference not set to an instance of an object"
    I have tried a handful of ways but keep getting this same error. I have searched the web for hours looking for a solution to this problem without success so any help/ideas much appreciated,
    Thanks.
    Paul

    Any updates on this?
    I am facing a similar problem.

  • Convert XML-String from Codepage utf-16 to ISO-8859-1

    Hi to all experts,
    our system is now unicode with codepage 4102 (UTF-16) and we do an Simple Transformation for creating an XML-String.
    before UniCode : xml_data = <?xml version="1.0" encoding="iso-8859-1"?>#<transactionRequest userID=" .......
    now with UniCode : xml_data = <?xml version="1.0" encoding="utf-16"?>#<transactionRequest userID=".......
    The xml_data transfered to an external Sytem via HTTPS- Communication direct from ABAP.
    The external Sytem send an Error Request:
    <?xml version="1.0" encoding="ISO-8859-1"?>#<transactionResponse>#    <transactionErrorResponse>#        <errorResponse>#            <errorCode>SYS-0001</errorCode>#            <errorDescription>java.lang.Exception: null[ #<?xml version="1.................
    Have you any idea
    Thanks for your help!
    Peter
    Edited by: Peter Pforr on Sep 25, 2008 9:59 AM
    Edited by: Peter Pforr on Sep 25, 2008 10:14 AM

    Darshan,
    Did you get an answer for this question? We have same requirement to create XML file in ISO-8859-1 format with Attributes is set to "Y" and CDATA is being used for data.
    Can you please let me know if you still remember how did you achieve it?
    Satyen...

  • Convert xml string into xml file?

    Hi,
    I got a method that returns an JDom Element object.
    Then I use the JDOM Element toString method() to change it into xml string.
    Now, I need to convert it into actual xml file.
    How to I do it?
    Thanks.

    Hi,
    If you got an xml string, just write it to an ordinary file. Look at FileWriter.
    /Kaj

  • To convert  XML String- ResultSet

    Hi
    I am using Web Services created in EJB and will be accessed from JSP client containing applet-swing based GUI, using n tier architecture so I need to convert the XML String to Java ResultSet. (I am able to convert the ResultSet -> XML string using ResultSetBuilder), So I just want to know how to convet the XML String to Java ResultSet.
    Secondly is there any method to manually add columns to the ResultSet.
    Will anybody tell me of any utility, tools or the methods so that I can accomplish this task.
    Thank in advance
    nitin

    What would be the point of doing this? A ResultSet is basically like a cursor running against a database query. You could create a fake ResultSet and pass it something else but why? Just use a normal data-structure.

Maybe you are looking for

  • Moving a Plant to a new company code

    Hi, Does anyone have experience of moving a Plant from one company code to another in a "live" syste. We are about to make some major changes to certain company codes and so new company codes will be required. We have two options The safe option - to

  • BW Interview Ques

    Dear All,   This is Mahitha from Dallas... I hav an interview 2morrow.. could anyone please help me out by mailing some interview questions,,,,Plzzzzz?([email protected])   Also would lik to welcome any of ur suggestion s regarding the same.... Regar

  • BIOHD-2 error code but starts anyway

    Hi! I've refreshed my HP computer which was working alright with windows 7 before. Now I've installed windows 8.1 N and when Im trying to start up I get to the HP screen, if I try to diagnos the problem it says that I've got a BIOHD-2 error, but afte

  • Yahoo e-mail content is blank when I am using Firefox. Works OK in Explorer

    I use Yahoo Mail. E-mail content is blank when opened in Firefox. Everything works fine when openied under Explorer.

  • Locked files in cs3

    I have checked the forums but cannot see this problem although there are similar problems. Unfortunatly none seem to resolve my problem. My problem is that i had to re-instate windows xp plus all my software and since doing this some of my files on m