Remove empty xmlns=“” after Xml Serialization?

This works (you just need them to be in the same namespace and you use the namespaces class so the writter doesn't confuse): TestMethod public void TestMethod3() { var list = new {new SitemapNode("1", DateTime. Now, 1), new SitemapNode("2", DateTime.Now. AddDays(1), 2)}; var serializer = new XmlSerializer(typeof(SitemapNode)); var st = new MemoryStream(); using (var writer = XmlWriter.

Create(st)) { var ns = new XmlSerializerNamespaces(); ns. Add("", "test"); writer. WriteStartElement("test", "test"); foreach (SitemapNode node in list) { serializer.

Serialize(writer, node, ns); } writer.WriteEndElement(); } st. Position = 0; TestContext. WriteLine(new StreamReader(st).ReadToEnd()); } XmlRoot(ElementName = "url", Namespace = "test") public class SitemapNode { XmlElement(ElementName = "loc") public string Location { get; set; } XmlElement(ElementName = "lastmod") public DateTime LastModified { get; set; } XmlElement(ElementName = "priority") public decimal Priority { get; set; } public SitemapNode() { Location = String.

Empty; LastModified = DateTime. Now; Priority = 0.5M; } public SitemapNode(string location, DateTime lastModified, decimal priority) { Location = location; LastModified = lastModified; Priority = priority; } } And the output is (based on your comments that is what you were looking for): 12009-03-05T13:35:54.6468-07:001 22009-03-06T13:35:54.6478-07:002.

1 If I could mark you up 50 points my self I would! Great post, and thank you for your time in this matter. I really appreciate it!

Worked a treat. + 1 + ANSWER :-) – REA_ANDREW Mar 5 '09 at 20:41 Take this same example and add this property to SitemapNode: XmlElement(ElementName = "value") public string Value { get; set; } Why the serializer just IGNORES it? – andrecarlucci Aug 19 '09 at 21:36.

I.e. : XmlRoot(ElementName = "url") public class SitemapNode { ... }.

Yes still the same, it outputs an empty xmlns="" – REA_ANDREW Mar 5 '09 at 19:49 And removing the XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns. Add(String. Empty, String.

Empty); as well? – cjk Mar 5 '09 at 19:54 I thought that at first but the output is as follows: So it gives me two extra attributes. – REA_ANDREW Mar 5 '09 at 20:14 To add further information when I start the document I write my root element with a namespace.

NOW, if I do not write the namespace then subsequent child root nodes do not output an xmlns attribute. How can I give the root element a xmlns attribute but no the child nodes when serializing? – REA_ANDREW Mar 5 '09 at 20:20.

This works (you just need them to be in the same namespace and you use the namespaces class so the writter doesn't confuse).

I was having trouble inserting a node into an existing document with multiple namespaces.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions