2023 May 31 7:54 AM
Hi
I am using if_ixml_document->create_simple_element_ns
To insert a subnode into an xml document. That is fine - but the element is placed in the end of the parent. Is there anyway to add an element as the beginning of the parent?
2023 May 31 6:27 PM
In iXML, the CREATE methods don't link the nodes to a node in a document. You must link them via methods like APPEND_CHILD, INSERT_CHILD, REPLACE_CHILD.
Concerning INSERT_CHILD, the documentation of "Interface if_ixml_node" says:
Method signature:
methods INSERT_CHILD
importing
!NEW_CHILD type ref to IF_IXML_NODE
!REF_CHILD type ref to IF_IXML_NODE
returning
value(RVAL) type I .
2023 May 31 6:27 PM
In iXML, the CREATE methods don't link the nodes to a node in a document. You must link them via methods like APPEND_CHILD, INSERT_CHILD, REPLACE_CHILD.
Concerning INSERT_CHILD, the documentation of "Interface if_ixml_node" says:
Method signature:
methods INSERT_CHILD
importing
!NEW_CHILD type ref to IF_IXML_NODE
!REF_CHILD type ref to IF_IXML_NODE
returning
value(RVAL) type I .
2023 Jun 02 10:14 AM
Hi
I am not quite sure i understand it: if i use INSERT_CHILD with empty refChild you are right, then the node is inserted as the last child of the current node.
If i use the current node as refChild it´s not inserted at all?
2023 Jun 02 12:36 PM
Why are you talking about an empty refChild?
The SAP documentation is clear: "This method inserts newChild immediately before the given refChild node"
data(root) = ixml_doc->GET_ROOT_ELEMENT( ).
data(first_child) = ixml_doc->create_element( name = 'FIRST_CHILD' ).
root->append_child( first_child ).
data(second_child) = ixml_doc->create_element( name = 'SECOND_CHILD' ).
root->append_child( new_child = second_child ref_child = first_child ).
You will get this XML element hierarchy (inserting SECOND_CHILD at the beginning of ROOT was your question):
ROOT
SECOND_CHILD
FIRST_CHILD
2023 Jun 02 2:33 PM
You are right - thank you. I missed the fact the it was ref CHILD - not ref Parent 🙂