pprasadravi
asked on
xml xsl and dataset
Hi
I have the following xml and schema(schema may be wrong).I want to populate dataset with table name as "main" and need to add the schema for the table.
When we creating dataset from xml what is exact structure and schema structure.
Because i want to use dataview sorting so i need to add datatype to the table and need to populate the records.
XML:
<main>
<SummaryInformation >
<PickupDate value="10/29/2001"></Picku pDate>
<PickUpRecord value="6481802191"></PickU pRecord>
<NoOfPackages value="78"></NoOfPackages>
<PublishedCharge value="955.75"></Published Charge>
<IncentiveCredit value="-231.08"></Incentiv eCredit>
<BilledCharges value="724.67"></BilledCha rges>
</SummaryInformation>
<SummaryInformation >
<PickupDate value="10/29/2001"></Picku pDate>
<PickUpRecord value="6481802191"></PickU pRecord>
<NoOfPackages value="78"></NoOfPackages>
<PublishedCharge value="955.75"></Published Charge>
<IncentiveCredit value="-231.08"></Incentiv eCredit>
<BilledCharges value="724.67"></BilledCha rges>
</SummaryInformation>
<SummaryInformation >
<PickupDate value="10/29/2001"></Picku pDate>
<PickUpRecord value="6481802191"></PickU pRecord>
<NoOfPackages value="78"></NoOfPackages>
<PublishedCharge value="955.75"></Published Charge>
<IncentiveCredit value="-231.08"></Incentiv eCredit>
<BilledCharges value="724.67"></BilledCha rges>
</SummaryInformation>
<SummaryInformation >
<PickupDate value="10/29/2001"></Picku pDate>
<PickUpRecord value="6481802191"></PickU pRecord>
<NoOfPackages value="78"></NoOfPackages>
<PublishedCharge value="955.75"></Published Charge>
<IncentiveCredit value="-231.08"></Incentiv eCredit>
<BilledCharges value="724.67"></BilledCha rges>
</SummaryInformation>
</main>
XSD :
<?xml version="1.0" standalone="yes"?>
<xs:schema id="main" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas- microsoft- com:xml-ms data">
<xs:element name="main" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="SummaryInformation">
<xs:complexType>
<xs:sequence>
<xs:element name="PickupDate" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="value" type="xs:date" />
</xs:complexType>
</xs:element>
<xs:element name="PickUpRecord" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="value" type="xs:integer" />
</xs:complexType>
</xs:element>
<xs:element name="NoOfPackages" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="value" type="xs:integer" />
</xs:complexType>
</xs:element>
<xs:element name="PublishedCharge" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="value" type="xs:decimal" />
</xs:complexType>
</xs:element>
<xs:element name="IncentiveCredit" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="value" type="xs:decimal" />
</xs:complexType>
</xs:element>
<xs:element name="BilledCharges" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="value" type="xs:decimal" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
Thanks
Ravi
I have the following xml and schema(schema may be wrong).I want to populate dataset with table name as "main" and need to add the schema for the table.
When we creating dataset from xml what is exact structure and schema structure.
Because i want to use dataview sorting so i need to add datatype to the table and need to populate the records.
XML:
<main>
<SummaryInformation >
<PickupDate value="10/29/2001"></Picku
<PickUpRecord value="6481802191"></PickU
<NoOfPackages value="78"></NoOfPackages>
<PublishedCharge value="955.75"></Published
<IncentiveCredit value="-231.08"></Incentiv
<BilledCharges value="724.67"></BilledCha
</SummaryInformation>
<SummaryInformation >
<PickupDate value="10/29/2001"></Picku
<PickUpRecord value="6481802191"></PickU
<NoOfPackages value="78"></NoOfPackages>
<PublishedCharge value="955.75"></Published
<IncentiveCredit value="-231.08"></Incentiv
<BilledCharges value="724.67"></BilledCha
</SummaryInformation>
<SummaryInformation >
<PickupDate value="10/29/2001"></Picku
<PickUpRecord value="6481802191"></PickU
<NoOfPackages value="78"></NoOfPackages>
<PublishedCharge value="955.75"></Published
<IncentiveCredit value="-231.08"></Incentiv
<BilledCharges value="724.67"></BilledCha
</SummaryInformation>
<SummaryInformation >
<PickupDate value="10/29/2001"></Picku
<PickUpRecord value="6481802191"></PickU
<NoOfPackages value="78"></NoOfPackages>
<PublishedCharge value="955.75"></Published
<IncentiveCredit value="-231.08"></Incentiv
<BilledCharges value="724.67"></BilledCha
</SummaryInformation>
</main>
XSD :
<?xml version="1.0" standalone="yes"?>
<xs:schema id="main" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-
<xs:element name="main" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="SummaryInformation">
<xs:complexType>
<xs:sequence>
<xs:element name="PickupDate" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="value" type="xs:date" />
</xs:complexType>
</xs:element>
<xs:element name="PickUpRecord" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="value" type="xs:integer" />
</xs:complexType>
</xs:element>
<xs:element name="NoOfPackages" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="value" type="xs:integer" />
</xs:complexType>
</xs:element>
<xs:element name="PublishedCharge" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="value" type="xs:decimal" />
</xs:complexType>
</xs:element>
<xs:element name="IncentiveCredit" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="value" type="xs:decimal" />
</xs:complexType>
</xs:element>
<xs:element name="BilledCharges" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="value" type="xs:decimal" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
Thanks
Ravi
' Visual Basic
Dim filePath As String
filePath = "Complete path where you saved the XML file"
dsAuthors.ReadXml(filePath )
With DataGrid1
.DataSource = dsAuthors
.DataMember = "authors"
.CaptionText = .DataMember
End With
Private Sub WriteXmlToFile(thisDataSet As DataSet)
If thisDataSet Is Nothing Then
Return
End If
' Create a file name to write to.
Dim filename As String = "myXmlDoc.xml"
' Create the FileStream to write with.
Dim myFileStream As New System.IO.FileStream _
(filename, System.IO.FileMode.Create)
' Create an XmlTextWriter with the fileStream.
Dim myXmlWriter As New System.Xml.XmlTextWriter _
(myFileStream, System.Text.Encoding.Unico de)
' Write to the file with the WriteXml method.
thisDataSet.WriteXml(myXml Writer)
myXmlWriter.Close()
End Sub
Regards,
Aeros
Dim filePath As String
filePath = "Complete path where you saved the XML file"
dsAuthors.ReadXml(filePath
With DataGrid1
.DataSource = dsAuthors
.DataMember = "authors"
.CaptionText = .DataMember
End With
Private Sub WriteXmlToFile(thisDataSet
If thisDataSet Is Nothing Then
Return
End If
' Create a file name to write to.
Dim filename As String = "myXmlDoc.xml"
' Create the FileStream to write with.
Dim myFileStream As New System.IO.FileStream _
(filename, System.IO.FileMode.Create)
' Create an XmlTextWriter with the fileStream.
Dim myXmlWriter As New System.Xml.XmlTextWriter _
(myFileStream, System.Text.Encoding.Unico
' Write to the file with the WriteXml method.
thisDataSet.WriteXml(myXml
myXmlWriter.Close()
End Sub
Regards,
Aeros
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath( "countries .xml"));
XmlDataDocument xmlDoc = new XmlDataDocument(ds);
XmlNodeList nodeList = xmlDoc.DocumentElement.Sel ectNodes(" /Countries /Country[o n=true]");
ds.ReadXml(Server.MapPath(
XmlDataDocument xmlDoc = new XmlDataDocument(ds);
XmlNodeList nodeList = xmlDoc.DocumentElement.Sel
And you can use ReadXMLSchema to Apply the Schema to the dataSet
Dim myDataSet as New DataSet()
myDataSet.ReadXmlSchema(Se
If you want to see what is the defalut Scema,
myDataSet.ReadXml(Server.M apPath("ma in.xml"))
After that myDataSet.WriteXMLSchema(" main.xsd")
you can see what is the XSD the dataset has.
myDataSet.ReadXml(Server.M
After that myDataSet.WriteXMLSchema("
you can see what is the XSD the dataset has.
ASKER
hi
here is another xml document and i am getting the error.
<main>
<SummaryInformation >
<PickupDate>10/29/2001></P ickupDate>
<PickUpRecord val=6481802191></PickUpRec ord>
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P ublishedCh arge>
<IncentiveCredit>-231.08</ IncentiveC redit>
<BilledCharges>724.67</Bil ledCharges >
</SummaryInformation>
<SummaryInformation >
<PickupDate >10/29/2001></PickupDate>
<PickUpRecord val=6481802191></PickUpRec ord>
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P ublishedCh arge>
<IncentiveCredit>-231.08</ IncentiveC redit>
<BilledCharges>724.67</Bil ledCharges >
</SummaryInformation>
<SummaryInformation >
<PickupDate>10/29/2001</Pi ckupDate>
<PickUpRecord val=6481802191></PickUpRec ord>
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P ublishedCh arge>
<IncentiveCredit>-231.08</ IncentiveC redit>
<BilledCharges>724.67</Bil ledCharges >
</SummaryInformation>
<SummaryInformation >
<PickupDate>10/29/2001</Pi ckupDate>
<PickUpRecord val=6481802191></PickUpRec ord>
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P ublishedCh arge>
<IncentiveCredit>-231.08</ IncentiveC redit>
<BilledCharges>724.67</Bil ledCharges >
</SummaryInformation>
</main>
here is another xml document and i am getting the error.
<main>
<SummaryInformation >
<PickupDate>10/29/2001></P
<PickUpRecord val=6481802191></PickUpRec
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P
<IncentiveCredit>-231.08</
<BilledCharges>724.67</Bil
</SummaryInformation>
<SummaryInformation >
<PickupDate >10/29/2001></PickupDate>
<PickUpRecord val=6481802191></PickUpRec
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P
<IncentiveCredit>-231.08</
<BilledCharges>724.67</Bil
</SummaryInformation>
<SummaryInformation >
<PickupDate>10/29/2001</Pi
<PickUpRecord val=6481802191></PickUpRec
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P
<IncentiveCredit>-231.08</
<BilledCharges>724.67</Bil
</SummaryInformation>
<SummaryInformation >
<PickupDate>10/29/2001</Pi
<PickUpRecord val=6481802191></PickUpRec
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P
<IncentiveCredit>-231.08</
<BilledCharges>724.67</Bil
</SummaryInformation>
</main>
what is 'the error'?
ASKER
Error is solved.
Here is schema,xml and code.The problem is for PickUprecord it is creating anothet table with name PICKUPRECORD and have the element pickupid.for this xml it is creating two tables.
i want to populate all data in on table if it has child elemets like details we can go for another table but attribute value should populate in the same table.
Can anyone tell me what i need to chane in SCHEMA FILE.I can't change the xml structure.
Here is the scheme :
<xs:schema id="main" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas- microsoft- com:xml-ms data">
<xs:element name="main" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="SummaryInformation">
<xs:complexType>
<xs:sequence>
<xs:element name="PickupDate" type="xs:date" minOccurs="0" />
<xs:element name="NoOfPackages" type="xs:integer" minOccurs="0" />
<xs:element name="PublishedCharge" type="xs:decimal" minOccurs="0" />
<xs:element name="IncentiveCredit" type="xs:decimal" minOccurs="0" />
<xs:element name="BilledCharges" type="xs:decimal" minOccurs="0" />
<xs:element name="PickUpRecord" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Details" type="xs:integer" minOccurs="0" msdata:Ordinal="0" />
</xs:sequence>
<xs:attribute name="Pickupid" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
Here is xml :
<main>
<SummaryInformation >
<PickupDate>10/29/1845</Pi ckupDate>
<PickUpRecord Pickupid="6481802191">
<Details>
</Details>
</PickUpRecord>
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P ublishedCh arge>
<IncentiveCredit>-231.08</ IncentiveC redit>
<BilledCharges>724.67</Bil ledCharges >
</SummaryInformation>
<SummaryInformation >
<PickupDate>10/29/1977</Pi ckupDate>
<PickUpRecord Pickupid="6481802191">
<Details>
</Details>
</PickUpRecord>
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P ublishedCh arge>
<IncentiveCredit>-231.08</ IncentiveC redit>
<BilledCharges>724.67</Bil ledCharges >
</SummaryInformation>
<SummaryInformation >
<PickupDate>10/29/2055</Pi ckupDate>
<PickUpRecord Pickupid="6481802191">
<Details>
</Details>
</PickUpRecord>
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P ublishedCh arge>
<IncentiveCredit>-231.08</ IncentiveC redit>
<BilledCharges>724.67</Bil ledCharges >
</SummaryInformation>
<SummaryInformation >
<PickupDate>10/29/2033</Pi ckupDate>
<PickUpRecord Pickupid="6481802191">
<Details>
</Details>
</PickUpRecord>
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P ublishedCh arge>
<IncentiveCredit>-231.08</ IncentiveC redit>
<BilledCharges>724.67</Bil ledCharges >
</SummaryInformation>
<SummaryInformation >
<PickupDate>10/29/2002</Pi ckupDate>
<PickUpRecord Pickupid="6481802191">
<Details>
</Details>
</PickUpRecord>
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P ublishedCh arge>
<IncentiveCredit>-231.08</ IncentiveC redit>
<BilledCharges>724.67</Bil ledCharges >
</SummaryInformation>
<SummaryInformation >
<PickupDate>10/29/2003</Pi ckupDate>
<PickUpRecord Pickupid="6481802191">
<Details>
</Details>
</PickUpRecord>
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P ublishedCh arge>
<IncentiveCredit>-231.08</ IncentiveC redit>
<BilledCharges>724.67</Bil ledCharges >
</SummaryInformation>
</main>
Here is Code
DataSet xx=new DataSet();
xx.ReadXml(Server.MapPath( "XMLFile2. xml"));
xx.ReadXmlSchema(Server.Ma pPath("XSD Schema1.xs d"));
int count1=xx.Tables[0].Rows.C ount;
string tablename=xx.Tables[0].Tab leName;
foreach( DataColumn dc in xx.Tables[0].Columns )
{
Response.Write(dc.ColumnNa me+" , "+dc.DataType +" ,"+dc.Unique +" ,"+dc.AutoIncrement+" ,"+dc.AllowDBNull );
Response.Write("<br>");
}
Here is schema,xml and code.The problem is for PickUprecord it is creating anothet table with name PICKUPRECORD and have the element pickupid.for this xml it is creating two tables.
i want to populate all data in on table if it has child elemets like details we can go for another table but attribute value should populate in the same table.
Can anyone tell me what i need to chane in SCHEMA FILE.I can't change the xml structure.
Here is the scheme :
<xs:schema id="main" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-
<xs:element name="main" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="SummaryInformation">
<xs:complexType>
<xs:sequence>
<xs:element name="PickupDate" type="xs:date" minOccurs="0" />
<xs:element name="NoOfPackages" type="xs:integer" minOccurs="0" />
<xs:element name="PublishedCharge" type="xs:decimal" minOccurs="0" />
<xs:element name="IncentiveCredit" type="xs:decimal" minOccurs="0" />
<xs:element name="BilledCharges" type="xs:decimal" minOccurs="0" />
<xs:element name="PickUpRecord" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Details" type="xs:integer" minOccurs="0" msdata:Ordinal="0" />
</xs:sequence>
<xs:attribute name="Pickupid" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
Here is xml :
<main>
<SummaryInformation >
<PickupDate>10/29/1845</Pi
<PickUpRecord Pickupid="6481802191">
<Details>
</Details>
</PickUpRecord>
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P
<IncentiveCredit>-231.08</
<BilledCharges>724.67</Bil
</SummaryInformation>
<SummaryInformation >
<PickupDate>10/29/1977</Pi
<PickUpRecord Pickupid="6481802191">
<Details>
</Details>
</PickUpRecord>
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P
<IncentiveCredit>-231.08</
<BilledCharges>724.67</Bil
</SummaryInformation>
<SummaryInformation >
<PickupDate>10/29/2055</Pi
<PickUpRecord Pickupid="6481802191">
<Details>
</Details>
</PickUpRecord>
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P
<IncentiveCredit>-231.08</
<BilledCharges>724.67</Bil
</SummaryInformation>
<SummaryInformation >
<PickupDate>10/29/2033</Pi
<PickUpRecord Pickupid="6481802191">
<Details>
</Details>
</PickUpRecord>
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P
<IncentiveCredit>-231.08</
<BilledCharges>724.67</Bil
</SummaryInformation>
<SummaryInformation >
<PickupDate>10/29/2002</Pi
<PickUpRecord Pickupid="6481802191">
<Details>
</Details>
</PickUpRecord>
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P
<IncentiveCredit>-231.08</
<BilledCharges>724.67</Bil
</SummaryInformation>
<SummaryInformation >
<PickupDate>10/29/2003</Pi
<PickUpRecord Pickupid="6481802191">
<Details>
</Details>
</PickUpRecord>
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P
<IncentiveCredit>-231.08</
<BilledCharges>724.67</Bil
</SummaryInformation>
</main>
Here is Code
DataSet xx=new DataSet();
xx.ReadXml(Server.MapPath(
xx.ReadXmlSchema(Server.Ma
int count1=xx.Tables[0].Rows.C
string tablename=xx.Tables[0].Tab
foreach( DataColumn dc in xx.Tables[0].Columns )
{
Response.Write(dc.ColumnNa
Response.Write("<br>");
}
So you resolved the issue my friend?
Aeros
Aeros
Look into annotation:
Annotations enable you to modify the names of the elements in your typed DataSet without modifying the underlying schema. Modifying the names of the elements in your underlying schema would cause the typed DataSet to refer to objects that do not exist in the data source, as well as losing a reference to the objects that do exist in the data source.
Using annotations, you can customize the names of objects in your typed DataSet with more meaningful names, making code more readable and your typed DataSet easier for clients to use, while leaving underlying schema intact. For example, the following schema element for the Customers table of the Northwind database would result in a DataRow object name of CustomersRow and a DataRowCollection named Customers.
<xs:element name="Customers">
<xs:complexType>
<xs:sequence>
<xs:element name="CustomerID" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
A DataRowCollection name of Customers is meaningful in client code, but a DataRow name of CustomersRow is misleading because it is a single object. Also, in common scenarios, the object would be referred to without the Row identifier and instead would be simply referred to as a Customer object. The solution is to annotate the schema and identify new names for the DataRow and DataRowCollection objects. Following is the annotated version of the previous schema.
<xs:element name="Customers" codegen:typedName="Custome r" codegen:typedPlural="Custo mers">
<xs:complexType>
<xs:sequence>
<xs:element name="CustomerID" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
Specifying a typedName value of Customer will result in a DataRow object name of Customer. Specifying a typedPlural value of Customers preserves the DataRowCollection name of Customers.
The following table shows the annotations available for use.
Annotation Description
typedName Name of the object.
typedPlural Name of a collection of objects.
typedParent Name of the object when referred to in a parent relationship.
typedChildren Name of the method to return objects from a child relationship.
nullValue Value if the underlying value is DBNull. See the following table for nullValue annotations. The default is _throw.
The following table shows the values that can be specified for the nullValue annotation.
nullValue Description
Replacement Value Specifies a value to be returned. The returned value must match the type of the element. For example, use nullValue="0" to return 0 for null integer fields.
_throw Throw an exception. This is the default.
_null Return a null reference or throw an exception if a primitive type is encountered.
_empty For strings, return String.Empty, otherwise return an object created from an empty constructor. If a primitive type is encountered, throw an exception.
The following table shows default values for objects in a typed DataSet and the available annotations.
Object/Method/Event Default Annotation
DataTable TableNameDataTable typedPlural
DataTable Methods NewTableNameRow
AddTableNameRow
DeleteTableNameRow
typedName
DataRowCollection TableName typedPlural
DataRow TableNameRow typedName
DataColumn DataTable.ColumnNameColumn
DataRow.ColumnName
typedName
Property PropertyName typedName
Child Accessor GetChildTableNameRows typedChildren
Parent Accessor TableNameRow typedParent
DataSet Events TableNameRowChangeEvent
TableNameRowChangeEventHan dler
typedName
To use typed DataSet annotations, you must include the following xmlns reference in your XML Schema definition language (XSD) schema.
xmlns:codegen="urn:schemas -microsoft -com:xml-m sprop"
The following is a sample, annotated schema that exposes the Customers table of the Northwind database with a relation to the Orders table included.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="CustomerDataSet"
xmlns:codegen="urn:schemas -microsoft -com:xml-m sprop"
xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas- microsoft- com:xml-ms data">
<xs:element name="CustomerDataSet" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Customers" codegen:typedName="Custome r" codegen:typedPlural="Custo mers">
<xs:complexType>
<xs:sequence>
<xs:element name="CustomerID" codegen:typedName="Custome rID" type="xs:string" minOccurs="0" />
<xs:element name="CompanyName" codegen:typedName="Company Name" type="xs:string" minOccurs="0" />
<xs:element name="Phone" codegen:typedName="Phone" codegen:nullValue="" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Orders" codegen:typedName="Order" codegen:typedPlural="Order s">
<xs:complexType>
<xs:sequence>
<xs:element name="OrderID" codegen:typedName="OrderID " type="xs:int" minOccurs="0" />
<xs:element name="CustomerID" codegen:typedName="Custome rID" codegen:nullValue="" type="xs:string" minOccurs="0" />
<xs:element name="EmployeeID" codegen:typedName="Employe eID" codegen:nullValue="0" type="xs:int" minOccurs="0" />
<xs:element name="OrderDate" codegen:typedName="OrderDa te" codegen:nullValue="1980-01 -01T00:00: 00" type="xs:dateTime" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1">
<xs:selector xpath=".//Customers" />
<xs:field xpath="CustomerID" />
</xs:unique>
<xs:keyref name="CustOrders" refer="Constraint1" codegen:typedParent="Custo mer" codegen:typedChildren="Get Orders">
<xs:selector xpath=".//Orders" />
<xs:field xpath="CustomerID" />
</xs:keyref>
</xs:element>
</xs:schema>
The following code example uses a strongly typed DataSet created from the sample schema. It uses one DataAdapter to populate the Customers table and another DataAdapter to populate the Orders table. The strongly typed DataSet defines the DataRelations.
[Visual Basic]
Dim nwindConn As SqlConnection = New SqlConnection("Data Source=localhost;Integrate d Security=SSPI;" & _
"Initial Catalog=northwind")
Dim custDA As SqlDataAdapter = New SqlDataAdapter("SELECT CustomerID, CompanyName, Phone FROM Customers", &
nwindConn)
Dim orderDA As SqlDataAdapter = New SqlDataAdapter("SELECT OrderID, CustomerID, EmployeeID, OrderDate FROM Orders", &
nwindConn)
' Populate a strongly typed DataSet.
nwindConn.Open()
Dim custDS As CustomerDataSet = New CustomerDataSet()
custDA.Fill(custDS, "Customers")
orderDA.Fill(custDS, "Orders")
nwindConn.Close()
' Add a strongly typed event.
AddHandler custDS.Customers.CustomerC hanged, &
New CustomerDataSet.CustomerCh angeEventH andler(Add ressOf OnCustomerChanged)
' Add a strongly typed DataRow.
Dim newCust As CustomerDataSet.Customer = custDS.Customers.NewCustom er()
newCust.CustomerID = "NEW01"
newCust.CompanyName = "My New Company"
custDS.Customers.AddCustom er(newCust )
' Navigate the child relation.
Dim customer As CustomerDataSet.Customer
Dim order As CustomerDataSet.Order
For Each customer In custDS.Customers
Console.WriteLine(customer .CustomerI D)
For Each order In customer.GetOrders()
Console.WriteLine(vbTab & order.OrderID)
Next
Next
Private Shared Sub OnCustomerChanged(sender As Object, e As CustomerDataSet.CustomerCh angeEvent)
End Sub
[C#]
SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrate d Security=SSPI;Initial Catalog=northwind");
SqlDataAdapter custDA = new SqlDataAdapter("SELECT CustomerID, CompanyName, Phone FROM Customers", nwindConn);
SqlDataAdapter orderDA = new SqlDataAdapter("SELECT OrderID, CustomerID, EmployeeID, OrderDate FROM Orders", nwindConn);
// Populate a strongly typed DataSet.
nwindConn.Open();
CustomerDataSet custDS = new CustomerDataSet();
custDA.Fill(custDS, "Customers");
orderDA.Fill(custDS, "Orders");
nwindConn.Close();
// Add a strongly typed event.
custDS.Customers.CustomerC hanged += new
CustomerDataSet.CustomerCh angeEventH andler(OnC ustomerCha nged);
// Add a strongly typed DataRow.
CustomerDataSet.Customer newCust = custDS.Customers.NewCustom er();
newCust.CustomerID = "NEW01";
newCust.CompanyName = "My New Company";
custDS.Customers.AddCustom er(newCust );
// Navigate the child relation.
foreach(CustomerDataSet.Cu stomer customer in custDS.Customers)
{
Console.WriteLine(customer .CustomerI D);
foreach(CustomerDataSet.Or der order in customer.GetOrders())
Console.WriteLine("\t" + order.OrderID);
}
protected static void OnCustomerChanged(object sender, CustomerDataSet.CustomerCh angeEvent e)
{
}
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconusingannotationswithtypeddataset.asp
Aeros
Annotations enable you to modify the names of the elements in your typed DataSet without modifying the underlying schema. Modifying the names of the elements in your underlying schema would cause the typed DataSet to refer to objects that do not exist in the data source, as well as losing a reference to the objects that do exist in the data source.
Using annotations, you can customize the names of objects in your typed DataSet with more meaningful names, making code more readable and your typed DataSet easier for clients to use, while leaving underlying schema intact. For example, the following schema element for the Customers table of the Northwind database would result in a DataRow object name of CustomersRow and a DataRowCollection named Customers.
<xs:element name="Customers">
<xs:complexType>
<xs:sequence>
<xs:element name="CustomerID" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
A DataRowCollection name of Customers is meaningful in client code, but a DataRow name of CustomersRow is misleading because it is a single object. Also, in common scenarios, the object would be referred to without the Row identifier and instead would be simply referred to as a Customer object. The solution is to annotate the schema and identify new names for the DataRow and DataRowCollection objects. Following is the annotated version of the previous schema.
<xs:element name="Customers" codegen:typedName="Custome
<xs:complexType>
<xs:sequence>
<xs:element name="CustomerID" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
Specifying a typedName value of Customer will result in a DataRow object name of Customer. Specifying a typedPlural value of Customers preserves the DataRowCollection name of Customers.
The following table shows the annotations available for use.
Annotation Description
typedName Name of the object.
typedPlural Name of a collection of objects.
typedParent Name of the object when referred to in a parent relationship.
typedChildren Name of the method to return objects from a child relationship.
nullValue Value if the underlying value is DBNull. See the following table for nullValue annotations. The default is _throw.
The following table shows the values that can be specified for the nullValue annotation.
nullValue Description
Replacement Value Specifies a value to be returned. The returned value must match the type of the element. For example, use nullValue="0" to return 0 for null integer fields.
_throw Throw an exception. This is the default.
_null Return a null reference or throw an exception if a primitive type is encountered.
_empty For strings, return String.Empty, otherwise return an object created from an empty constructor. If a primitive type is encountered, throw an exception.
The following table shows default values for objects in a typed DataSet and the available annotations.
Object/Method/Event Default Annotation
DataTable TableNameDataTable typedPlural
DataTable Methods NewTableNameRow
AddTableNameRow
DeleteTableNameRow
typedName
DataRowCollection TableName typedPlural
DataRow TableNameRow typedName
DataColumn DataTable.ColumnNameColumn
DataRow.ColumnName
typedName
Property PropertyName typedName
Child Accessor GetChildTableNameRows typedChildren
Parent Accessor TableNameRow typedParent
DataSet Events TableNameRowChangeEvent
TableNameRowChangeEventHan
typedName
To use typed DataSet annotations, you must include the following xmlns reference in your XML Schema definition language (XSD) schema.
xmlns:codegen="urn:schemas
The following is a sample, annotated schema that exposes the Customers table of the Northwind database with a relation to the Orders table included.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="CustomerDataSet"
xmlns:codegen="urn:schemas
xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-
<xs:element name="CustomerDataSet" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Customers" codegen:typedName="Custome
<xs:complexType>
<xs:sequence>
<xs:element name="CustomerID" codegen:typedName="Custome
<xs:element name="CompanyName" codegen:typedName="Company
<xs:element name="Phone" codegen:typedName="Phone" codegen:nullValue="" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Orders" codegen:typedName="Order" codegen:typedPlural="Order
<xs:complexType>
<xs:sequence>
<xs:element name="OrderID" codegen:typedName="OrderID
<xs:element name="CustomerID" codegen:typedName="Custome
<xs:element name="EmployeeID" codegen:typedName="Employe
<xs:element name="OrderDate" codegen:typedName="OrderDa
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
<xs:unique name="Constraint1">
<xs:selector xpath=".//Customers" />
<xs:field xpath="CustomerID" />
</xs:unique>
<xs:keyref name="CustOrders" refer="Constraint1" codegen:typedParent="Custo
<xs:selector xpath=".//Orders" />
<xs:field xpath="CustomerID" />
</xs:keyref>
</xs:element>
</xs:schema>
The following code example uses a strongly typed DataSet created from the sample schema. It uses one DataAdapter to populate the Customers table and another DataAdapter to populate the Orders table. The strongly typed DataSet defines the DataRelations.
[Visual Basic]
Dim nwindConn As SqlConnection = New SqlConnection("Data Source=localhost;Integrate
"Initial Catalog=northwind")
Dim custDA As SqlDataAdapter = New SqlDataAdapter("SELECT CustomerID, CompanyName, Phone FROM Customers", &
nwindConn)
Dim orderDA As SqlDataAdapter = New SqlDataAdapter("SELECT OrderID, CustomerID, EmployeeID, OrderDate FROM Orders", &
nwindConn)
' Populate a strongly typed DataSet.
nwindConn.Open()
Dim custDS As CustomerDataSet = New CustomerDataSet()
custDA.Fill(custDS, "Customers")
orderDA.Fill(custDS, "Orders")
nwindConn.Close()
' Add a strongly typed event.
AddHandler custDS.Customers.CustomerC
New CustomerDataSet.CustomerCh
' Add a strongly typed DataRow.
Dim newCust As CustomerDataSet.Customer = custDS.Customers.NewCustom
newCust.CustomerID = "NEW01"
newCust.CompanyName = "My New Company"
custDS.Customers.AddCustom
' Navigate the child relation.
Dim customer As CustomerDataSet.Customer
Dim order As CustomerDataSet.Order
For Each customer In custDS.Customers
Console.WriteLine(customer
For Each order In customer.GetOrders()
Console.WriteLine(vbTab & order.OrderID)
Next
Next
Private Shared Sub OnCustomerChanged(sender As Object, e As CustomerDataSet.CustomerCh
End Sub
[C#]
SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrate
SqlDataAdapter custDA = new SqlDataAdapter("SELECT CustomerID, CompanyName, Phone FROM Customers", nwindConn);
SqlDataAdapter orderDA = new SqlDataAdapter("SELECT OrderID, CustomerID, EmployeeID, OrderDate FROM Orders", nwindConn);
// Populate a strongly typed DataSet.
nwindConn.Open();
CustomerDataSet custDS = new CustomerDataSet();
custDA.Fill(custDS, "Customers");
orderDA.Fill(custDS, "Orders");
nwindConn.Close();
// Add a strongly typed event.
custDS.Customers.CustomerC
CustomerDataSet.CustomerCh
// Add a strongly typed DataRow.
CustomerDataSet.Customer newCust = custDS.Customers.NewCustom
newCust.CustomerID = "NEW01";
newCust.CompanyName = "My New Company";
custDS.Customers.AddCustom
// Navigate the child relation.
foreach(CustomerDataSet.Cu
{
Console.WriteLine(customer
foreach(CustomerDataSet.Or
Console.WriteLine("\t" + order.OrderID);
}
protected static void OnCustomerChanged(object sender, CustomerDataSet.CustomerCh
{
}
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconusingannotationswithtypeddataset.asp
Aeros
ASKER
Hi Aero
Thanks for the documentation.Here is my XML file : i want to create schema for the following xml structure and when i load xml and xsd into dataset ,it should create one table in dataset.
If anybody have clue pls help me or if anybody have sample code it really helpfu..
<main>
<SummaryInformation>
<PickupDate>2/2/2004</Pick upDate>
<PickUpRecord Pickupid="6481802191">
<Details>
</Details>
</PickUpRecord>
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P ublishedCh arge>
<IncentiveCredit>-231.08</ IncentiveC redit>
<BilledCharges>724.67</Bil ledCharges >
</SummaryInformation>
<SummaryInformation>
<PickupDate>2/2/2004</Pick upDate>
<PickUpRecord Pickupid="6481802191">
<Details>
</Details>
</PickUpRecord>
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P ublishedCh arge>
<IncentiveCredit>-231.08</ IncentiveC redit>
<BilledCharges>724.67</Bil ledCharges >
</SummaryInformation>
</main>
Thanks
Ravi
Thanks for the documentation.Here is my XML file : i want to create schema for the following xml structure and when i load xml and xsd into dataset ,it should create one table in dataset.
If anybody have clue pls help me or if anybody have sample code it really helpfu..
<main>
<SummaryInformation>
<PickupDate>2/2/2004</Pick
<PickUpRecord Pickupid="6481802191">
<Details>
</Details>
</PickUpRecord>
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P
<IncentiveCredit>-231.08</
<BilledCharges>724.67</Bil
</SummaryInformation>
<SummaryInformation>
<PickupDate>2/2/2004</Pick
<PickUpRecord Pickupid="6481802191">
<Details>
</Details>
</PickUpRecord>
<NoOfPackages >44</NoOfPackages>
<PublishedCharge>955.75</P
<IncentiveCredit>-231.08</
<BilledCharges>724.67</Bil
</SummaryInformation>
</main>
Thanks
Ravi
ASKER
here is my schema :
When i load this xsd and xml i found two table in dataset.We can change xsd structure but i can't change xml structure.
or
how do i map to the dataserver control.
It is creating the following table :
SummaryInformation
child to this is
PickupRecord
i want to bind the following elements.
Pickupdate pickuprecord no of packages.
pickupdate and noofpackages is in SummaryInformation and pickupid is in pickuprecord table
so how do i create dataview with summaryinformation and pickuprecord .so i can sort on any column.
<?xml version="1.0" standalone="yes" ?>
<xs:schema id="main" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas- microsoft- com:xml-ms data">
<xs:element name="main" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="SummaryInformation">
<xs:complexType>
<xs:sequence>
<xs:element name="PickUpDate" type="xs:date" minOccurs="0" />
<xs:element name="NoOfPackages" type="xs:integer" minOccurs="0" />
<xs:element name="PublishedCharge" type="xs:decimal" minOccurs="0" />
<xs:element name="IncentiveCredit" type="xs:decimal" minOccurs="0" />
<xs:element name="BilledCharges" type="xs:decimal" minOccurs="0" />
<xs:element name="PickUpRecord" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Details" type="xs:string" minOccurs="0" msdata:Ordinal="0" />
</xs:sequence>
<xs:attribute name="Pickupid" type="xs:integer" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
Thanks
Ravi
When i load this xsd and xml i found two table in dataset.We can change xsd structure but i can't change xml structure.
or
how do i map to the dataserver control.
It is creating the following table :
SummaryInformation
child to this is
PickupRecord
i want to bind the following elements.
Pickupdate pickuprecord no of packages.
pickupdate and noofpackages is in SummaryInformation and pickupid is in pickuprecord table
so how do i create dataview with summaryinformation and pickuprecord .so i can sort on any column.
<?xml version="1.0" standalone="yes" ?>
<xs:schema id="main" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-
<xs:element name="main" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="SummaryInformation">
<xs:complexType>
<xs:sequence>
<xs:element name="PickUpDate" type="xs:date" minOccurs="0" />
<xs:element name="NoOfPackages" type="xs:integer" minOccurs="0" />
<xs:element name="PublishedCharge" type="xs:decimal" minOccurs="0" />
<xs:element name="IncentiveCredit" type="xs:decimal" minOccurs="0" />
<xs:element name="BilledCharges" type="xs:decimal" minOccurs="0" />
<xs:element name="PickUpRecord" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Details" type="xs:string" minOccurs="0" msdata:Ordinal="0" />
</xs:sequence>
<xs:attribute name="Pickupid" type="xs:integer" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
Thanks
Ravi
bind it to a datagrid:
' Visual Basic
Dim filePath As String
filePath = "Complete path where you saved the XML file"
dsAuthors.ReadXml(filePath )
With DataGrid1
.DataSource = dsAuthors
.DataMember = "authors"
.CaptionText = .DataMember
End With
Private Sub WriteXmlToFile(thisDataSet As DataSet)
If thisDataSet Is Nothing Then
Return
End If
' Create a file name to write to.
Dim filename As String = "myXmlDoc.xml"
' Create the FileStream to write with.
Dim myFileStream As New System.IO.FileStream _
(filename, System.IO.FileMode.Create)
' Create an XmlTextWriter with the fileStream.
Dim myXmlWriter As New System.Xml.XmlTextWriter _
(myFileStream, System.Text.Encoding.Unico de)
' Write to the file with the WriteXml method.
thisDataSet.WriteXml(myXml Writer)
myXmlWriter.Close()
End Sub
' Visual Basic
Dim filePath As String
filePath = "Complete path where you saved the XML file"
dsAuthors.ReadXml(filePath
With DataGrid1
.DataSource = dsAuthors
.DataMember = "authors"
.CaptionText = .DataMember
End With
Private Sub WriteXmlToFile(thisDataSet
If thisDataSet Is Nothing Then
Return
End If
' Create a file name to write to.
Dim filename As String = "myXmlDoc.xml"
' Create the FileStream to write with.
Dim myFileStream As New System.IO.FileStream _
(filename, System.IO.FileMode.Create)
' Create an XmlTextWriter with the fileStream.
Dim myXmlWriter As New System.Xml.XmlTextWriter _
(myFileStream, System.Text.Encoding.Unico
' Write to the file with the WriteXml method.
thisDataSet.WriteXml(myXml
myXmlWriter.Close()
End Sub
ASKER
here my problem is i am able create the dataset.But i am nor sure it it creates multiple table in dataset, how can i mar to repeater.
When i want to sort on pickuprecord how can i do?
When i want to sort on pickuprecord how can i do?
well the datagrid handles all that for you, if you chose the repeater you would have to manually write sorting and paging routines
ASKER
sorry the question is not clear.I am explaining again
When i load xml and xsd into dataset.It is creating two tables.I want to create only one table in dataset.I can't change xml structure but i can chage xsd schema.
I think this time i explained better aero.
When i load xml and xsd into dataset.It is creating two tables.I want to create only one table in dataset.I can't change xml structure but i can chage xsd schema.
I think this time i explained better aero.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
also check here:
http://support.microsoft.com/default.aspx?scid=kb;en-us;317940#2
http://support.microsoft.com/default.aspx?scid=kb;en-us;317940#2
His schema forced multiple tables, his only opton was a view or to change the schema, request points.
Aeros
Aeros
for example :
Dim myDataSet as New DataSet()
myDataSet.ReadXml(Server.M