programatically adding attribute xsi:nil=true to XML element - XML SOAP

This is a discussion on programatically adding attribute xsi:nil=true to XML element - XML SOAP ; Hi, I want to add the xsi:nil="true' attribute to an element in XML. I am using XmlNode.Attributes.Append() but the generated output results in the attribute [nil="true"] ignoring the "xsi:" prefix. How do I work around this problem?....

+ Reply to Thread
Results 1 to 2 of 2

programatically adding attribute xsi:nil=true to XML element

  1. Default programatically adding attribute xsi:nil=true to XML element

    Hi,
    I want to add the xsi:nil="true' attribute to an element in XML. I am using
    XmlNode.Attributes.Append() but the generated output results in the attribute
    [nil="true"] ignoring the "xsi:" prefix.

    How do I work around this problem?.


  2. Default Re: programatically adding attribute xsi:nil=true to XML element

    Nabeel Moeen wrote:

    > I want to add the xsi:nil="true' attribute to an element in XML. I am using
    > XmlNode.Attributes.Append() but the generated output results in the attribute
    > [nil="true"] ignoring the "xsi:" prefix.


    It works like this, using CreateAttribute and SetAttributeNode:

    XmlDocument xmlDocument = new XmlDocument();
    xmlDocument.LoadXml(@"<foo><bar/></foo>");
    XmlElement bar = xmlDocument.DocumentElement["bar"];
    XmlAttribute xsinil = xmlDocument.CreateAttribute("xsi", "nil",
    "http://www.w3.org/2001/XMLSchema-instance");
    xsinil.Value = "true";
    bar.SetAttributeNode(xsinil);

    --

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

+ Reply to Thread

Similar Threads

  1. Replies: 0
    Last Post: 12-02-2007, 09:03 AM
  2. Replies: 7
    Last Post: 09-25-2007, 09:22 AM
  3. Replies: 0
    Last Post: 09-16-2007, 08:03 PM
  4. Replies: 23
    Last Post: 07-25-2007, 07:40 AM
  5. Replies: 0
    Last Post: 05-11-2007, 08:03 PM