Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Architecture
ASP.NET
ASP.NET MVC
ASP.NET WebForms
B2B (Business Integration)
BizTalk
Book Excerpts
Build and Deploy
C#
C++
Code Contracts
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Design Patterns
Development Process
Display Technologies
Distributed Computing
DotNetNuke
DSL
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Graphics
Internet Explorer 8.0
Interviews
iPhone
Java
Java Script
jQuery
LINQ
Linux
Mac OS X
MDX
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
Network
NHibernate
Object Oriented Development
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
Podcasts
Post Mortem
PowerPoint
Print/Output
Product News
Product Reviews
Project Management
Python
Q&A
Reporting Services
REST
RIA Services
Ruby
Search
Security
Services
SharePoint
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server CE/AnyWhere/Mobile/Compact
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
Tips
UI Design
UML
User Groups
VB Script
VB.NET
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WF
Whitepapers
Windows 7
Windows Azure
Windows Live
Windows Server
Windows Vista
WinForms
Workflow
WPF
XAML
XML
XNA
XSLT



ESDC


 


GiveCamp - Coding for Charity

Reader rating:
Click here to read 2 comments about this article.
Article source: CoDe (2007 - Vol. 4 - Issue 3 - Data Programability )


Article Pages:  1  2 - Next >


XML Tools in Visual Studio 2008

XML is everywhere from XML Web Services to databases to config files to Office documents. This article will show you tooling support offered in Visual Studio 2008 that will make working with XML easier. It will cover editing XML files, working with XML schemas, debugging XSLT style sheets and extending Visual Studio by writing your own custom XML Designers.

When you open a file with an XML extension in Visual Studio 2008 (for example, .xml, .xsd, .xslt, svg, or .config), you will invoke its XML Editor. XML Editor comes with a full range of features you would expect from a Visual Studio editor, which includes IntelliSense, color-coding, brace matching, outlining, and formatting. It provides full XML 1.0 syntax checking, end-tag completion, as well as DTD and XML schema support with real-time validation.

"
XML Editor comes with a full range of features you would expect from a Visual Studio editor, which includes IntelliSense, color-coding, brace matching, and formatting.
"

Editing XML Files

Face it, manual editing of XML files can be very tedious and time consuming. To help with this, the Visual Studio 2008 XML Editor comes with a number of productivity enhancement features. One such feature is an extensible library of XML code snippets-XML files that contain a configurable code segment, which acts as a template to use while editing documents. Visual Studio installs a number of XML code snippets that help developers to write XML schemas and XSLT style sheets. To invoke a snippet while editing an XML file, select “Insert Snippet” from the “Edit > IntelliSense” menu. Once you have inserted a snippet, you can TAB between highlighted modifiable fields to enter data. Figure 1 shows an example of inserting a snippet.

Click for a larger version of this image.

Figure 1: Invoking an XML snippet in Visual Studio 2008.

You can also write your own snippets. If you want to create a simple snippet, follow these easy steps:

  1. Create a new XML file and type in:
<snippet
  1. Press ESCAPE to close the IntelliSense window.
  2. Press TAB.
  3. Fill in the blanks.
  4. Press ENTER to finish.

For more detailed information about creating snippets, I recommend VSEditor’s blog post “Code Snippet - Schema Description” (http://blogs.msdn.com/vseditor/archive/2004/07/14/183189.aspx).

So what do you do when there are no snippets and you need to create an XML file based on an existing schema? XML Editor offers a wide range of features when you associate your XML documents with XML schemas. Schema-based IntelliSense, real-time validation, and error reporting are just a few of them. In addition, XML Editor can dynamically generate snippets based on an existing schema. Once you provide a name of the element you want to add, the XML Editor can parse the schema for required information, generate a snippet, and insert it for you. To invoke dynamic snippet functionality, all you need to do is type the name of the element as in the following example:

<element_name

and press TAB. The XML Editor will create a snippet, which looks very much like the one in Figure 1 except this time you didn’t have to do anything up front. This is a very powerful feature, especially when you need to create documents with large content models.

By default the XML Editor generates only the required content, but this can be customized by annotating your XML schemas. More information is available on MSDN under, “How to: Generate an XML Snippet From an XML Schema”.

Schema Cache and Schema Catalogs

For advanced users, XML Editor offers features such as schema cache and schema catalog files. Schema cache is a folder that contains a number of well-known W3C schemas, as well as a number of Microsoft-specific schemas. It serves as a repository of widely used schemas that are unlikely to change. You’ll find the default location for the schema cache at %vsinstalldir%\xml\schemas, where “%vsinstalldir%” is a variable representing the location in which Visual Studio itself was installed. When you declare one of the namespaces defined by these schemas in your XML files, XML Editor will automatically associate appropriate schemas from the cache location and instantly provide you with IntelliSense and validation.

Schema catalogs are XML files located in the Schema Cache directory (catalog.xml file is the default). They give advanced users more granular control over various namespaces they might want to use. For example, you can associate specific namespaces with external locations:

<Schema 
    href="mylocation/myschema.xsd" 
    targetNamespace="http://myschema"/>

You can also use catalog files to create associations between schema files and file extensions, which you can find particularly useful when your schema has no targetNamespace:

<Association 
    extension="config"
    schema="xml/schemas/dotNetConfig.xsd"/>

New in Visual Studio 2008, you can also add conditions:

<Association 
    extension="config" 
    schema="xml/schemas/dotNetConfig30.xsd"
    condition="%TargetFrameworkVersion% = 3.0" />

This condition means that the dotNetConfig30.xsd schema should only be associated when the current project is targeting .NET Framework version 3.0.

Finally, you can create a chain by pointing one catalog file at another:

<Catalog href="http://mycompany/catalog.xml"/>

Working with Large Files

Another important editing feature I would like to highlight is the XML Editor’s support for editing large files. While you could work with large files in previous versions, Visual Studio 2008 supports incremental parsing of the XML documents. Now if you work with a 10 MB file, you don’t have to wait for Visual Studio to parse the entire file every time you make an edit. The XML Editor will isolate the edits and reparse only what’s needed, offering better performance and responsiveness.

I have covered a few interesting features of XML Editor, but obviously couldn’t go over all of them. Table 1 shows some of the other features available to Visual Studio users.

&

By: Stan Kitsis

Stan Kitsis is a Program Manager in the Data Programmability team at Microsoft. Stan has over 10 years of software development experience. His primary focus is on the XML tools, which include XML Editor, XSLT Debugger, and XML Schema Designer. Prior to working on the XML tools, Stan was responsible for parts of the System.xml and MSXML APIs.

stan.kitsis@microsoft.com

Fast Facts

“Visual Studio seems to be the best editor for XML (compared to Eclipse plugins and NetBeans) and I use it even when my Web project is Java based.”



Table1: Overview of XML Editor features available in Visual Studio 2008.
FeatureVisual Studio 2008 Support
Auto-completionX
Syntax coloring X
Outlining X
IntelliSense X
Extendable snippet library X
Dynamic snippets X
Go to definition (from XML to XSD) X
Back/Forward navigation X
Project and user profile support X
Real-time validation X
Full XSD Support X
Namespace support X
DTD support X
XML-to-XSD generation X
DTD-to-XSD conversion X
Unicode support X
Large file support (10 MB+) X


Article Pages:  1  2 - Next Page: 'Debugging XSLT Style Sheets' >>

Page 1: XML Tools in Visual Studio 2008
Page 2: Debugging XSLT Style Sheets

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
3.4 out of 5

16 people have rated this article.

      Sharepoint TechCon

 

VFPConversion.com