Skip to Content
author's profile photo Former Member
Former Member

cl_xml_document

Hi all,

I create an xml document through this code:

DATA : itab   TYPE TABLE OF sflight,
       l_xml  TYPE REF TO cl_xml_document,       

SELECT * FROM sflight INTO TABLE itab.

CREATE OBJECT l_xml.

CALL METHOD l_xml->create_with_data( dataobject = itab[] name = 'FLIGHTS' ).

Then I have a xml-file with root node named 'FLIGHTS' instead of the standard 'DATA' (see the parameters of method create_with_data).

Now all the sub-nodes have the node name 'item', how do I change these node names? Preferably I want the node to be <FLIGHTNUMBER id="CONNID"> and at "CONNID" there must be the value of the CONNID of that node.

Thnx in advance,

Fred.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Posted on Sep 28, 2005 at 10:06 AM

    you need to write an XSLT program to convert this XML file to your desired format. and then using CALL TRANSFORMATION using the XSLT you have to convert the source xml to target xml.

    another note instead of the method you have used for xml you could also use

    CALL TRANSFORMATION (`ID`)

    SOURCE flights = itab[]

    RESULT XML xml_out.

    Regards

    Raja

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 28, 2005 at 10:45 AM

    hi,

    data : l_string type string.

    data :lo_mxml type ref to cl_xml_document,

    m_document type ref to if_ixml_document,

    l_dom type ref to if_ixml_element,

    l_ele type ref to if_ixml_element,

    l_ele1 type ref to if_ixml_element,

    m_doctype type ref to if_ixml_document_type,

    g_ixml type ref to if_ixml,

    l_text type ref to if_ixml_text,

    ls_srctab1 type xstring,

    l_retcode type sysubrc. "#EC *.

    create object lo_mxml.

    move 'cxml SYSTEM "http://b2b.xxxxx.com/"' to l_string.

    class cl_ixml definition load.

    g_ixml = cl_ixml=>create( ).

    m_document = g_ixml->create_document( ).

    call method m_document->create_document_type

    exporting

    name = 'cXML'

    receiving

    rval = m_doctype.

    call method m_document->set_document_type

    exporting

    document_type = m_doctype.

    l_dom = m_document->create_element( name = 'cXML' ).

    l_retcode = m_document->append_child( l_dom ).

    move 'xxxx'_id to l_string.

    *____setting attribute payload id for cxml tag

    call method l_dom->set_attribute

    exporting

    name = 'payloadID'

    value = l_string

    • NODE = LO_NODE

    receiving

    rval = l_retcode.

    cheers,

    sasi

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 28, 2005 at 10:52 AM

    I know it is possible with an xsl transformation, but I wonder if it is possible to realise the same through cl_xml_document.

    Perhaps I need to use the methods create_element, append_child or set_attribute or some other. I don't know because the documentation on this is nowhere to be found.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 28, 2005 at 01:28 PM

    with following adittion to my code:

    DATA l_node type ref to IF_IXML_NODE.
    
    l_node = l_xml->FIND_NODE( NAME = 'item' ).
    
    CALL METHOD l_xml->FIND_SIMPLE_ELEMENT
      EXPORTING
        name   = 'CARRID' 
        ROOT   = l_node   
      receiving
        value   = l_string
        .
    
    l_node->SET_NAME( name = l_string ).

    I get the CARRID in the first <item> node. But I want the CONNID in the node, this can not be, because the xml file does not accept a node like <0001>...</0001> (I've tried). I want the node to look like <CONNID id="0001">...</CONNID> (this works, I've tried by editting the xml-file).

    Can someone help me on this last part? I think it has to do with the node attributes, but am not sure.

    Greetings Fred.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      Data: l_dom type ref to if_ixml_element,

      l_ele type ref to if_ixml_element.

      call method l_dom->set_attribute

      exporting

      name = 'timestamp'

      value = l_string

      • NODE = LO_NODE

      receiving

      rval = l_retcode.

      l_ele = m_document->create_element( name = 'Response' ).

      l_retcode = l_dom->append_child( l_ele ).

      is this one you are expecting

      cheers,

      sasi

  • author's profile photo Former Member
    Former Member
    Posted on Sep 28, 2005 at 02:13 PM

    No, I think it is not...

    As you can see, I do not append elements to the xml file manualy, but use:

    CALL METHOD l_xml->create_with_data( dataobject = itab[] name = 'FLIGHTS' ).

    Now with this method, there are multiple nodes created, called <item>, these nodes i need to change.

    As there are more than one nodes called <item> I would like to make them "unique" by changing the <item>...</item> part to <CONNID id="0001">...</CONNID>. I know how to change the name if the nod (see my post above), but I do not know how to insert the id="0001" part to the node.

    Please, read my above posts to know what I have done till now.

    Greetings Fred.

    ps: I have already realized this with the call transformation (xslt), but want to know if it is possible this way.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.