?
Solved

VB.NET Dataset and XSD document

Posted on 2005-04-13
5
Medium Priority
?
1,332 Views
Last Modified: 2008-02-01
Hi,

I have some code that retreives a dataset from an ODB provider. The Dataset is returned with all the data in it. What I have been trying to do is format an XML document out of the Dataset using an XSD file. I cannot even come close to doing this. I read on the web that you can but I cannot find any good examples. If anyone knows ow this is done, I would really apreciate the help.

Thanks in advance.
0
Comment
Question by:comt00006
  • 3
  • 2
5 Comments
 
LVL 1

Author Comment

by:comt00006
ID: 13771951
Here is an example of what I am trying to do.

DATASET VALUES
-----------------------
NOTE: Could be multiple records
-----------------------------------------
Table name='Table'
ColumnName = 'SERIAL_NBR'
ColumnName = 'EMPLOYEE_ID'
ColumnName = 'EMPLOYEE_NAME'
ColumnName = 'EMPLOYEE_ADDRESS'
ColumnName = 'EMPLOYEE_SIN'
ColumnName = 'EMPLOYEE_PHONE'
ColumnName = 'DATE_CREATED'
ColumnName = 'COMMENT'


------------------------------------
The result I want in my XML
------------------------------------
<ROOT>
    <RECORD SERIAL_NBR="1">
        <EMP_ID>23456789</EMP_ID>
        <EMP_NAME>NAME</EMP_NAME>
        <EMP_ADDRESS>ADDRESS HERE</EMP_ADDRESS>
        <EMP_SIN>23456789</EMP_SIN>
        <EMP_PHONE>23456789</EMP_PHONE>
        <DATE>23456789</DATE>
        <COMMENT>COMMENT HERE</COMMENT>
    </RECORD>
</ROOT>



Thanks again
0
 
LVL 6

Expert Comment

by:Havagan
ID: 13772517
Would you accept:

<ROOT>
    <RECORD>
        <SERIAL_NBR>1</SERIAL_NBR>
        <EMP_ID>23456789</EMP_ID>
        <EMP_NAME>NAME</EMP_NAME>
        <EMP_ADDRESS>ADDRESS HERE</EMP_ADDRESS>
        <EMP_SIN>23456789</EMP_SIN>
        <EMP_PHONE>23456789</EMP_PHONE>
        <DATE>23456789</DATE>
        <COMMENT>COMMENT HERE</COMMENT>
    </RECORD>
</ROOT>

which is much easier?

DataSet can serialize to XML (.NET 2.0 will have the ability at the DataTable level) using the .WriteXML method.

Ex:

Dataset name = 'ROOT'
Table name='RECORD'
ColumnName = 'SERIAL_NBR'
ColumnName = 'EMPLOYEE_ID'
ColumnName = 'EMPLOYEE_NAME'
ColumnName = 'EMPLOYEE_ADDRESS'
ColumnName = 'EMPLOYEE_SIN'
ColumnName = 'EMPLOYEE_PHONE'
ColumnName = 'DATE_CREATED'
ColumnName = 'COMMENT'

DataSet.WriteXml("C:\PathToXml\File.xml")

will create:

<ROOT>
    <RECORD>
        <SERIAL_NBR>1</SERIAL_NBR>
        <EMP_ID>23456789</EMP_ID>
        <EMP_NAME>NAME</EMP_NAME>
        <EMP_ADDRESS>ADDRESS HERE</EMP_ADDRESS>
        <EMP_SIN>23456789</EMP_SIN>
        <EMP_PHONE>23456789</EMP_PHONE>
        <DATE>23456789</DATE>
        <COMMENT>COMMENT HERE</COMMENT>
    </RECORD>
    <RECORD>
        <SERIAL_NBR>2</SERIAL_NBR>
        <EMP_ID>22222229</EMP_ID>
        <EMP_NAME>NAME</EMP_NAME>
        <EMP_ADDRESS>ADDRESS HERE</EMP_ADDRESS>
        <EMP_SIN>22222229</EMP_SIN>
        <EMP_PHONE>22222229</EMP_PHONE>
        <DATE>22222229</DATE>
        <COMMENT>COMMENT HERE</COMMENT>
    </RECORD>
    <RECORD>
        <SERIAL_NBR>3</SERIAL_NBR>
        <EMP_ID>99999789</EMP_ID>
        <EMP_NAME>NAME</EMP_NAME>
        <EMP_ADDRESS>ADDRESS HERE</EMP_ADDRESS>
        <EMP_SIN>99999789</EMP_SIN>
        <EMP_PHONE>99999789</EMP_PHONE>
        <DATE>99999789</DATE>
        <COMMENT>COMMENT HERE</COMMENT>
    </RECORD>
</ROOT>

The xml can be read into a dataset using DataSet.ReadXml("C:\PathToXml\File.xml")
You can just write the XSD using DataSet.WriteXmlSchema("C:\PathToXml\Schema.xsd")
And read XSD using DataSet.ReadXmlSchema("C:\PathToXml\Schema.xsd")

Paul
0
 
LVL 1

Author Comment

by:comt00006
ID: 13772632
Hi Paul, thanks for the post

In your previous post there are errors.

----------------------------------------------------------------------------------
Here is your post:
----------------------------------------------------------------------------------
DataSet can serialize to XML (.NET 2.0 will have the ability at the DataTable level) using the .WriteXML method.

Ex:

Dataset name = 'ROOT'
Table name='RECORD'
ColumnName = 'SERIAL_NBR'
ColumnName = 'EMPLOYEE_ID'
ColumnName = 'EMPLOYEE_NAME'
ColumnName = 'EMPLOYEE_ADDRESS'
ColumnName = 'EMPLOYEE_SIN'
ColumnName = 'EMPLOYEE_PHONE'
ColumnName = 'DATE_CREATED'
ColumnName = 'COMMENT'

DataSet.WriteXml("C:\PathToXml\File.xml")

will create:

-----------------------------------------------------------------------------------------------------
THIS IS WRONG
-----------------------------------------------------------------------------------------------------
The WriteXML will use the actual column names (EMPLOYEE_SIN) and you have
it writen down as (EMP_SIN).
I want (EMP_SIN) and so on. How do you change names and add nodes and map
Dataset fields using XSD?
-----------------------------------------------------------------------------------------------------
<ROOT>
    <RECORD>
        <SERIAL_NBR>1</SERIAL_NBR>
        <EMP_ID>23456789</EMP_ID>
        <EMP_NAME>NAME</EMP_NAME>
        <EMP_ADDRESS>ADDRESS HERE</EMP_ADDRESS>
        <EMP_SIN>23456789</EMP_SIN>
        <EMP_PHONE>23456789</EMP_PHONE>
        <DATE>23456789</DATE>
        <COMMENT>COMMENT HERE</COMMENT>
    </RECORD>
-----------------------------------------------------------------------------------------------------

If you know how to change field names and map Dataset fields, please help me out.

Thanks in advance.
0
 
LVL 6

Accepted Solution

by:
Havagan earned 1200 total points
ID: 13775337
You're right, I didn't check your field names, I assumed you wanted your XML field names to be the same as your datatable field names. I'm compulsive like that.

I know of no easy way to map an XSD file to a DataTable definition. Whether you read the XML schema or use a strongly typed dataset, if you attempt to fill a dataset with columns which are not defined your schema they will be added to the DataTable. You're either going to have to change your DataTable column names to match your XSD or custom write a method to create an XML file manually using an XmlTextWriter and loop through your DataTable's Rows creating one Element per Column.

Paul
0
 
LVL 1

Author Comment

by:comt00006
ID: 13775610
Thanks a million.

Points have been awarded.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
Suggested Courses

600 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