Connecting Tech Pros Worldwide Forums | Help | Site Map

programatically adding attribute xsi:nil=true to XML element

=?Utf-8?B?TmFiZWVsIE1vZWVu?=
Guest
 
Posts: n/a
#1: May 15 '07
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?.


Martin Honnen
Guest
 
Posts: n/a
#2: May 15 '07

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/
Closed Thread