Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / January 2004

Tip: Looking for answers? Try searching our database.

Form and XmlRootElement

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Richard Grimes - 30 Jan 2004 15:12 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.