We help IT Professionals succeed at work.


Medium Priority
Last Modified: 2013-11-19

I have produced an XML Web Service in ASP 2.0, this returns a dataset.  The output is below:

  <?xml version="1.0" encoding="utf-8" ?>
- <DataSet xmlns="http://education.co">
- <xs:schema id="datareader" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
- <xs:element name="datareader" msdata:IsDataSet="true" msdata:Locale="en-US">
- <xs:complexType>
- <xs:choice minOccurs="0" maxOccurs="unbounded">
- <xs:element name="Results">
- <xs:complexType>
- <xs:sequence>
  <xs:element name="UserName" type="xs:string" minOccurs="0" />
  <xs:element name="Password" type="xs:string" minOccurs="0" />
  <xs:element name="EstablishmentFullName" type="xs:string" minOccurs="0" />
  <xs:element name="Address1" type="xs:string" minOccurs="0" />
  <xs:element name="Address2" type="xs:string" minOccurs="0" />
  <xs:element name="Town" type="xs:string" minOccurs="0" />
  <xs:element name="County" type="xs:string" minOccurs="0" />
  <xs:element name="Postcode" type="xs:string" minOccurs="0" />
  <xs:element name="Authority" type="xs:string" minOccurs="0" />
  <xs:element name="Telephone" type="xs:string" minOccurs="0" />
  <xs:element name="Fax" type="xs:string" minOccurs="0" />
  <xs:element name="PupilsonRoll" type="xs:string" minOccurs="0" />
  <xs:element name="EducationNumber" type="xs:string" minOccurs="0" />
  <xs:element name="KB_ID" type="xs:string" minOccurs="0" />
- <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
- <datareader xmlns="">
- <Results diffgr:id="Results1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
  <EstablishmentFullName>Gravesend Grammar School</EstablishmentFullName>
  <Address1>Church Walk</Address1>
  <Postcode>DA12 2PR</Postcode>
  <Telephone>01474 331893</Telephone>
  <Fax>01474 331894</Fax>

I want to remove the schema at the top.  I have searched higth and low and cannot find anything?  Is it even possible.  I have tried returning the dataset as string but this removes the row counter on every line.

I would really appreciate any help

Watch Question


For a typed dataset you can set DataSet.SchemaSerializationMode = SchemaSerializationMode.ExcludeSchema;
Or if you want to return it as string but keep the rowcounter you can do this:

        StringWriter sw = new StringWriter();
        DataSet.WriteXml(sw, XmlWriteMode.DiffGram);
        return sw.ToString();

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Hi e1v,

The method to return as a string works almost perfectly,however,the closing tags are replaced with &gt and the opening with @Lt the source file of the page returned,any idea why?  The person I am writing this for is consuming it with PHP and has suggested this will be a problem for them.  I don't quite understand why as the actual output appears fine!!?

The method you suggested to keep it as a dataset returns this error message "SchemaSerializationMode property can be set only if it is overridden by derived DataSet".  Any ideas why?

I appreciate my first paragraph is a seperate question,and if necessary I am prepared to post it as one and award you the points for your answer about returning it as a string.


I suppose the SchemaSerializationMode errormessage mens that can only be set on a typed dataset, that is a dataset generated from a xsd, not on a generic DataSet (like DataSet ds = new DataSet())

As for the problem you have with string it probably has to do with the string encoding, you could try using an XmlTextWriter and experimenting with different System.Text.Encoding...) , but I

Another suggesiton would be to return a xmldocument like this

public XmlDocument ReturnXmlDoc()
StringWriter sw = new StringWriter();
yourDataSet.WriteXml(sw, XmlWriteMode.DiffGram);
XmlDocument doc = new XmlDocument();
return doc;

Sorry for the typos above, but I was really in a hurry...(approaching deadline at work..)

I don't remember what I started writing where I wrote 'but I'...  


thank you.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.