I have created a class Newsgroup which allows itself to be serialized using
Xml serialization attributes.
[Serializable]
[XmlRoot("Newsgroup")]
public class Newsgroup
{
[XmlAttribute("Name")]
public string Name;
[XmlIgnore]
public int LastArticle;
[XmlIgnore]
public int FirstArticle;
[XmlIgnore]
public bool PostingAllowed;
[XmlIgnore]
public int EstimatedArticles;
public Newsgroup()
{
}
public Newsgroup(string response)
{
}
}
I serialize the contents of an ArrayList of Newsgroup objects to a file
"C:\\news.xml".
ArrayList list = client.GetNewsgroupList();
TextWriter tw = new StreamWriter("C:\\news.xml");
XmlSerializer xs = new XmlSerializer(typeof(Newsgroup));
foreach (Newsgroup newsgroup in list)
xs.Serialize(tw, newsgroup);
tw.Close();
This works fine, but the file is much larger than I would like. A sample
line from this generated XML file looks like so:
<Newsgroup xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Name="microsoft.public.access" /><?xml version="1.0" encoding="utf-8"?>
What do I have to do to get each line look like this:
<Newsgroup Name="microsoft.public.access">
I am looking for a way to skip all of these "xmlns:xsd" & "xmlns:xsi"
attributes. I would also like to avoid putting so many <?xml version> tags
in the file, there is one at the beginning of the document already. I do
not know XML very well, is there something I am missing?