nibble wrote:
I'm doign the following:
XmlElement myElem....;
string name = "xmlns:"+"abc";
string value = "http://www.abc.com";
myElem.SetAttribute(name, value);
I get an exception saying that name cannot have ':' in it. However, MSDN
usage doc for this method explicitly says that ':' will be parsed and the
prefix would be retrieved.
If you want to create a namespace attribute I think you have to do it as
follows:
using System;
using System.Xml;
public class Test2004082101 {
public static void Main (string[] args) {
string xmlns = "http://www.w3.org/2000/xmlns/";
XmlDocument xmlDocument = new XmlDocument();
XmlElement rootElement = xmlDocument.CreateElement("gods");
XmlAttribute attribute = xmlDocument.CreateAttribute("xmlns",
"prefix", xmlns);
attribute.Value = "http://example.org/2004/08/whatever";
rootElement.SetAttributeNode(attribute);
xmlDocument.AppendChild(rootElement);
Console.WriteLine(xmlDocument.OuterXml);
}
}
that is you have to use CreateAttributeNode and you have to make sure
you have the right namespace when you create the attribute.
--
Martin Honnen
http://JavaScript.FAQTs.com/