Is it possible to copy an element out of a xml with all parents?
Such as:
<root>
  <child>child1</child>
  <child>
    <subchild>subchild21</subchild>
  </child>
</root>
to:
<root><child><subchild>subchild21
or something equal?
Is it possible to copy an element out of a xml with all parents?
Such as:
<root>
  <child>child1</child>
  <child>
    <subchild>subchild21</subchild>
  </child>
</root>
to:
<root><child><subchild>subchild21
or something equal?
 
    
    Put some id for that <subchild> and create new xml it will work
XDocument myXMLDocument = XDocument.Load("File.xml");
XElement mychildElement = myXMLDocument.Element("child");
XElement myFirstchildElement = mychildElement.Element("subchild");
XElement myNewchildElement = new XElement(myFirstchildElement);
XAttribute myChildId = myNewParentElement.Attribute("id");
mychild.Value = "subchild";
myFirstchileElement.AddAfterSelf(myNewchildElement);
myXMLDocument.Save("NewFile.xml");
 
    
     
    
    Just for future reference, you could achieve something similar with the DOM of the web-browser using:
var o = document.getElementsByTagName("subchild")[0];
var _xmlstr = o.innerText;
while( o ){
   _xmlstr = "<"+o.tagName.toLowerCase()+">"+_xmlstr; 
   o = o.parentNode;
};
Result:
<root><child><subchild>subchild21
 
    
    Notepad++ and XML Tools did it!
It's possible with
Ctrl + Alt + Shift + P
And called XPath
