. NET FileStreams inserts a DTD into an XML file

Source: Internet
Author: User
Tags comparison

Although you can validate and create XML files through a schema, use them in comparison. NET class is more convenient, it will give you more flexibility to use.

Technical Toolbox: vb.net, XML, ado.net

Ado. NET provides a good capability to handle transformations between datasets and XML. You can pass VS. NET creates a dataset schema visually in XML. Like a document type definition (DTD), schemas allow you to validate and create XML files, but use them in comparison. NET class is more convenient, it will give you more flexibility to use.

But DTDs are not useless. It is widely used in non. NET program, the World Wide Web Consortium (consortium) standard for Internet and data conversion. In order to be able to achieve backwards (that is, not. NET) compatibility, the. NET Framework contains the ability to validate XML through DTDs.

However, even if you need to include a DTD in an output XML file generated by a Web program, this is not the case, or even if it exists, there is a lack of standard files to refer to.

And System.IO.FileStream object can help you solve this problem. You can create a FileStream and insert the DTD into your XML file, and one FileStream leads to two filestream―― that they get from the DTD and the dataset, respectively. You can design a DataSet schema with a DTD file and some sample XML. Vs. NET's visual Data set design interface makes this work easy, and DTD files stored in the application folder are included in the resulting XML.

This method uses many different kinds of filestreams. A FileStream (stream A) contains information about DTDs, and another FileStream (stream B) is used to create the final XML file. Stream a flows into stream B, the dataset flows directly into stream B, and Stream B closes and is stored as an XML file in your file system.

The first thing you should prepare is a dataset, and you can create a new schema-based dataset and then data binding. Next, the DTD file is read into a FileStream (Stream A). You can accomplish this by creating a FileStream object and a StreamReader object. To read a text file to FileStream by StreamReader:

Private Function GetDTD(DTDFilePath as string) _
  As IO.FileStream
  Dim fsDTD As System.IO.FileStream
  Dim srDTD As IO.StreamReader
  fsDTD = New IO.FileStream(DTDFilePath, _
  IO.FileMode.Open)
  srDTD = New IO.StreamReader(fsDTD)
  GetDTD = fsDTD
  End Function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.