Advertisement

03.29.2008 at 09:20AM PDT, ID: 23279534
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

VS2005  Linking XML document to XSD file

Tags: Visual Basic (Visual Studio 2005, Windows Forms)
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
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:
<?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>
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: FJRMill
Solution Provided By: TheLearnedOne
Participating Experts: 1
Solution Grade: B
Views: 91
Translate:
Loading Advertisement...
03.30.2008 at 05:24AM PDT, ID: 21240448

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.31.2008 at 02:44AM PDT, ID: 21244152

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.31.2008 at 05:46AM PDT, ID: 21244828

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.31.2008 at 06:54AM PDT, ID: 21245343

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.31.2008 at 07:13AM PDT, ID: 21245519

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.31.2008 at 12:16PM PDT, ID: 21248207

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.31.2008 at 12:35PM PDT, ID: 21248377

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.01.2008 at 01:40PM PDT, ID: 21257893

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.01.2008 at 06:30PM PDT, ID: 21259486

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
03.30.2008 at 05:24AM PDT, ID: 21240448

Rank: Genius

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
 
03.31.2008 at 02:44AM PDT, ID: 21244152
Hi Bob

Thanks for your response.  I'm using Visual Studio 2005.  I tried hard to provide the background to my problem .. but my primary aim is to get and answer to the 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?

Ultimately, when I have got my head around the methods to apply, I intend to read-in, manipulate/display the data, and write-back to the XML file using code behind Windows forms.
 
03.31.2008 at 05:46AM PDT, ID: 21244828

Rank: Genius

Are you using Express, Professional, or Team Suite 2005?  What do you mean by "opened in Data view"?

Bob
 
03.31.2008 at 06:54AM PDT, ID: 21245343
Hello again Bob.

I'm Using VS 2005 Professional.

Right clicking on the XML document within VS gives  a contextual menu which includes a view Data option. Without a root node, the default xml file shows nothing in the data view. How do I get this new xml document to automatically pick up its structure from the designated xsd?


{ when I select my .xsd file from the list which shows when clicking the elipsis in the xml properties window ('Schemas' property), nothing changes in the text of the .xml document itself .. whereas in the \LearnVisualStudio video, selecting an xsd file against TargetSchema does amend the .xml text.. }

Thanks

Mill.
 
03.31.2008 at 07:13AM PDT, ID: 21245519

Rank: Genius

Mill,

You can attach a screen shot .png file that shows what you have tried?

Bob
 
03.31.2008 at 12:16PM PDT, ID: 21248207
Hello again Bob.

I started by creating the .xsd in Design view:
{xsd-01.png}

This automatically converts to the code view I provided in the 'code snippet' above.

I then created a new xml file. This defaults to the single line file as shown in:
{xsd-02.png}  

To associate the new xml file to the xsd, I went to 'Properties/Schemas' and clicked on the elipsis.  ...     .  This opens the XSD Schemas dialogue box.  I select the XSD I have just created and click OK.
Also: {xsd-02.png}

At this point, according to the LearnVisualStudio video, we would like the xml file to be amended by Visual Studio to reference the xsd file - but this does not happen.

File {xsd-03.png} shows the end result. The Schemas property is referencing the xsd file .. but the text of the xml file does not change ..


Note all along, the red 'squiggly' at the end of the single line of code in the xml file. Hover the cursor over this and get the message 'xml file must contain a root element'


Thanks

Mill








 
Xsd in design view
Xsd in design view
 
 
default xml file
default xml file
 
 
default xml file with Schema association
default xml file with Schema association
 
 
03.31.2008 at 12:35PM PDT, ID: 21248377

Rank: Genius

I didn't watch the video again, but this is how I would do it.

1) On line 2, type '<', and you will get a dropdown of the allowable entries.  

2) Double click on the namespace entry in the list, and you'll get something like this:

<AdventureWorksDataSet xmlns="http://tempuri.org/AdventureWorksDataSet.xsd"

3) Close the tag with '>' at the end, and you'll automatically get this:

<AdventureWorksDataSet xmlns="http://tempuri.org/AdventureWorksDataSet.xsd"></AdventureWorksDataSet>

4) Repeat the process for other elements.

Example:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
<AdventureWorksDataSet xmlns="http://tempuri.org/AdventureWorksDataSet.xsd">
  <Employee>
    <EmployeeID></EmployeeID>
    <NationalIDNumber></NationalIDNumber>
    <ContactID></ContactID>
    <LoginID></LoginID>
    <ManagerID></ManagerID>
    <Title></Title>
    <BirthDate></BirthDate>
    <MaritalStatus></MaritalStatus>
    <Gender></Gender>
    <HireDate></HireDate>
    <SalariedFlag></SalariedFlag>
    <VacationHours></VacationHours>
    <SickLeaveHours></SickLeaveHours>
    <CurrentFlag></CurrentFlag>
    <rowguid></rowguid>
    <ModifiedDate></ModifiedDate>
  </Employee>
</AdventureWorksDataSet>
Open in New Window
Accepted Solution
 
04.01.2008 at 01:40PM PDT, ID: 21257893
Thanks Bob

Yes, I followed your example and I have created am xml file that is validated by the xsd file. I guess that's 'objective achieved' :)

This has just been an example to help me get to understand the VS2005 methods.  In the system I aim to develop, the data structure will be more demanding. As I said earlier, and in the previous thread, I aim to handle the transfer of data with code behind windows forms.

Was I being too naive to think that by linking a new xml file to an existing xsd file, that it would automatically pick up the required structure?  It seems a little long-winded to have to manually create the structure (despite the very useful 'intellisense' prompting).

Mill
 
04.01.2008 at 06:30PM PDT, ID: 21259486

Rank: Genius

Mill,

You need to think about a schema from the point of view of validation.  The objective for a schema file is to allow the IDE to validate the entries, and determine what are allowable values.  This also helps with XML file parsing, so that you can look for expected values, and trap for malformed XML.

Bob
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628