Moras da navedes default namespace URI za svaki tag koji kreiras a koji ce biti dete tvog root-a. CreateElement ima overload koji prima xmlns namespace elementa i mozes da mu das onaj koji je u root-u:
Code:
XmlDocument doc = new XmlDocument();
doc.LoadXml("<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\"></Project>");
XmlNode node = doc.CreateElement("Proba", doc.DocumentElement.NamespaceURI);
doc.DocumentElement.AppendChild(node);
Console.WriteLine("Attributes: " + node.Attributes.Count);
Console.WriteLine("node.OuterXml: " + node.OuterXml);
Console.WriteLine(doc.OuterXml);
i sad dobijes:
Code:
Attributes: 0
node.OuterXml: <Proba xmlns="http://schemas.microsoft.com/developer/msbuild/2003" />
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><Proba /></Project>
Attributes je nula zato sto se xmlns= i xmlns:xxx= ne tretira kao atribut od strane XML DOM-a. Ako budes kreirao atribute u tvojim nodovima, prica je drugacija, za razliku od tagova atribut nasledjuje namespace elementa u koji je umetnut. Cak ako navedes isti namespace u CreateAttribute, DOM ce napraviti neku ludoriju ovog tipa (sto je po meni propust u DOMu):
Code:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Proba d2p1:TestAttr="" xmlns:d2p1="http://schemas.microsoft.com/developer/msbuild/2003" />
</Project>
▪ The word 'politics' is derived from the word 'poly', meaning 'many', and the word 'ticks', meaning 'blood sucking parasites' - Larry Hardiman
▪ If the good guy gets the girl, it's rated PG; if the bad guy gets the girl, it's rated R; and if everybody gets the girl, it's rated X
▪ Illegal aliens have always been a problem in the United States. Ask any Native American