09-28-2005 10:45 AM
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.
09-28-2005 11: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
09-28-2005 11: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
09-28-2005 11: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.
09-28-2005 2: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.
09-28-2005 2:47 PM
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
09-28-2005 3: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.