Connecting Tech Pros Worldwide Forums | Help | Site Map

Adding attributes to nodes...

Maersa
Guest
 
Posts: n/a
#1: Nov 12 '05
hi,

i'm trying to add "attributes" to some nodes and it works at design time but
fails at runtime.

XmlDocument doc = new XmlDocument();

XmlElement elem = doc.CreateElement( "root" );
elem.InnerXml = "<first>abcde</first><last>1234</last>";

Now, what I'd like to do here is, go through adding "namespaces" to the
child nodes of <root>.

XmlNode node = elem.FirstChild;

while( node != null )
{
XmlAttribute attr = node.OwnerDocument.CreateAttribute( "xmlns" );
attr.Value = "urn:mynamespace";
node.Attributes.Append( attr ); // This works in designtime but
fails at runtime
node = node.NextSibiling;
}

Is there some better way in setting the namespace for EACH node element ?
The xsd
requires that i have a namespace on each node.

thanks,



Closed Thread