• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2000
  • Last Modified:

Return an ASP.NET XML DATASET WITHOUT THE SCHEMA

Hi,

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" />
  </xs:sequence>
  </xs:complexType>
  </xs:element>
  </xs:choice>
  </xs:complexType>
  </xs:element>
  </xs:schema>
- <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">
  <UserName>spirit_sys</UserName>
  <Password>Gh05t5ly</Password>
  <EstablishmentFullName>Gravesend Grammar School</EstablishmentFullName>
  <Address1>Church Walk</Address1>
  <Address2>Milton</Address2>
  <Town>GRAVESEND</Town>
  <County>Kent</County>
  <Postcode>DA12 2PR</Postcode>
  <Authority>Kent</Authority>
  <Telephone>01474 331893</Telephone>
  <Fax>01474 331894</Fax>
  <PupilsonRoll>1000</PupilsonRoll>
  <EducationNumber>17219</EducationNumber>
  <KB_ID>15</KB_ID>
  </Results>
  </datareader>
  </diffgr:diffgram>
  </DataSet>

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



thanks
0
kinton
Asked:
kinton
  • 4
  • 2
1 Solution
 
e1vCommented:
For a typed dataset you can set DataSet.SchemaSerializationMode = SchemaSerializationMode.ExcludeSchema;
0
 
e1vCommented:
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();
0
 
kintonAuthor Commented:
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.

thanks
0
Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
e1vCommented:
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

[WebMethod]
public XmlDocument ReturnXmlDoc()
{
StringWriter sw = new StringWriter();
yourDataSet.WriteXml(sw, XmlWriteMode.DiffGram);
XmlDocument doc = new XmlDocument();
doc.LoadXml(sw.ToString());
return doc;
}
0
 
e1vCommented:
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'...  
:)
0
 
kintonAuthor Commented:
thank you.
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now