Connecting Tech Pros Worldwide Help | Site Map

programatically adding attribute xsi:nil=true to XML element

 
LinkBack Thread Tools Search this Thread
  #1  
Old May 15th, 2007, 11:55 AM
=?Utf-8?B?TmFiZWVsIE1vZWVu?=
Guest
 
Posts: n/a
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  
Old May 15th, 2007, 12:35 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: programatically adding attribute xsi:nil=true to XML element

Nabeel Moeen wrote:
Quote:
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/
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.