1 YEAR UPGRADE
BUYER PROTECTION PLAN
Develop and Deliver Enterprise-Critical Applications with XML .NET
• Complete Case Studies with Ready-to-Run Source Code and Full Explanations
• Hundreds of Developing & Deploying, and Debugging Sidebars, Security Alerts,
and FAQs
• Complete Coverage of Web Services and the VS.NET Integrated Development
Environment (IDE)
XML
.NET
Developer’s
Guide
Adam Sills
Mesbah Ahmed
Dotthatcom.com
Frank Boumphrey
Jonothon Ortiz
Technical Editor
With more than 1,500,000 copies of our MCSE, MCSD, CompTIA, and Cisco
study guides in print, we continue to look for ways we can better serve the
information needs of our readers. One way we do that is by listening.
Readers like yourself have been telling us they want an Internet-based ser-
vice that would extend and enhance the value of our books. Based on
reader feedback and our own strategic plan, we have created a Web site
that we hope will exceed your expectations.
is an interactive treasure trove of useful infor-
mation focusing on our book topics and related technologies. The site
offers the following features:
■
One-year warranty against content obsolescence due to vendor
Jonothon Ortiz
Technical Editor
155_XML_NET_FM.qxd 3/7/02 3:01 PM Page iii
Syngress Publishing, Inc., the author(s), and any person or firm involved in the writing, editing, or
production (collectively “Makers”) of this book (“the Work”) do not guarantee or warrant the results
to be obtained from the Work.
There is no guarantee of any kind, expressed or implied, regarding the Work or its contents.The Work
is sold AS IS and WITHOUT WARRANTY. You may have other legal rights, which vary from state
to state.
In no event will Makers be liable to you for damages, including any loss of profits, lost savings, or
other incidental or consequential damages arising out from the Work or its contents. Because some
states do not allow the exclusion or limitation of liability for consequential or incidental damages, the
above limitation may not apply to you.
You should always use reasonable care, including backup and other appropriate precautions, when
working with computers, networks, data, and files.
Syngress Media®, Syngress®,“Career Advancement Through Skill Enhancement®,” and “Ask the
Author UPDATE®,” are registered trademarks of Syngress Publishing, Inc. “Mission Critical™,”“Hack
Proofing™,” and “The Only Way to Stop a Hacker is to Think Like One™” are trademarks of Syngress
Publishing, Inc. Brands and product names mentioned in this book are trademarks or service marks of
their respective companies.
KEY SERIAL NUMBER
001 PKH4T67VT5
002 ESTRT45RF4
003 BHER6W354N
004 9HD34B3QAN
005 ZR88JN6NVH
006 NTG4R54RM4
007 CG8VHTR46T
008 D6Y9R565MR
009 22N5M4BX6S
Kevin Votel, Kent Anderson, Frida Yara, Bill Getz, Jon Mayes, John Mesjak, Peg
O’Donnell, Sandra Patterson, Betty Redmond, Roy Remer, Ron Shapiro, Patricia
Kelly, Andrea Tetrick, Jennifer Pascal, Doug Reil, and David Dahl of Publishers
Group West for sharing their incredible marketing experience and expertise.
Jacquie Shanahan, AnnHelen Lindeholm, David Burton, Febea Marinetti, and Rosie
Moss of Elsevier Science for making certain that our vision remains worldwide in
scope.
Annabel Dent and Paul Barry of Elsevier Science/Harcourt Australia for all their help.
David Buckland,Wendi Wong, Marie Chieng, Lucy Chong, Leslie Lim, Audrey Gan,
and Joseph Chan of Transquest Publishers for the enthusiasm with which they receive
our books.
Kwon Sung June at Acorn Publishing for his support.
Ethan Atkin at Cranbury International for his help in expanding the Syngress
program.
Jackie Gross, Gayle Voycey, Alexia Penny, Anik Robitaille, Craig Siddall, Darlene
Morrow, Iolanda Miller, Jane Mackay, and Marie Skelly at Jackie Gross & Associates
for all their help and enthusiasm representing our product in Canada.
Lois Fraser, Connie McMenemy, Shannon Russell and the rest of the great folks at
Jaguar Book Group for their help with distribution of Syngress books in Canada.
155_XML_NET_FM.qxd 3/7/02 3:01 PM Page v
vi
Contributors
Adam Sills is an Internet Programmer at GreatLand Insurance, a small
insurance company parented by Kemper Insurance. He works in a small IT
department that focuses on creating applications to expedite business pro-
cesses and manage data from a multitude of locations. Previously, he had a
small stint in consulting and also worked at a leading B2B eCommerce
company designing and building user interfaces to interact with a large-
scale enterprise eCommerce application.Adam’s current duties include
building and maintaining Web applications, as well as helping to architect,
Extension, North Seattle Community College, Puget Sound Center, and
Seattle Vocational Institute, where he teaches courses in Web Development
(DHTML, ASP, XML, XSLT, C#, and ASP.NET). Patrick is a Co-Founder
of DotThatCom.com, a company that provides consulting, online develop-
ment resources, and internships for students. He is currently working on a
.NET solution with contributing author David Jorgensen and nLogix.
Patrick holds a bachelor of science degree from the University of
Washington, Bothell. He lives in Puyallup,Washington with his wife,
Angela. Patrick is a contributor to Syngress Publishing’s C# .NET Web
Developer’s Guide (ISBN: 1-928994-50-4) and the ASP .NET Web
Developer’s Guide (ISBN: 1-928994-51-2).
David Jorgensen (MCP) is an instructor at North Seattle Community
College, University of Washington Extension campus, and Puget Sound
Centers. He is also developing courses for Seattle Vocational Institute, which
teach .NET and Web development to the underprivileged in the Seattle
area. David also provides internship opportunities through his company,
DotThatCom.com, which does online sample classes and chapters of books.
David holds a bachelor’s degree in Computer Science from St. Martin’s
College and resides in Puyallup,Washington, with his wife, Lisa and their
two sons, Scott and Jacob. David is a contributor to Syngress Publishing’s
C# .NET Web Developer’s Guide (ISBN: 1-928994-50-4) and the
ASP .NET Web Developer’s Guide (ISBN: 1-928994-51-2).
Joe Dulay (MCSD) is the Vice-President of Technology for the IT Age
Corporation. IT Age Corporation is a project management and software
development firm specializing in customer-oriented business enterprise
and e-commerce solutions located in Atlanta, Georgia. His current
155_XML_NET_FM.qxd 3/7/02 3:01 PM Page vii
viii
responsibilities include managing the IT department, heading the tech-
nology steering committee, software architecture, e-commerce product
155_XML_NET_FM.qxd 3/7/02 3:01 PM Page viii
ix
and research, he provides technical consulting and training for IT and
manufacturing industries in Ohio and Michigan. His consulting experi-
ence includes systems design and implementation projects with Ford
Motors, Dana Corporation, Riverside Hospital, Sears, and others.
Currently, he provides IT training in the areas of Java Server, XML, and
.NET technologies. He teaches graduate level courses in Database
Systems, Manufacturing Systems, and Application Development in
Distributed and Web Environment. Recently, he received the University
of Toledo Outstanding Teaching award, and the College of Business
Graduate Teaching Excellence award. His current research interests are in
the areas of data warehousing and data mining. He has published many
research articles in academic journals such as Decision Sciences, Information
& Management, Naval Research Logistic Quarterly, Journal of Operations
Management, IIE Transaction, and International Journal of Production Research.
He has also presented numerous papers and seminars in many national
and international conferences. Mesbah is also a co-author of Syngress
Publishing’s ASP .NET Web Developer’s Guide (ISBN: 1-928994-51-2).
Dreamtech Software India, Inc., is a leading provider of corporate
software solutions. Based in New Delhi, the company is a successful pio-
neer of innovative solutions in e-learning technologies.The Dreamtech
Software team, which authored all the books in the Cracking the Code
series has over 50 years of combined software-engineering experience in
areas such as Java, wireless application, XML, voice-based solutions, .NET,
COM/COM+ technologies, distributed computing, DirectX,Windows
Media technologies, and security solutions. For more information, log on
to www.dreamtechsoftware.com.
Frank Boumphrey is a retired professor of surgery who now specializes in
Internet applications and medical documentation. As well as numerous
Foreword xxi
Chapter 1 Introducing the Microsoft
.NET Framework 1
Introduction 2
What Is the .NET Framework? 3
Introduction to the Common Language Runtime 3
Using .NET-Compliant Programming Languages 5
Creating Assemblies 5
Using the Manifest 8
Assembly Cache 11
Locating an Assembly 12
Private Assembly Files 17
Shared Assembly Files 17
Understanding Metadata 17
The Benefits of Metadata 18
Identifying an Assembly with Metadata 18
Types 19
Defining Members 19
Using Contracts 20
Assembly Dependencies 21
Unmanaged Assembly Code 21
Reflection 21
Attributes 22
Ending DLL Hell 22
Side-by-Side Deployment 23
Versioning Support 23
Using System Services 24
Exception Handling 24
Step 1 of the Location
Process
Gaining Representation through
a Principal 45
Security Policy 46
Summary 48
Solutions Fast Track 49
Frequently Asked Questions 52
Chapter 2 Visual Studio.NET IDE 55
Introduction 56
Introducing Visual Studio.NET 56
Components of VS.NET 58
Design Window 59
Code Window 59
Server Explorer 60
Toolbox 61
Docking Windows 62
Properties Explorer 63
Solution Explorer 64
The Toolbox Window
155_XML_NET_TOC.qxd 3/7/02 3:12 PM Page xii
Contents xiii
Class View 65
Dynamic Help 66
Task List Explorer 67
Features of VS.NET 68
IntelliSense 68
XML Editor 70
Documentation Generation
(XML Embedded Commenting) 73
Adding XML Document Comments
to C# Pages 74
■
It shall be easy to write
programs that process
XML documents.
■
The number of optional
features in XML is to
be kept to the absolute
minimum; ideally, zero.
■
XML documents should
be human-legible and
reasonably clear.
■
The XML design should
be prepared quickly.
■
The design of XML
shall be formal and
concise.
■
XML documents shall
be easy to create.
■
Terseness in XML
markup is of minimal
importance.
■
XML shall be
straightforwardly
Building the XML Address Book 145
Loading the XML Address Book 145
Creating and Deleting Categories 149
Creating, Editing, and Deleting Entries 151
Summary 156
Solutions Fast Track 157
Frequently Asked Questions 158
Chapter 5 Understanding .NET and
XML Security 159
Introduction 160
The Risks Associated with Using XML in
the .NET Framework 160
The Document
Interface Attributes
Attribute Description
doctype The Document
Type Declaration
(DTD) with this
document. If
DTD is not
present, this
returns null.
document The root
Element element in the
document.
155_XML_NET_TOC.qxd 3/7/02 3:12 PM Page xiv
Contents xv
Confidentiality Concerns 161
.NET Internal Security as a Viable Alternative 162
Permissions 163
Summary 222
Solutions Fast Track 223
Frequently Asked Questions 228
You can determine the
permission set of a
code group by
performing these
steps:
1. Run Microsoft
Management Console
(MMC) by choosing
Start | Run and typing
mmc.
2. Open the .NET
Management snap-in,
via Console |
Add/Remove Snap-in.
3. Expand the Console
Root | .NET
Configuration | My
Computer.
4. Expand Runtime
Security Policy |
Enterprise |Code
Groups.
5. Select the code group
All_Code.
6. Right-click All_Code
and select Properties.
7. Select the Permission
Querying XML Data Using XPathDocument
and XPathNavigator 256
Using XPathDocument and
XPathNavigator Objects 259
Using XPathDocument and XPathNavigator
Objects for Document Navigation 261
Transforming an XML Document Using XSLT 264
Transforming an XML Document
to an HTML Document 266
Transforming an XML Document into
Another XML Document 268
Working with XML and Databases Online 274
Answers to Your
Frequently asked
Questions
Q:
Why so much emphasis
on the Web? Can’t I
use XML on the
desktop as well?
A:
Yes, you can use XML
on the desktop.
However, one of the
main goals of .NET is
to properly connect
the desktop with the
Internet and not suffer
any setback due to
server type, program-
Advanced Options for the Guestbook Interface 301
Manipulating Colors and Images 301
Modifying the Page Output 305
Summary 308
Solutions Fast Track 308
Frequently Asked Questions 310
Chapter 8 Creating a Message Board
with ADO and XML 311
Introduction 312
Setting Up the Database 312
MS Access Database 313
SQL Server Database 317
Designing Your Application 321
Designing Your Objects 323
Creating Your Data Access Object 323
Designing the User Class 325
Designing the Board Class 335
Migrating…
Online Forms
As you have noticed and
learned throughout this
book, ASP.NET enables
programmers to use Web
forms, which can be
described as the VB6.0
desktop form. In this par-
ticular example, your
“AddClick” sub would be
placed within the
OnClick() event for what-
Chapter 9 Building a Remote
Database Viewer 407
Introduction 408
Understanding ADO.NET 408
The ADO.NET Architecture 410
Using .NET Data Provider 410
Connection 411
Command 411
Data Reader 411
Data Adapter 412
Using DataSets and DataTables 413
A Quick Comparison of ADO and
ADO.NET 414
Accessing Data from a Database Using ADO.NET 414
Database Design 415
Navigating between Records 415
Add Record Form 419
Delete/Update Form 422
The Board Class
+Update()
+CreateThread()
+Delete()
+DeleteThread()
+DeletePost()
+CreateBoard() : Board
+BoardID : Long
+Name : String
+Description : String
+ChildThreads
+ChildThread
Vocabularies 457
Requirements 457
Analysis 458
Data Store 458
Catalog Updating 459
Business-to-Business E-Communications 459
The XML Files 460
Data Typing Entries 461
Catalog 462
Understanding
ADO.NET
The ADO.NET also sports
these features:
■
Interoperability
■
DataSet
■
Performance
■
Scalability
■
Maintainability
155_XML_NET_TOC.qxd 3/7/02 3:12 PM Page xix
xx Contents
Coding the Project 462
Database Design 463
OLTP versus OLAP 463
XML Packages Design 465
Supplier Interface and B2B Design 469
Frequently Asked Questions 535
Index 537
Developing &
Deploying…
DataReader versus DataSet
DataReader for the most
part works pretty much
like the old recordset with
which ASP programmers
are familiar. DataSet will
create a virtual database
(preserved in XML) that
we can work with even
while disconnected to the
database. It requires a
complete new subset of
objects and methods to
work with it.
155_XML_NET_TOC.qxd 3/7/02 3:12 PM Page xx
Welcome to the XML.NET Developer’s Guide! We have taken great care to create a
quality reference book for XML programmers who want to enhance their coding
skills to include applications for the .NET platform.This book assumes that you do
have previous exposure to XML and are familiar with VB.NET, C#, and ASP.NET.
In other words, this book is not for a novice or beginner.
Since its inception in February of 1998, XML has been moving forward through
the continued efforts of the World Wide Web Consortium (W3C). At first many
developers scoffed at XML, thinking it was just a new way to script. However, those
developers who regularly worked with database management and development soon
realized the potential of what XML could be—a way to provide data between parties
without needing to rely on proprietary solutions.
If you have read any of Syngress’ .NET books in the past you’ll be familiar with
the layout.We introduce either introductory material (or, in this case, refresher mate-
rial) in the first couple of chapters, move on to the meat of the book with in-depth
views on specific points in the programming language, and finish off with a set of
case studies that enhance the skills and ideas you’ve learned throughout the book. All
in all, the XML.NET Developer’s Guide has a total of ten chapters.
Chapter 1 (Introducing the .NET Framework) will bring you up to speed with a
refresher in how .NET works internally, with Chapter 2 (Visual Studio .NET IDS)
providing an introductory look into VS.NET, Microsoft’s IDE for .NET program-
ming.This new IDE can work more with XML than its predecessor, so even if you
are familiar with the VS.NET IDE it may be a good idea to browse through this
chapter.
Chapter 3 (Reviewing the Fundamentals of XML) kicks off by giving you a quick
refresher for XML basics.This is followed up by Chapter 4 (Using XML in the .NET
Framework), in which we start to look at how you can work with XML through
.NET. Both Chapter 3 and 4 cover basic XML items such as proper XML syntax and
validation through Schemas.You will also learn about many of the major namespaces
and how they work, and begin to familiarize yourself with the appropriate classes
you need to complete your projects.You will be surprised at the flexibility that XML
offers and how even some other classes that do not directly revolve around XML can
work with XML as well.
Chapter 5 (Understanding .NET and XML Security) introduces a major issue in the
XML user community—security.While XML is unable to provide proper security by
www.syngress.com
155_XML_NET_fore.qxd 3/6/02 5:16 PM Page xxii
www.syngress.com
itself, a thorough understanding of what XML can do combined with an under-
standing of .NET security is vital.
Chapter 6 (Web Development Using XML and ASP.NET) will introduce you to the
online aspect of XML using ASP .NET and teach you how XML is a vital part of