Posted on 2006-04-03
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="">
- <xs:schema id="datareader" xmlns="" xmlns:xs="" 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

Question by:kinton
    LVL 6

    Expert Comment

    For a typed dataset you can set DataSet.SchemaSerializationMode = SchemaSerializationMode.ExcludeSchema;
    LVL 6

    Accepted Solution

    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();
    LVL 2

    Author Comment

    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.

    LVL 6

    Expert Comment

    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;
    LVL 6

    Expert Comment

    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'...  
    LVL 2

    Author Comment

    thank you.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    This article will show, step by step, how to integrate R code into a R Sweave document
    JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
    The viewer will learn how to dynamically set the form action using jQuery.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now