nibble wrote:
I'm doign the following:
XmlElement myElem....;
string name = "xmlns:"+"a bc";
string value = "http://www.abc.com";
myElem.SetAttri bute(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.Cre ateElement("god s");
XmlAttribute attribute = xmlDocument.Cre ateAttribute("x mlns",
"prefix", xmlns);
attribute.Value = "http://example.org/2004/08/whatever";
rootElement.Set AttributeNode(a ttribute);
xmlDocument.App endChild(rootEl ement);
Console.WriteLi ne(xmlDocument. OuterXml);
}
}
that is you have to use CreateAttribute Node and you have to make sure
you have the right namespace when you create the attribute.
--
Martin Honnen
http://JavaScript.FAQTs.com/