Im using VS2010 professional and am trying to teach myself how to use an XML file to store information.
I have added an XSD file to the project with the following code:
I've also added an XML file to the project and set the schema to Study_Aid_Schema.xsd in the properties pane. The XML file contains the following code.Code:<?xml version="1.0" encoding="utf-8"?> <xs:schema id="Study_Aid_Schema" targetNamespace="http://tempuri.org/XMLSchema1.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema1.xsd" xmlns:mstns="http://tempuri.org/XMLSchema1.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" > <xs:element name="Study"> <xs:complexType> <xs:sequence> <xs:element name="Subject" minOccurs="1" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="Title" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element> <xs:element name="Topic" minOccurs="1" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="Title" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element> <xs:element name="StudyAid" minOccurs="1" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="Box" type="xs:integer" minOccurs="1" maxOccurs="1"></xs:element> <xs:element name="LastLearned" type="xs:date" minOccurs="1" maxOccurs="1"></xs:element> <xs:element name="TimesLearned" type="xs:integer" minOccurs="1" maxOccurs="1"></xs:element> <xs:element name="CorrectAnswer" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element> <xs:element name="Field1" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element> <xs:element name="Field2" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element> <xs:element name="Field3" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element> <xs:element name="Field4" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element> <xs:element name="Field5" type="xs:string" minOccurs="1" maxOccurs="1"></xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>But when I try to access the information in the XML file with a data set I get the schema information for element not found error for every element in the XML file. This is the code I am using to try and access the data.Code:<?xml version="1.0" encoding="utf-8" ?> <Study> <Subject> <Title>SampleSubject</Title> <Topic> <Title>SampleTopic</Title> <StudyAid> <Box>0</Box> <LastLearned>2011\03\02</LastLearned> <TimesLearned>0</TimesLearned> <CorrectAnswer>A</CorrectAnswer> <Field1>This is the sample questions for sample 1</Field1> <Field2>This is the Sample A answer</Field2> <Field3>This is the Sample B answer</Field3> <Field4>This is the Sample C answer</Field4> <Field5>This is the Sample D answer</Field5> </StudyAid> </Topic> </Subject> </Study>Anyone have any idea where I am going wrong?Code:Public Class Form2 Private DS_Aids As New DataSet Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click DS_Aids.ReadXmlSchema("Study_Aid_Schema.xsd") DS_Aids.ReadXml("Study_Aid.xml") For Each Subject In DS_Aids.Tables("Subject") lbSubjectBox.Items.Add(Subject.ToString) Next Subject End Sub End Class




Reply With Quote