Solved

Asp.Net,Xml and Xsd

Posted on 2004-09-29
32
516 Views
Last Modified: 2013-11-25
Hi

Here is my xml structure, xsd and asp.net code.
Problem :

It is displaying all column type is string

XML Structure (File Name : XMLFile1.xml):

<main>
             <SummaryInformation >
                    <PickupDate>"10/29/1845"</PickupDate>
                    <NoOfPackages >44</NoOfPackages>
                    <PublishedCharge>955.75</PublishedCharge>
                    <IncentiveCredit>-231.08</IncentiveCredit>
                    <BilledCharges>724.67</BilledCharges>
               </SummaryInformation>
                <SummaryInformation >
                    <PickupDate>10/29/1977</PickupDate>
                    <PickUpRecord Pickupid="6481802191">
                    <Details>
                    </Details>
                    </PickUpRecord>    
                    <NoOfPackages >44</NoOfPackages>
                    <PublishedCharge>955.75</PublishedCharge>
                    <IncentiveCredit>-231.08</IncentiveCredit>
                    <BilledCharges>724.67</BilledCharges>
               </SummaryInformation>
                <SummaryInformation >
                    <PickupDate>10/29/2055</PickupDate>
                    <PickUpRecord Pickupid="6481802191">
                    <Details>
                    </Details>
                    </PickUpRecord>    
                    <NoOfPackages >44</NoOfPackages>
                    <PublishedCharge>955.75</PublishedCharge>
                    <IncentiveCredit>-231.08</IncentiveCredit>
                    <BilledCharges>724.67</BilledCharges>
               </SummaryInformation>
                <SummaryInformation >
                    <PickupDate>10/29/2033</PickupDate>
                    <PickUpRecord Pickupid="6481802191">
                    <Details>
                    </Details>
                    </PickUpRecord>    
                    <NoOfPackages >44</NoOfPackages>
                    <PublishedCharge>955.75</PublishedCharge>
                    <IncentiveCredit>-231.08</IncentiveCredit>
                    <BilledCharges>724.67</BilledCharges>
               </SummaryInformation>
                <SummaryInformation >
                    <PickupDate>10/29/2002</PickupDate>
                    <PickUpRecord Pickupid="6481802191">
                    <Details>
                    </Details>
                    </PickUpRecord>    
                    <NoOfPackages >44</NoOfPackages>
                    <PublishedCharge>955.75</PublishedCharge>
                    <IncentiveCredit>-231.08</IncentiveCredit>
                    <BilledCharges>724.67</BilledCharges>
               </SummaryInformation>
                <SummaryInformation >
                    <PickupDate>10/29/2003</PickupDate>
                    <PickUpRecord Pickupid="6481802191">
                    <Details>
                    </Details>
                    </PickUpRecord>    
                    <NoOfPackages >44</NoOfPackages>
                    <PublishedCharge>955.75</PublishedCharge>
                    <IncentiveCredit>-231.08</IncentiveCredit>
                    <BilledCharges>724.67</BilledCharges>
               </SummaryInformation>
</main>


XSD(FileName : XSDSchema1.xsd) :

<xs:schema id="main" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
      <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:sequence>
                              </xs:complexType>
                        </xs:element>
                  </xs:choice>
            </xs:complexType>
      </xs:element>
</xs:schema>


This code is under PAGELOAD

DataSet xx=new DataSet();
                  xx.ReadXml(Server.MapPath("XMLFile1.xml"));
                  xx.ReadXmlSchema(Server.MapPath("XSDSchema1.xsd"));
                  
                  int count1=xx.Tables[0].Rows.Count;
                  string tablename=xx.Tables[0].TableName;

                  foreach( DataColumn dc in xx.Tables[0].Columns )
                  {
                        Response.Write(dc.ColumnName+" , "+dc.DataType +" ,"+dc.Unique +" ,"+dc.AutoIncrement+" ,"+dc.AllowDBNull );
                        Response.Write("<br>");

                  }

OutPut :

PickupDate , System.String ,False ,False ,True
NoOfPackages , System.String ,False ,False ,True
PublishedCharge , System.String ,False ,False ,True
IncentiveCredit , System.String ,False ,False ,True
BilledCharges , System.String ,False ,False ,True
SummaryInformation_Id , System.Int32 ,True ,True ,False
0
Comment
Question by:pprasadravi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 20
  • 12
32 Comments
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12184876
its displaying datatype as system.string or system.int32?

Aeros
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12184880
Response.Write(dc.ColumnName+" , "***+dc.DataType*** +" ,"+dc.Unique +" ,"+dc.AutoIncrement+" ,"+dc.AllowDBNull );
0
 

Author Comment

by:pprasadravi
ID: 12184895
Hi Aero
it is displaying "System.String" for all columns.At the bottom we have screen out put.Can you pls look that.
Thanks
Ravi
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:AerosSaga
ID: 12184907
for the columns .datatype which is what it should do
0
 

Author Comment

by:pprasadravi
ID: 12184915
what is the wrong in my code
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12184928
What do you want there?  Its displaying exactly what your asking it for a .datatype thus System.String or System.Int32 the DATATYPE of the column.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12184944
just hit dc. to see what properties you can expose.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12184979
Here are your choices:

The properties of the DataColumn class are listed here. For a complete list of DataColumn class members, see the DataColumn Members topic.
Public Properties
public propertyAllowDBNull

Supported by the .NET Compact Framework.
      Gets or sets a value indicating whether null values are allowed in this column for rows belonging to the table.
public propertyAutoIncrement

Supported by the .NET Compact Framework.
      Gets or sets a value indicating whether the column automatically increments the value of the column for new rows added to the table.
public propertyAutoIncrementSeed

Supported by the .NET Compact Framework.
      Gets or sets the starting value for a column that has its AutoIncrement property set to true.
public propertyAutoIncrementStep

Supported by the .NET Compact Framework.
      Gets or sets the increment used by a column with its AutoIncrement property set to true.
public propertyCaption

Supported by the .NET Compact Framework.
      Gets or sets the caption for the column.
public propertyColumnMapping

Supported by the .NET Compact Framework.
      Gets or sets the MappingType of the column.
public propertyColumnName

Supported by the .NET Compact Framework.
      Gets or sets the name of the column in the DataColumnCollection.
public propertyContainer (inherited from MarshalByValueComponent)       Gets the container for the component.
public propertyDataType

Supported by the .NET Compact Framework.
      Gets or sets the type of data stored in the column.
public propertyDefaultValue

Supported by the .NET Compact Framework.
      Gets or sets the default value for the column when creating new rows.
public propertyDesignMode (inherited from MarshalByValueComponent)       Gets a value indicating whether the component is currently in design mode.
public propertyExpression

Supported by the .NET Compact Framework.
      Gets or sets the expression used to filter rows, calculate the values in a column, or create an aggregate column.
public propertyExtendedProperties

Supported by the .NET Compact Framework.
      Gets the collection of custom user information associated with a DataColumn.
public propertyMaxLength

Supported by the .NET Compact Framework.
      Gets or sets the maximum length of a text column.
public propertyNamespace

Supported by the .NET Compact Framework.
      Gets or sets the namespace of the DataColumn.
public propertyOrdinal

Supported by the .NET Compact Framework.
      Gets the position of the column in the DataColumnCollection collection.
public propertyPrefix

Supported by the .NET Compact Framework.
      Gets or sets an XML prefix that aliases the namespace of the DataTable.
public propertyReadOnly

Supported by the .NET Compact Framework.
      Gets or sets a value indicating whether the column allows changes once a row has been added to the table.
public propertySite (inherited from MarshalByValueComponent)       Gets or sets the site of the component.
public propertyTable

Supported by the .NET Compact Framework.
      Gets the DataTable to which the column belongs to.
public propertyUnique

Supported by the .NET Compact Framework.
      Gets or sets a value indicating whether the values in each row of the column must be unique.
Protected Properties
protected propertyEvents (inherited from MarshalByValueComponent)       Gets the list of event handlers that are attached to this component.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataDataColumnPropertiesTopic.asp
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12184989
public propertyDataType

Supported by the .NET Compact Framework.
     Gets or sets the type of data stored in the column.

Thats why you were getting dataype you were asking for it
0
 

Author Comment

by:pprasadravi
ID: 12185106
when i am displaying datatable data types it is displaying system.string.
But i mentioned exact datatypes in schema.

                                  <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" />

when i disply the datatypes
 Response.Write(dc.ColumnName+" , "+dc.DataType +" ,"+dc.Unique +" ,"+dc.AutoIncrement+" ,"+dc.AllowDBNull );

PickupDate , System.String ,False ,False ,True
NoOfPackages , System.String ,False ,False ,True
PublishedCharge , System.String ,False ,False ,True
IncentiveCredit , System.String ,False ,False ,True
BilledCharges , System.String ,False ,False ,True
SummaryInformation_Id , System.Int32 ,True ,True ,False

thanks
Ravi
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12185142
evidently when the framework renders the xml it renders it with those types.  If you want the underlying type query the schema, instead of using response.write

0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12185146
when it renders it for html output that is
0
 

Author Comment

by:pprasadravi
ID: 12185160
agreed.but when i am sorting on dataview it is taking all  column  datatype as string.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12185162
You'll need to write it from the dataset
http://support.microsoft.com/default.aspx?scid=kb;en-us;317940
0
 

Author Comment

by:pprasadravi
ID: 12185176
but i don't have databse.i getting data from xml.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12185177
[Visual Basic]
Private Shared Sub DemonstrateGetXmlSchema()
    ' Create a DataSet with one table containing two columns.
    Dim ds As DataSet = New DataSet("myDataSet")
    Dim t As DataTable = ds.Tables.Add("Items")
    t.Columns.Add("id", Type.GetType("System.Int32"))
    t.Columns.Add("Item", Type.GetType("System.String"))

    ' Display the DataSet schema as XML.
    Console.WriteLine( ds.GetXmlSchema() )
End Sub

[C#]
private static void DemonstrateGetXmlSchema()
{
    // Create a DataSet with one table containing two columns.
    DataSet ds = new DataSet("myDataSet");
    DataTable t = ds.Tables.Add("Items");
    t.Columns.Add("id", typeof(int));
    t.Columns.Add("Item", typeof(string));

    // Display the DataSet schema as XML.
    Console.WriteLine( ds.GetXmlSchema() );
}
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12185181
I said dataset,

Youve already got it in a dataset come on man

DataSet xx=new DataSet();
               xx.ReadXml(Server.MapPath("XMLFile1.xml"));
               xx.ReadXmlSchema(Server.MapPath("XSDSchema1.xsd"));
               
               int count1=xx.Tables[0].Rows.Count;
               string tablename=xx.Tables[0].TableName;

               foreach( DataColumn dc in xx.Tables[0].Columns )
               {
                    Response.Write(dc.ColumnName+" , "+dc.DataType +" ,"+dc.Unique +" ,"+dc.AutoIncrement+" ,"+dc.AllowDBNull );
                    Response.Write("<br>");

               }
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12185205
[Visual Basic]
custDS.WriteXmlSchema("Customers.xsd")
[C#]
custDS.WriteXmlSchema("Customers.xsd");
[Visual Basic]
Dim xmlSW As System.IO.StreamWriter = New System.IO.StreamWriter("Customers.xsd")
custDS.WriteXmlSchema(xmlSW)
xmlSW.Close()
[C#]
System.IO.StreamWriter xmlSW = new System.IO.StreamWriter("Customers.xsd");
custDS.WriteXmlSchema(xmlSW);
xmlSW.Close();
To obtain the schema of a DataSet and write it as an XML Schema string, use the GetXmlSchema method as shown in the following example.

[Visual Basic]
Dim xsdDS As String = custDS.GetXmlSchema()
[C#]
string xsdDS = custDS.GetXmlSchema();
0
 

Author Comment

by:pprasadravi
ID: 12185207
Response.Write(dc.ColumnName+" , "+dc.DataType +" ,"+dc.Unique +" ,"+dc.AutoIncrement+" ,"+dc.AllowDBNull );
 displying system.string for all columns.

I am really sorry aero ,today i totally stressedout.
i have to complete this task by endof day

I am really sorry for that.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12185230
just relax man, take a breath, you've already done the hard part reading the xml into a dataset with xsd schema, try that last one:
Write from the schema file
 [Visual Basic]
custDS.WriteXmlSchema("Customers.xsd")
[C#]
custDS.WriteXmlSchema("Customers.xsd");
[Visual Basic]
Dim xmlSW As System.IO.StreamWriter = New System.IO.StreamWriter("Customers.xsd")
custDS.WriteXmlSchema(xmlSW)
xmlSW.Close()
[C#]
System.IO.StreamWriter xmlSW = new System.IO.StreamWriter("Customers.xsd");
custDS.WriteXmlSchema(xmlSW);
xmlSW.Close();
To obtain the schema of a DataSet and write it as an XML Schema string, use the GetXmlSchema method as shown in the following example.

[Visual Basic]
Dim xsdDS As String = custDS.GetXmlSchema()
[C#]
string xsdDS = custDS.GetXmlSchema();
0
 

Author Comment

by:pprasadravi
ID: 12185294
Hi Aero

i found the probelm.
the date format is not accepting .Do you have any clue.


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: String was not recognized as a valid DateTime.

Source Error:


Line 30:                   
Line 31:                   xx.ReadXmlSchema(Server.MapPath("XSDSchema1.xsd"));
Line 32:                   xx.ReadXml(Server.MapPath("XMLFile1.xml"));
Line 33:                   
Line 34:                   
 

Thanks
Ravi
0
 
LVL 17

Accepted Solution

by:
AerosSaga earned 500 total points
ID: 12185341
Youll have to step  through, according to Microsoft date is correct:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbwlkwalkthoughdesigningpurchaseorderschema.asp

See if somehow the time is getting appended, or it looks jumbled in anyway

Look at your dates they start at:
1845 and end in 2055 Maybe those dates are somehow to old or future for the schema?
0
 

Author Comment

by:pprasadravi
ID: 12185398
Accepted.I am giving points Aero.I will do research on date format.Whatever dateformat i specified it is not accepting.
i have another question.When element have attribute it is creating another table in dataset.Can't we create attribute in the same table.

Question may not be clear

In my xml PickUpRecord has attribute.So it is creating two tables
SummaryInformation and PickUpRecord.Can't we do it in one table even if we have attributes.

Thanks
Ravi
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12185495
I believe that extra table is needed for the schema .xsd
0
 

Author Comment

by:pprasadravi
ID: 12190860
no i want to create the followinde as one record in my table.So if we want we can chage schema.
<main>
<SummaryInformation >
                    <PickupDate>10/29/2003</PickupDate>
                    <PickUpRecord Pickupid="6481802191">
                    <Details>
                    </Details>
                    </PickUpRecord>    
                    <NoOfPackages >44</NoOfPackages>
                    <PublishedCharge>955.75</PublishedCharge>
                    <IncentiveCredit>-231.08</IncentiveCredit>
                    <BilledCharges>724.67</BilledCharges>
</SummaryInformation>
</main>
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12190873
what are the two tables its creating?
0
 

Author Comment

by:pprasadravi
ID: 12190897
Summaryinformation and pickuprecord

pickupid is the column for pickuprecordtable.

0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12190916
try making your initial xml something like:
<main>
                    <PickUpRecord Pickupid="6481802191">
                     <PickupDate>10/29/2003</PickupDate>
                    <Details>
                    </Details>
                    <NoOfPackages >44</NoOfPackages>
                    <PublishedCharge>955.75</PublishedCharge>
                    <IncentiveCredit>-231.08</IncentiveCredit>
                    <BilledCharges>724.67</BilledCharges>
                    </PickUpRecord>    
</main>
0
 

Author Comment

by:pprasadravi
ID: 12190951
i am sorry aero.It is rellay good solution but all elements are in the same level.I can't chage it.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12190971
well thats why your schema looks the way it does your only option then is to create a view of the dataset/schema to make it look like you want, seee my other posts in your ongoing question.
0
 

Author Comment

by:pprasadravi
ID: 12191057
agreed how can i create dataview on multiple tables.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12191096
moving to the open question now. check there I already posted the links
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21149631.html
Ok, I think you'll need to create a view of the schema and join the two tables before you bind then:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsqlmag02/html/definingxmlviews.asp
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to dynamically set the form action using jQuery.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

688 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