Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating a xml and xsd to hold data

Status
Not open for further replies.

robUK2

Programmer
Mar 10, 2008
57
TH
Hello,

It reads the xsd ok, but fails to read the xml.

What I am trying to do is create a table from the xml with no data. Just an empty table that I can use to start filling.

The columns will be as follows: ID, Name, and Number. So the xml will create this table and contain no data.

The ID number will be an integer that will be auto-incremented.

This is my current xml and xsd file. Below is the code I am using to read the xml and xsd.

Code:
<?xml version="1.0" encoding="utf-8" ?>
<RedialNumbers>
  <RecentNumber>
    <ID></ID>
    <Name></Name>
    <Number></Number>
  </RecentNumber>
</RedialNumbers>


Code:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema">[/URL]
  <xs:element minOccurs="0" name="RedialNumbers">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="RecentNumber">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="ID" />
              <xs:element name="Name" />
              <xs:element name="Number" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>


Code:
 //Read xml dialed numbers and set binding source to dsDialedNumbers
                this.dsDialedNumber.ReadXmlSchema(Path.Combine(path, "DialledNumbers1.xsd"));
                this.dsDialedNumber.Tables[0].Columns[0].DataType = typeof(int);
                this.dsDialedNumber.Tables[0].Columns[0].AutoIncrement = true;
                this.dsDialedNumber.Tables[0].Columns[0].AutoIncrementStep = 1;

                this.dsDialedNumber.ReadXml(Path.Combine(path, "DialledNumbers.xml")); //ERROR HERE "FORMAT EXECEPTION"
                
                this.bsRedialedNumbers.DataSource = dsDialedNumber.Tables[0].DefaultView;

                //Bind combo box to for re-dialed numbers.
                this.cboRecentNumbers.DataSource = this.bsRedialedNumbers;
                this.cboRecentNumbers.DisplayMember = "Name";
                this.cboRecentNumbers.ValueMember = "ID";

                this.bsRedialedNumbers.Sort = "ID DESC";
However, when I insert a 0 into the ID field. <ID>0<ID> the code runs as normal. However, I get 1 record already created. I don't want to start with any data already inserted.

many thanks for continued help,

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top