0

I Have XML with this structure:

<ms:tech ID="TM_002"> 
      <ms:wrap MDTYPE="NISOIMG" MIMETYPE="text/xml"> 
        <ms:xmlData> 
          <ml:ml> 
            <mx:BasicInformation> 
              <mx:ObjectIdentifier> 
                <mx:objectIdentifierType>Value</mix:objectIdentifierType> 
              </mx:ObjectIdentifier>
              **-----HERE AT THIS POSITION INSERT NEW XML TAG------**
              <mx:byteOrder>Value2</mx:byteOrder>  
              <mx:Compression> 
                <mx:compressionScheme>Uncompressed</mx:compressionScheme> 
              </mx:Compression> 
            </mx:BasicInformation>
           </ml:ml>
        <ms:xmlData> 
       </ms:wrap>       
</ms:tech>

I want to insert new XML tag at specific position in XML tree. My code so far looks like this:

    String xp = "//ms:tech[@ID='TM_002']/ms:wrap/ms:xmlData/ml:ml/mx:BasicInformation";
    List<Node> list = amdDocument.selectNodes(xp);
    Node element = list.get(0);

By this I got the tag, and in this tag I want insert new one after . Im using dom4j. How can I do this? Thanks.

Michael
  • 169
  • 2
  • 2
  • 16
  • 1
    Does this answer your question? [How can I insert a node before an other using dom4j?](https://stackoverflow.com/questions/7571369/how-can-i-insert-a-node-before-an-other-using-dom4j) – Alejandro Jan 17 '20 at 14:47
  • It depends on which dom4j class you use for `Node`. `DOMElement` from `org.dom4j.dom` has `insertBefore()`. – Alejandro Jan 17 '20 at 15:36

0 Answers0