I have an XML file with no namespaces defined:
<data>
<textItems>
<add name="test" value="test value"/>
</textItems>
</data>
I can map this to a class with:
[XmlRoot]
public class data
{
[XmlArray("textItems", Form=XmlSchemaFor.Unqualified)]
[XmlArrayItem("add", typeof(addItem), Form=XmlSchemaFor.Unqualified)]
public addItem[] Items;
}
public class addItem
{
[XmlAttribute] public string name;
[XmlAttribute] public string value;
}
That is fine. I can read in the XML file, deserialize it with XmlSerializer
to a data object and access the Items. I can alter the Items array and write
the data object to the XML file by serializing it.
However, I find that the XmlSerializer writes the root element with
xmlns:xsd and xmlns:xsi attributes:
<data xmlns:xsd="stuff" xmlns:xsi="stuff">
<!-- stuff -->
</data>
How do I prevent that? [XmlRoot] does not have a Form property.
Richard

Signature
my email evpuneqt@zicf.bet is encrypted with ROT13 (www.rot13.org)
Oleg Tkachenko [MVP] - 30 Jan 2004 15:30 GMT
> However, I find that the XmlSerializer writes the root element with
> xmlns:xsd and xmlns:xsi attributes:
[quoted text clipped - 4 lines]
>
> How do I prevent that? [XmlRoot] does not have a Form property.
What's wrong with them?
Anyway, it's a faq:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=e4wQER%24MCHA.2428%40tkm
sftngp12

Signature
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Richard Grimes [MVP] - 30 Jan 2004 16:09 GMT
>> However, I find that the XmlSerializer writes the root element with
>> xmlns:xsd and xmlns:xsi attributes:
[quoted text clipped - 8 lines]
>
> Anyway, it's a faq:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=e4wQER%24MCHA.2428%40tkm
sftngp12
Oleg,
Its not really my expertise, so please excuse my ignorance <g>
But I have to admit that adding empty namespaces is hardly logical, but it
works. Thanks!
Richard

Signature
my email evpuneqt@zicf.bet is encrypted with ROT13 (www.rot13.org)
Daniel Cazzulino - 30 Jan 2004 18:21 GMT
You can avoid both namespace declarations by using a custom XmlTextWriter.
Here's one such writer:
http://weblogs.asp.net/cazzu/archive/2004/01/23/62141.aspx. Look at the
NonXsiTextWriter.

Signature
Daniel Cazzulino
Lagash Systems SA
http://weblogs.asp.net/cazzu
> I have an XML file with no namespaces defined:
>
[quoted text clipped - 34 lines]
>
> Richard