xmlns attribute added to child nodes

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have the following (this is a cut down version) to create some XML - the trouble is that the xmlns attribute is added to all child nodes of <business> and is empty - this is causing an error with our supplied schema. How do I stop this
attribute being added to child nodes? I am relatively new to XML in .net so be gentle! :)
public static bool GetXML() <br/>
{<br/>
XmlDocument xmlOutputDoc = new XmlDocument();<br/>
xmlOutputDoc.LoadXml("<business id="54" lang="en-gb" xmlns= http://www.webaddress.co.uk www.webaddress.co.uk "<br/>
+ "<name>busname</name>"<br/>
+ "</business>");<br/>
XmlElement xmlOutputElement = xmlOutputDoc.DocumentElement; <br/>
List<weblinks>links = GetWebLinks(); <br/>
XmlNode engagementMethodsNode = xmlOutputDoc.CreateNode(XmlNodeType.Element, "engagement-methods", null);
<br/>
xmlOutputElement.AppendChild(engagementMethodsNode);<br/>
foreach (WebLinks link in links) <br/>
{ <br/>
XmlNode method = xmlOutputDoc.CreateNode(XmlNodeType.Element, "method", "");<br/>
xmlOutputElement.AppendChild(method);<br/>
Helper.AppendNode(xmlOutputDoc, method, "title", link.TypeName);<br/>
Helper.AppendNode(xmlOutputDoc, method, "url", link.URL);
<br/>
engagementMethodsNode.AppendChild(method);<br/>
} <br/>
<br/>
// Save the document to a file and auto-indent the output <br/>
using (XmlTextWriter writer = new XmlTextWriter(ConfigurationManager.AppSettings["XMLSavePath"] + ConfigurationManager.AppSettings["RKHXMLFileName"], null))
<br/>
{<br/>
writer.Formatting = Formatting.Indented; xmlOutputDoc.Save(writer);
<br/>
} <br/>
return true; <br/>
}</weblinks>

View the full article
 
Back
Top