Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Insert node with if_ixml_document

jakob_steen-petersen
Contributor
0 Kudos
677

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?

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos
597

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:

  • "This method inserts newChild immediately before the given refChild node in this node's list of children. If refChild is 0, newChild is appended to the end of the list of children."

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 .
4 REPLIES 4

Sandra_Rossi
Active Contributor
0 Kudos
598

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:

  • "This method inserts newChild immediately before the given refChild node in this node's list of children. If refChild is 0, newChild is appended to the end of the list of children."

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 .

0 Kudos
597

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?

0 Kudos
597

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

597

You are right - thank you. I missed the fact the it was ref CHILD - not ref Parent 🙂