Dear experts
I need to handle xml data using visual basic in a windows forms project in Visual Studio 2005. My intention is to create an XML file, linked to an .XSD file to represent a small collection of database tables. I am designing an application to read in data from the XML file, append new records, amend records, and display selected records.
New to this, work has quickly ground to a halt because the guidance I am following suggests that once a schema file has been created, it is very simple to add a new XML document to the VS project and link this to the schema.
I have replicated the .XSD file provided as an example
See code snippet:
However, when I add a new .xml document to the project, by default, the new document contains only a single line:
<?xml version="1.0" encoding="utf-8" ?>
VS2005 shows an error (red wiggly) at the end of the line. Hovering the cursor over the red wiggly displays following error text:
XML document must contain a root level element
Please look at the LearnVisualStudio video here:
http://gmilner.myzen.co.uk/2502.wmv
In this video, at about 1 minute 20 seconds, the trainer demonstrates the creation of an xml document within Visual Studio .. but he does not get the root element error I am experiencing. OK, it is likely that he is using a different version of VS, also, the video refers to the TargetSchema property, where XML documents in VS2005 have a Schemas property.
I have hooked the Schemas property of my new XML document to my XSD file but this appears to have no effect in the XML document.
My question:
In VS 2005, how do we associate an XML document with an XSD schema file, so that when the xml document is opened in Data view in Visual Studio, the XSD structure is applied?
Linked question:
http://www.experts-exchange.com/Database/Miscellaneous/Q_23266426.html
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="EmplyeesSchema" targetNamespace="http://tempuri.org/EmplyeesSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/EmplyeesSchema.xsd" xmlns:mstns="http://tempuri.org/EmplyeesSchema.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="ZipCode">
<xs:restriction base="xs:positiveInteger">
<xs:pattern value="\d{5}" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="Address">
<xs:sequence>
<xs:element name="Name" type="xs:string" />
<xs:element name="Street" type="xs:string" />
<xs:element name="State" type="xs:string" />
<xs:element name="Zip" type="ZipCode" />
</xs:sequence>
</xs:complexType>
<xs:element name="EmployeeList">
<xs:complexType>
<xs:sequence>
<xs:element name="Employee">
<xs:complexType>
<xs:sequence>
<xs:element name="Email" type="xs:string" />
<xs:element name="Password" type="xs:string" />
<xs:element name="HomeAddress" type="Address" />
<xs:element name="OtherAddress" type="Address" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
Select allOpen in new window
by: TheLearnedOnePosted on 2008-03-30 at 05:24:43ID: 21240448
1) Who knows what version of .NET 2005 that is.
2) What version do you have?
3) That error is not really important, if you plan to continue and add XML text to the document.
Bob