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 / February 2008

Tip: Looking for answers? Try searching our database.

Set Element Prefix  when serializing a class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jerry C - 26 Feb 2008 10:20 GMT
I am serializing a class and want to set the prefix on the elements.
This is the element I am getting when I serialize the class.
<d1p1:Header> and I would like to set the prefix "d1p1" to someting else.
How do I do this.

Thank you
Signature

Jerry

Martin Honnen - 26 Feb 2008 11:51 GMT
> I am serializing a class and want to set the prefix on the elements.
> This is the element I am getting when I serialize the class.
> <d1p1:Header> and I would like to set the prefix "d1p1" to someting else.
> How do I do this.

Here is an example in C#:

            XmlSerializerNamespaces namespaces = new
XmlSerializerNamespaces();
            namespaces.Add("prefix", "http://example.com/2008/ex1");
            XmlSerializer serializer = new XmlSerializer(typeof(Foo));
            Foo f = new Foo();
            f.Bar = "foobar";
            serializer.Serialize(Console.Out, f, namespaces);

So you create an XmlSerializerNamespaces object, call the Add method to
bind the desired prefix to the namespace URI and then pass that object
as the third argument to the Serialize method.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

Wen Yuan Wang [MSFT] - 29 Feb 2008 09:13 GMT
Thanks for Martin's prompt reply.

Hello Jerry,

It seems Martin has given a great sample and advice.
I just want to check if there is anything else we can help with.
If the issue still persists or there is anything unclear, please feel free
to update here again. We are glad to assist you.

Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
======================================
This posting is provided "AS IS" with no warranties, and confers no rights.

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.