You must Sign In to post a response.
  • Category: XML

    How to Add Additional parent in existing XML document

    Are you looking for a way to Add Additional parent in existing XML document ? then read this thread to know how to do it

    Hi All,
    Here I have document like below.Here the xml document having a tag <carrier:Header> which is having two child.Now i want to add one more child to <carrier:Header> but at the same time it will be sub parent for existing child elements.For example,it should like to make it.please help me.


    <EnrollmentRequest xsi:schemaLocation="" xmlns="" xmlns:core="" xmlns:carrier="" xmlns:group="" xmlns:infra="" xmlns:simple="" xmlns:xsi="">
    <core:AddressLine1>29 Winthrop Road</core:AddressLine1>
    <core:City>Short Hills</core:City>
  • #757338
    You need to create a second xml and then add your first xml as child of second xml, create a two separate xml and then create their XMLDocument
    Now, you need to use 'DocumentElement.AppendChild' to append child in documentA

    XmlDocument documentA;
    XmlDocument documentB;

    foreach(var childNode in documentA.DocumentElement.ChildNodes)

    hope it helps

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #763000
    This may give you a rough idea. Hope this helps.

    Nodes childNodes = parent.query("child");
    for (int i = 0; i < childNodes.size(); i++) {
    Element currentChild = (Element) childNodes.get(i);
    if (someCondition) {
    ParentNode parent = currentChild.getParent();
    int currentIndex = parent.indexOf(currentChild);
    Element extraParent = new Element("extraParent");

  • Sign In to post your comments