I was trying to insert a xml node before another xmlnode and I have got an exception saying "The reference node is not a child of this node."

This is my initial xml :

<?xml version="1.0" encoding="utf-8" ?>
<Details xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <sampleData>
    <otherNodes></otherNodes>
  </sampleData>
</Details>

I wanted to insert following xml datas(b:dataTobeInserted1,b:dataTobeInserted2 and b:dataTobeInserted3) as a Child of Details but before sampleData.

Details1.xml

<?xml version="1.0" encoding="utf-8" ?>
<DataInserted1 xmlns:b="http://example.com/data">
  <b:dataTobeInserted1>
    <b:otherDetails1></b:otherDetails1>
  </b:dataTobeInserted1>
</DataInserted1>

Details2.xml

<?xml version="1.0" encoding="utf-8" ?>
<DataInserted2 xmlns:b="http://example.com/data">
  <b:dataTobeInserted2>
    <b:otherDetails2></b:otherDetails2>
  </b:dataTobeInserted2>
</DataInserted2>

Details3.xml

<?xml version="1.0" encoding="utf-8" ?>
<DataInserted3 xmlns:b="http://example.com/data">
  <b:dataTobeInserted3>
    <b:otherDetails3></b:otherDetails3>
  </b:dataTobeInserted3>
</DataInserted3>

I want my Output as

<?xml version="1.0" encoding="utf-8" ?>
<Details xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:b="http://example.com/data">
  <b:dataTobeInserted1>
    <b:otherDetails1></b:otherDetails1>
  </b:dataTobeInserted1>
  <b:dataTobeInserted2>
    <b:otherDetails2></b:otherDetails2>
  </b:dataTobeInserted2>
  &l
Edit
Report