PAQ'd & points refunded
Chmod
Community Support Moderator @Experts Exchange
Main Topics
Browse All TopicsI have a WebService that has a WebMethod that returns a custom structure. I accomplished this by using the XmlSerializer on a custom object. This custom object was created from a XSD (Xml Schema Diagram) using the xsd.exe tool. The output from the WebMethod is correct expect that the XmlSerializer appends the following Namespaces to the RootTag:
<RootTag xmlns:xsd="http://www.w3.o
<field1></field1>
<field2></field2>
</RootTag>
The XmlSerializer variable is called 'xs' and when I set 'xs.Namespaces = False' it is suppose to not have Namespace support. However, when I run the WebMethod like this, I get an exception:
System.InvalidOperationExc
at System.Xml.XmlTextWriter.W
at System.Xml.Serialization.X
at System.Xml.Serialization.X
at System.Xml.Serialization.X
My guess is that I need to indicate to the XmlSerializationWriter to pass in null or string.Empty as the parameter for WriteStartElement(..,Strin
My question:
How can I get the WebMethod/XmlSerializer to not output these Namespaces?
Thank you,
Alvin
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: AlvinBeachPosted on 2003-06-23 at 10:00:28ID: 8782973
Ok, I have found the solution.
.Response. OutputStre am, System.Text.Encoding.UTF8) ;
ct, ns);
The solution is to create an instance of a XmlSerializerNamespaces object. Then add an empty prefix and namespace to the collection. Then pass the XmlSerializerNamspaces object to the Serialize() method call. Here's some code to illustrate this:
XmlTextWriter writer = new XmlTextWriter(this.Context
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("","");
xs.Serialize(writer,myObje
This will remove any attribute tags that are on the root tag.