none
How to transfer node value to parent node in xml using c# RRS feed

  • Question

  • Hello All, 

    Please help me to achieve this. I am manipulating  xml document in c#. Here i need to transform inner element value to upper element value. i.e 

    my input is like below

    <AttributeValue>
    <AttributeStringValue>
    <StringValue>CVC-CR</StringValue>
    </AttributeStringValue>
    </AttributeValue>

    My output should be like below

    <AttributeValue>
    <AttributeStringValue>
    CVC-CR
    </AttributeStringValue>
    </AttributeValue>

    please help me to achieve this in c#

    Thanks

    Chandu

    Friday, October 13, 2017 4:49 AM

All replies

  • Hello Chandu,

    There is a way replace nodes in using XDocument , please try it.

                XDocument xd = XDocument.Parse("<AttributeValue><AttributeStringValue><StringValue> CVC - CR </StringValue></AttributeStringValue></AttributeValue>");
    
                string replaceValue = xd.Descendants("StringValue").First().Value;
    
                xd.Root.Descendants("StringValue").FirstOrDefault().ReplaceWith(replaceValue);
    
                xd.Save("XMLFile1.xml");

    Sincerely,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, October 13, 2017 9:13 AM
    Moderator
  • Hello Chandu,

    Is there anything updated?

    If your issue has been solved, you could close the thread by marking the reply  as answer, This can be beneficial to other community members reading this thread.

    Sincerely,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, October 19, 2017 11:09 AM
    Moderator