comt00006
asked on
VB.NET Dataset and XSD document
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.
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.
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_P HONE>
<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:\PathT oXml\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_P HONE>
<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_P HONE>
<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_P HONE>
<DATE>99999789</DATE>
<COMMENT>COMMENT HERE</COMMENT>
</RECORD>
</ROOT>
The xml can be read into a dataset using DataSet.ReadXml("C:\PathTo Xml\File.x ml")
You can just write the XSD using DataSet.WriteXmlSchema("C: \PathToXml \Schema.xs d")
And read XSD using DataSet.ReadXmlSchema("C:\ PathToXml\ Schema.xsd ")
Paul
<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_P
<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:\PathT
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_P
<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_P
<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_P
<DATE>99999789</DATE>
<COMMENT>COMMENT HERE</COMMENT>
</RECORD>
</ROOT>
The xml can be read into a dataset using DataSet.ReadXml("C:\PathTo
You can just write the XSD using DataSet.WriteXmlSchema("C:
And read XSD using DataSet.ReadXmlSchema("C:\
Paul
ASKER
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:\PathT oXml\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_P HONE>
<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.
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:\PathT
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_P
<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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a million.
Points have been awarded.
Points have been awarded.
ASKER
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_P
<DATE>23456789</DATE>
<COMMENT>COMMENT HERE</COMMENT>
</RECORD>
</ROOT>
Thanks again