How do I prefix attributes with a namespace?

  • Thread starter Thread starter Sam-I-Am
  • Start date Start date
S

Sam-I-Am

I need to create xml like the following:
<item mynamespace:name="MyName" mynamespace:age="100" />

I am using code similar to this:
XmlDocument meegoInfo = _LoadTemplateXml("Avatar");

// Create downlevel item
XmlNode node= xmlDoc.DocumentElement;
XmlElement item = xmlDoc.CreateElement("item");
item.SetAttribute("name", "MyName");
item.SetAttribute("age", "100");
node.AppendChild(item);

Cheers,

Sam-I-Am
 
Then you will need to use XmlAttribute rather than SetAttribute.
You will need to associate an URI with the namespace prefix.

XmlAttribute a = [XmlDocument].CreateAttribute
("mynamespace", "name", "http://ourcompany.com/mynamespace/");
[XmlNode].Attributes.Append(a);
 
Back
Top