[Mono-bugs] [Bug 699242] New: XElement.SetElementValue remove all other child elements

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri Jun 10 05:20:01 EDT 2011


https://bugzilla.novell.com/show_bug.cgi?id=699242

https://bugzilla.novell.com/show_bug.cgi?id=699242#c0


           Summary: XElement.SetElementValue remove all other child
                    elements
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 1.2.0
          Platform: x86
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Sys.XML
        AssignedTo: atsushi at ximian.com
        ReportedBy: tom103 at free.fr
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


User-Agent:       Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101
Firefox/4.0.1

When you set the value of a child element with XElement.SetElementValue, all
other child elements are removed. This is not the expected behavior, only the
specified child elements should be affected.

Reproducible: Always

Steps to Reproduce:
Run the following code

    XElement e = new XElement("foo", new XElement("bar", "xyz"), new
XElement("baz", "abc"));
    Console.WriteLine("*** Original XML ***");
    Console.WriteLine(e);
    Console.WriteLine();
    e.SetElementValue("bar", "hello");
    Console.WriteLine("*** Modified XML ***");
    Console.WriteLine(e);
    Console.WriteLine();
Actual Results:  
The output of the code above is this:

    *** Original XML ***

    <foo>
      <bar>xyz</bar>
      <baz>abc</baz>
    </foo>

    *** Modified XML ***

    <foo>
      <bar>hello</bar>
    </foo>

Notice the "baz" element disappeared

Expected Results:  
The output should be as follows:

    *** Original XML ***

    <foo>
      <bar>xyz</bar>
      <baz>abc</baz>
    </foo>

    *** Modified XML ***

    <foo>
      <bar>hello</bar>
      <baz>abc</baz>
    </foo>

(the "baz" element is still there)

This is the behavior observed with the Microsoft .NET implementation

The current SetElementValue method does the following:
- create a new element with the specified name and value.
- call RemoveNodes to clear all child elements
- add the new child element

It should do the following:
- look for an existing element with the specified name
- create it if it doesn't already exist
- set the specified value on this element

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list