Visualstudio-Xml-Tools-Vs-2022 Manual Explicativo
Visualstudio-Xml-Tools-Vs-2022 Manual Explicativo
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
Extensible Markup Language (XML) is a markup language that provides a format for
describing data. XML separates the data and its presentation by using associated style
sheets such as Extensible Stylesheet Language (XSL) and cascading style sheets (CSS).
Visual Studio includes tools and features that make it easier to work with XML, XSLT, and
XML schemas.
XML editor
The XML editor is used to edit XML documents. It provides full XML syntax checking,
schema validation while you type, color-coding, and IntelliSense. If a schema or
document type definition is provided, it is used by IntelliSense to list allowable elements
and attributes.
The ability to execute XSLT transformations and to view the results as text, XML, or
HTML
The ability to generate XML Schema definition language (XSD) schemas from the
XML instance document
XSLT debugging
Visual Studio supports debugging XSLT style sheets. Using the debugger, you can set
break points in an XSLT style sheet, step into an XSLT style sheet from code, and so on.
7 Note
The XSLT debugger is only available in the Enterprise edition of Visual Studio.
See also
System.Xml
XSLT transformations
Process XML data using the XPath data model
XML Document Object Model (DOM)
XML Schema Object Model (SOM)
XML editor
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The XML editor in Visual Studio is based on the text editor and includes additional
support for the XML languages. When you open an XML file in Visual Studio, it opens in
the XML editor.
Integration with the XML Schema Explorer. This provides a hierarchal view of XML
schemas.
The XML editor is invoked for well-known file extensions, such as .xml, .xsd, .xsl, and
.config. It is also invoked on any unknown file extension if the file appears to contain
XML.
XSLT IntelliSense
XSLT IntelliSense allows you to auto-complete attribute set names, template modes and
names, and parameter names for a specified mode or a specified named template.
XSLT profiler
The XSLT profiler creates detailed XSLT performance reports that help you measure,
evaluate, and target performance-related problems in XSLT code. The XSLT Profiler also
includes useful hints for XSL and XSLT style sheet optimizations.
XSLT hierarchy
The XSLT hierarchy tool allows you to add breakpoints in included style sheets and/or
built-in template rules.
See also
XML editor options - formatting
XML editor options - miscellaneous
Features of the code editor
XML standards reference
XML tools in Visual Studio
XML document validation
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The XML editor checks XML 1.0 syntax and also performs data validation as you type.
The editor can validate using a document type definition (DTD) or a schema. Red wavy
underlines highlight any XML 1.0 well-formed errors. Blue wavy underlines show
semantic errors based on DTD or schema validation. Each error has an associated entry
in the error list. You can also view the error message by pausing the mouse over the
wavy underline.
From the file name specified in the Schemas field of the document Properties
window.
Schemas can also be found in the following additional locations when the schema has a
non-empty target namespace:
XSLT files
When editing an XSLT file, the xslt.xsd file located in the schema cache is used for
validation. Validation errors are shown as blue wavy underlines. Errors from the XSLT
compiler are shown as red wavy underlines.
If you encounter this limitation in processing an XML document and wish to extend the
validator to a larger schema, this can be changed with the
MaxNumberOfDtdEntityReferences Visual Studio registry key. See editing the registry for a
Visual Studio instance for more information on making this change. Please note that this
applies to all XML documents opened by the user on that machine.
See also
XML editor
XML editor IntelliSense features
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The XML editor provides full IntelliSense features comparable to other language editors
provided in Visual Studio. This section explains how you can use the IntelliSense with
XML Schema definition language (XSD) and XSLT documents.
For information about how to associate schemas with your XML documents, see XML
document validation.
When you type SPACE from inside a start tag, you also get a drop-down list showing all
attributes that can be added to the current element.
When you type "=" for an attribute value, or the opening quote for the value, you also
get list of possible values for that attribute. Values are only provided if the schema
provides enumerated values via xsd:enumeration facets, or if the attribute is a Boolean
type. An IntelliSense list of known language codes is also provided for xml:lang or any
simpleType that derives from xsd:language . An IntelliSense list of known
targetNamespace values is provided for namespace declarations.
An IntelliSense list of possible values is also provided when you type ">" to close a start
tag if the element is a simpleType . The behavior for elements is similar to the behavior
for attributes described in the previous paragraph.
Template modes.
Template names.
Auto-completion
The XML editor also makes editing XML easier by filling in required XML syntax for you.
For example, if you type the following start tag:
<book>
The XML editor fills in the end tag and positions the cursor after the start tag. The
following is an example of this (the "|" notes the cursor position):
<book> | </book>
Because attribute values must always have quotes, the XML editor fills in the quotes for
you. For example, if you type the following:
<book title=
The XML editor adds the quotes and positions the cursor between the quotes:
Similarly, the XML editor also inserts the following XML syntax automatically for you:
The XML editor also has the ability to insert a namespace declaration if you select a
namespace qualified element or attribute from an IntelliSense list and the namespace
for that element or attribute is not yet in scope.
For example, if you select the e:Book element from the IntelliSense list where the prefix
is bound to the http://books namespace that has not been declared in the document,
the XML editor inserts the required namespace declaration for you. The following is the
resulting XML text:
<e:Book xmlns:e="http://books"
Brace matching
The XML editor provides brace highlighting to give you immediate feedback on
elements you have just closed. You can also use the keyboard shortcut (Ctrl+]) to jump
from one brace to the matching brace.
The Auto Insert section of the Miscellaneous page controls the following behavior:
Name Description
Name Description
Attribute Inserts attribute value quotes when you enter a new attribute name.
quotes
3. Make any changes to the Auto insert section and click OK.
See also
XML editor
Using IntelliSense
Walkthrough: Using XSLT IntelliSense
XML snippets
Article • 12/12/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The XML editor offers a feature, called XML snippets, that allows you to build XML files
more quickly. You can reuse XML snippets by inserting them into your files. You can also
generate XML data based on an XML schema definition language (XSD) schema.
XML
<xs:element name="name">
<xs:complexType>
<xs:sequence>
<xs:element name="name">
<xs:simpleType>
<xs:restriction base="xs:string"></xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
You can insert snippets in two ways. The Insert Snippet command inserts the XML
snippet at the cursor position. The Surround With command wraps the XML snippet
around the selected text. Both commands are available either from the IntelliSense
submenu under the Edit menu, or from the right-click menu within the editor.
Related content
Code snippets in Visual Studio
XML editor
How to: Use XML snippets
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
You can invoke XML snippets by using the following two commands on the XML editor
shortcut menu. The Insert Snippet command inserts the XML snippet at the cursor
position. The Surround With command wraps the XML snippet around the selected text.
Each XML snippet has designated snippet types. The snippet types determine whether
the snippet is available with the Insert Snippet command, the Surround With
command, or both.
After the XML snippet has been added to the editor, any editable fields in the snippet
are highlighted in yellow, and the cursor is positioned on the first editable field.
Insert Snippet
The following procedures describe how to access the Insert Snippet command.
7 Note
The Insert Snippet command is also available through the keyboard shortcut
(Ctrl+K, then Ctrl+X).
3. Select a snippet from the list using the mouse, or by typing the name of the
snippet and pressing Tab or Enter.
2. From the Edit menu, point to IntelliSense, and then select Insert Snippet.
A list of available XML snippets is displayed.
3. Select a snippet from the list using the mouse or by typing the name of the
snippet and pressing Tab or Enter.
2. Begin typing the XML snippet that you want to add to your file. If automatic
completion is turned on, the IntelliSense complete word list is displayed. If it does
not appear, press Ctrl+Space to activate it.
7 Note
There may be cases when the XML snippet does not get invoked. For example, if
you try to insert an xs:complexType element inside an xs:element node, the editor
does not generate an XML snippet. When an xs:complexType element is used inside
an xs:element node, there are no required attributes or subelements, so the editor
does not have any data to insert.
4. Type the shortcut name of the snippet, and press Tab to invoke the XML snippet.
Surround With
The following procedures describe how to access the Surround With command.
7 Note
The Surround With command is also available through the keyboard shortcut
(Ctrl+K, then Ctrl+S).
3. Select a snippet from the list using the mouse, or by typing the name of the
snippet and pressing Tab or Enter.
2. From the Edit menu, point to IntelliSense, and then select Surround With.
3. Select a snippet from the list using the mouse, or by typing the name of the
snippet and pressing Tab or Enter.
When a field is selected, you can type a new value for the field. Pressing Tab cycles
through the editable fields of the snippet; pressing Shift+Tab cycles through them in
reverse order. Clicking a field places the cursor in the field, and double-clicking a field
selects it. When a field is highlighted, a ToolTip might be displayed, offering a
description of the field.
Only the first instance of a given field is editable. When that field is highlighted, the
other instances of that field are outlined. When you change the value of an editable
field, that field is changed everywhere it is used in the snippet.
Pressing Enter or Esc cancels field editing and returns the editor to normal.
The default colors for editable code snippet fields can be changed by modifying the
Code Snippet Field setting in the Fonts and Colors pane of the Options dialog box. For
more information, see How to: Change fonts and colors in the editor.
See also
XML snippets
How to: Generate an XML snippet from an XML schema
How to: Create XML snippets
How to: Generate an XML snippet from
an XML schema
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The XML editor has the ability to generate XML snippets from an XML Schema definition
language (XSD) schema. For example, as you are authoring an XML file, while positioned
next to the element name, you can press Tab to populate the element with XML data
generated from the schema information for that element.
This feature is only available on elements. The following rules also apply:
The element must have an associated schema type; that is, the element must be
valid according to some associated schema. The schema type cannot be abstract
and the type must contain the required attributes and/or required child elements.
The current element in the editor must be empty with no attributes. For example,
the following are all valid
<Account
<Account>
<Account></Account>
The cursor must be located immediately to the right of the element name.
The generated snippet contains all required attributes and elements. If minOccurs is
greater than one, the required minimum number of instances of that element is
included in the snippet, up to a maximum of 100 instances. Any fixed values found in
the schema result in fixed values in the snippet. xsd:any and xsd:anyAttribute elements
are ignored and result in no additional snippet constructs.
Default values are generated and noted as editable values. If the schema specifies a
default value, this default value is used. However, if the schema default value is an
empty string, the editor generates the default values in the following manner:
If the schema type contains any enumeration facets, either directly or indirectly by
means of any of members of a union type, the first enumerated value found in the
Schema Object Model is used as the default.
If the schema type is an atomic type, the editor gets the atomic type and inserts
the atomic type name. For a derived simple type it uses the base simple type. For a
list type the atomic type is the itemType . For a union, the atomic type is the atomic
type of the first memberType .
Example
The steps in this section show you how to use the schema-generated XML snippet
feature of the XML editor.
7 Note
Before starting these procedures, save the schema file to your local computer.
A new file is opened in the editor. The file contains a default XML declaration, <?
xml version="1.0" encoding="utf-8"> .
3. In the document properties window, click the browse button (...) on the Schemas
field.
4. Click Add.
6. Click OK.
The editor adds the start tag <Contact and positions the cursor after the element
name.
4. Press Tab to generate XML data for the Contact element based on its schema
information.
Input
The following schema file is used by the walkthrough.
XML
Output
Following is the XML data that is generated based on the schema information
associated with the Contact element. Items marked as bold designate editable fields in
the XML snippet.
XML
<Contact>
<Name>name</Name>
<Title>title</Title>
<Phone>
<Number>number</Number>
<Type>Voice</Type>
</Phone>
</Contact>
See also
XML snippets
How to: Use XML snippets
Create XML snippets
Article • 12/12/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The XML editor can be used to create new XML snippets. The editor includes an XML
snippet, named "Snippet", that is a boilerplate snippet for creating new XML snippets.
7. Enter the name for the new snippet and select Snippet Files from the Save as type
drop-down window.
8. Use the Save in drop-down list to change the file location to the My
Documents\Visual Studio 2005\Code Snippets\XML\My XML Snippets folder and
then press Save.
Snippet description
This section describes some of the key elements in the boilerplate snippet. For more
information about schema elements used by the XML snippets, see Code snippets
schema reference.
SnippetType element
The editor supports two snippet types:
XML
<SnippetTypes>
<SnippetType>SurroundsWith</SnippetType>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
The Expansion type determines whether the snippet appears when you invoke the
Insert Snippet command. The SurroundsWith type determines whether the snippet
appears when you invoke the Surrounds With command.
Code element
The Code element defines the XML text that will be inserted when the snippet is
invoked.
7 Note
The following is the Code element that is created by the boilerplate snippet.
XML
<Code Language="XML">
<![CDATA[<test>
<name>$name$</name>
$selected$ $end$</test>]]>
</Code>
$selected$ is a predefined variable. It represents the text that was selected in the
XML editor before invoking the snippet. The placement of this variable determines
where the selected text appears in the code snippet that surrounds that selection.
$end$ is a predefined variable. When the user presses Enter to finish editing the
code snippet fields, this variable determines where the caret (^) is moved to.
XML
<test>
<name>name</name>
</test>
Literal element
The Literal element is used to identify replacement text that can be customized after it
is inserted into the file. For example, literal strings, numeric values, and some variable
names can be declared as literals. You can define any number of literals in your XML
snippet and you can refer to them multiple times from within the snippet. The following
is an example of a Literal element that defines a $name$ variable whose default value
is "name."
XML
<Literal>
<ID>name</ID>
<Default>name</Default>
</Literal
Literals can also refer to functions. The XML editor includes a function named
LookupPrefix. The LookupPrefix function looks up the given namespace URI from the
location in the XML document that this snippet is invoked from and returns the
namespace prefix that is defined for that namespace, if any, and it includes the colon (:)
in that name. The following is an example of a Literal element that uses the
LookupPrefix function.
XML
<Literal Editable="false">
<ID>prefix</ID>
<Function>LookupPrefix("namespaceURI")</Function>
</Literal>
The $prefix$ variable can then be used elsewhere in your XML snippet.
Related content
XML snippets
How to: Use XML snippets
How to: Generate an XML snippet from an XML schema
Edit XSLT Style Sheets
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The XML editor can also be used to edit XSLT style sheets. You can take advantage of
the default Editor features such as IntelliSense, outlining, XML snippets, and so on. In
addition, there are also new features that make it easier to develop in XSLT.
XSLT Features
The following table describes features specific to working with XSLT style sheets.
Syntax coloring
XSLT keywords, such as template and match , are displayed in the XSLT keyword color
specified by the Fonts and Colors settings.
Wavy underlines
The XML editor uses the installed xslt.xsd file to validate XSLT style sheets. Validation
errors are shown as blue wavy underlines. The XML editor also compiles the style sheet
in the background and reports compiler errors or warnings with appropriate wavy
underlines.
Code in script blocks is supported by the XSLT debugger so you can set breakpoints and
step through the script block code.
You can execute an XSL transformation and view the output from the XML editor. For
more information, see How to: Execute an XSLT transformation from the XML editor.
Debug XSLT
You can launch the XSLT debugger from an XSLT file in the XML editor. The debugger
supports setting breakpoints in the XSLT file, viewing XSLT execution state, and so on.
Hovering over an XSLT variable brings up a ToolTip with the value of the variable. The
debugger can be used to debug a style sheet, or to debug a compiled XSL
transformation invoked from another application. For more information, see Debugging
XSLT.
See also
XML editor
Schema cache
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The XML editor can also find schemas located in the solution, schemas specified in the
Schemas field of the document Properties window, and schemas identified by the
xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes.
The following table describes the schemas that are installed with the XML editor.
Filename Description
catalog.xsd Schema for XML editor schema catalog files. For information about schema
catalogs, see below.
msdata.xsd Schema for the XSD annotations added by the DataSet class, "urn:schemas-
microsoft-com:xml-msdata".
SnippetFormat.xsd Schema for the code snippet XML files. For examples, see
%VSInstallDir%\VC#\Expansions.
7 Note
Because the schema cache directory is global to your computer, you should only
add schemas here that are standard and useful to all the Visual Studio projects that
may be created on your computer.
The XML editor also supports any number of schema catalog files in the schema cache
directory. Schema catalogs can point to other locations for schemas that you always
want the editor to know about. The catalog.xsd file defines the format for the catalog file
and is included in the schema cache directory. The catalog.xml file is the default catalog
and it contains links to other schemas in the %VSInstallDir%. The following is a sampling
of the catalog.xml file:
XML
<SchemaCatalog xmlns="http://schemas.microsoft.com/xsd/catalog">
<Schema href="%VSInstallDir%/help/schemas/Favorites.xsd"
targetNamespace="urn:Favorites-Schema"/>
<Schema href="%VSInstallDir%/help/schemas/Links.xsd"
targetNamespace="urn:Links-Schema"/>
<Schema href="%VSInstallDir%/help/schemas/MyHelp.xsd"
targetNamespace="urn:VSHelp-Schema"/>
</SchemaCatalog>
The href attribute can be any file path or http URL pointing to the schema. The file path
can be relative to the catalog document. The following variables, delimited by %%, are
recognized by the editor and expanded in the path:
VSInstallDir
System
ProgramFiles
Programs
CommonProgramFiles
ApplicationData
CommonApplicationData
LCID
The catalog document can include a Catalog element, which points to other catalogs.
You can use the Catalog element to point to a central catalog shared by your team or
company, or an online catalog shared with your business partners. The href attribute is
the file path or http URL for the other catalogs. The following is an example of the
Catalog element:
XML
<Catalog href="file://c:/xcbl/xcblCatalog.xml"/>
The catalog can also control how schemas are associated with XML documents using
the special Association element. This element associates schemas that have no target
namespace with a particular file extension, which can be useful because the XML editor
does not do any auto-association of schemas that do not have a targetNamespace
attribute. In the following example the Association element associates the
dotNetConfig schema with all files that have the "config" file extension:
XML
<Association extension="config"
schema="%VSInstallDir%/xml/schemas/dotNetConfig.xsd"/>
Localized schemas
In many cases the catalog.xml file does not contain entries for localized schemas. You
can add additional entries to the catalog.xml file that point to the localized schema
directory.
In the following example a new Schema element has been created that uses the %LCID%
variable to point to the localized schema.
XML
<Schema href="%InstallRoot%/Common7/IDE/Policy/Schemas/%LCID%/TDLSchema.xsd"
targetNamespace="http://www.microsoft.com/schema/EnterpriseTemplates/TDLSche
ma"/>
7 Note
4. Select the folder for the schema cache and click OK.
See also
XML editor
Walkthrough: Use XML editor features
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The steps in this walkthrough show you how to create a new XML document. The
walkthrough also uses some of the features of the XML editor that make it valuable for
XML authoring.
7 Note
Before starting the walkthrough, save the hireDate.xsd file (included below in this
topic) to your local computer.
A new file is opened in the editor. The file contains a default XML declaration, <?
xml version="1.0" encoding="utf-8"> .
3. In the document properties window, click the browse button (...) on the Schemas
field.
4. Click Add.
6. Click OK.
The XML Schema is now associated with the XML document. The XML Schema is
used to validate the document. It is also used by IntelliSense to populate the
member list of valid elements.
To add data
1. Type < in the editor pane.
The editor inserts a comment end tag and places the cursor between the start and
end comment tags.
4. On a new line, type < , and select employee from the member list.
The editor adds the start of an XML element, <employee . At this point you can add
attributes to the element or you can close the start tag by typing > .
6. The editor adds the end tag. The end tag is added with a wavy underline indicating
a validation error. The ToolTip displays the message: The element 'employee' has
incomplete content. Expected 'ID'.
7. Type < and select ID from the member list. Then type > .
The editor adds the XML element, <ID></ID> , and positions the cursor after the ID
start tag.
8. Type abc.
The abc text has a wavy underline. The ToolTip displays the message: The 'ID'
element has an invalid value according to its data type.
The editor opens the hireDate.xsd file in a new document window and positions
the cursor on the ID schema element definition.
10. Return to the XML file, and replace the abc text with 123.
The wavy underline and ToolTip are cleared under the ID element value. The
ToolTip for the employee end tag now displays the message: The element
'employee' has incomplete content. Expected 'hire-date'.
11. Place the cursor after the ID end tag, type in < , select hire-date from the member
list, and then type in > .
The editor adds the XML element, <hire-date></hire-date> , and positions the
cursor after the hire-date start tag.
The Save File As dialog box is displayed. The default filename is 'XMLFile1'.
2. Enter the file name and location for the XML document and click Save.
hireDate.xsd file
The following schema file is used in this walkthrough:
XML
<?xml version="1.0"?>
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified" targetNamespace="urn:empl-hire"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element name="ID" type="xs:unsignedShort" />
<xs:element name="hire-date" type="xs:date" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
See also
XML editor
How to: Select the XML schemas to use
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
Use the Schemas document property to select one or more XML schema definition
language (XSD) schemas. You can select schemas from the schema cache or elsewhere.
The schemas you specify are saved in a (hidden) solution user options file (.suo), along
with all other XML document properties. As a result, you don't have to reenter these
values the next time you open the solution.
7 Note
The editor can validate using an inline schema or a schema referenced by the
xsd:schemaLocation attribute. For more information, see XML document validation.
2. In the document properties window, click in the Schemas field. When the browse
button (...) appears, click it.
The XML Schemas dialog box opens. The dialog box lists all schemas with an .xsd
extension in the schema cache (including schemas referenced in the catalog.xml
file), and also any schema that is in the current solution, open in Visual Studio,
referenced in an xsd:schemaLocation attribute, or referenced in the Schemas
property.
3. Select the schemas to use for validation by doing one of the following:
Select a schema listed in the XML Schemas dialog, click the Use column, and
then select Use this schema.
-or-
Select multiple schemas listed in the XML Schemas dialog, and then right-
click and select Use this schema.
4. Choose OK.
The list of selected schemas is copied back to the Schemas document property.
2. Click Add.
The schemas are added to the schema cache and the Use column value is set to
Use this schema.
The schema is removed from the in-memory schema cache, but it is not removed
from the file system.
7 Note
See also
Schema cache
XML schemas dialog box
XML editor
How to: Create an XML schema from an
XML document
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The XML editor lets you create an XML Schema definition language (XSD) schema from
an XML document. The XML file determines how the schema is generated in the
following manner:
If the XML document contains an associated DTD, the external DTD and internal
subset are converted to a corresponding XML Schema.
If the XML document contains an inline XML-Data Reduced (XDR) schema, the XDR
schema is converted to a corresponding XML Schema.
The schemas that are created are then used to provide IntelliSense for the XML file.
For more information about the schema inference engine, see Infer an XML schema.
An XML Schema document is created and opened for each namespace found in
the XML file. Each schema is opened as a temporary miscellaneous file. The
schemas can be saved to disk, added to your project, or discarded.
See also
XML editor
How to: Execute an XSLT transformation
from the XML editor
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The XML editor lets you associate an XSLT style sheet with an XML document, perform
the transformation, and view the output. The resulting output from the XSLT
transformation is displayed in a new document window.
The Output property specifies the filename for the output. If the Output property is
blank, a filename is generated in your temporary directory. The file extension is based
on the xsl:output element in your style sheet and can be .xml, .txt or .htm.
If the Output property specifies a filename with an .htm or .html extension, the XSLT
output is previewed using a web browser. All other file extensions are opened using the
default editor chosen by Visual Studio. For example, if the file extension is .xml, Visual
Studio uses the XML editor.
-or-
Add the XSLT style sheet using the Properties window. With the XML file
open in the editor, right-click anywhere in the editor and choose Properties.
In the Properties window, click in the Stylesheet field and choose the browse
button (...). Select the XSLT style sheet, and then choose Open.
3. On the menu bar, choose XML > Start XSLT Without Debugging. Or, press
Ctrl+Alt+F5.
The output from the XSLT transformation is displayed in a new document window.
7 Note
If there is no style sheet associated with the XML document, a dialog box
prompts you to provide the style sheet to use.
2. Specify an XML document in the Input field of the document Properties window.
7 Note
3. On the menu bar, choose XML > Start XSLT Without Debugging. Or, press
Ctrl+Alt+F5.
The output from the XSLT transformation is displayed in a new document window.
See also
XML editor
How to: Edit XML files
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The XML editor is the new editor for XML files. It can be used on a stand-alone XML file,
or on a file associated with a Visual Studio project. The XML editor is associated with the
following file extensions: .config, .dtd, .xml, .xsd, .xdr, .xsl, .xslt, and .vssettings. The XML
editor is also associated with any other file type that has no specific editor registered,
and that contains XML or DTD content.
7 Note
The XML file is added to the project and opens in the XML editor. The file contains
the default XML declaration, <?xml version="1.0" encoding="utf-8" ?> .
3. Select Open.
2. Enter Empty Project in the template search box, select the Empty Project (.NET
Framework) template, and then select Next.
3. Select Create.
The XML editor finds the schemas you add to this project and uses them for
validation and IntelliSense in any XML, schema, or XSLT files that you edit while this
project is open.
See also
XML editor
XML document properties, properties window
How to: Create an XML schema from an XML document
Walkthrough: Using XSLT IntelliSense
Article • 12/12/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
XML
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<!-- These 2 elements effectively assign
$messages = resources/en.xml/<messages>,
then $messages is used in the "localized-message" template. -->
<xsl:param name="lang">en</xsl:param>
<xsl:variable name="messages"
select="document(concat('resources/', $lang, '.xml'))/messages"/>
<xsl:template name="localized-message">
<xsl:param name="msgcode"/>
<!-- Show message string. -->
<xsl:message terminate="yes">
<xsl:value-of select="$messages/message[@name=$msgcode]"/>
</xsl:message>
</xsl:template>
</xsl:stylesheet>
XML
<xsl:call-template name="localized-message">
</xsl:call-template>
The list of template names appears in the name="" attribute of the xsl:call-
template element as you type.
XML
<xsl:with-param name="msgcode">msg23</xsl:with-param>
The list of parameter names appears in the name="" attribute of the xsl:with-
param element.
XML
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<HTML>
<BODY>
<TABLE>
<xsl:apply-templates select="customers/customer">
<xsl:sort select="state"/>
<xsl:sort select="name"/>
</xsl:apply-templates>
</TABLE>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="customer">
<TR>
<xsl:apply-templates select="name" />
<xsl:apply-templates select="address" />
<xsl:apply-templates select="phone" />
</TR>
</xsl:template>
<xsl:template match="name">
<TD STYLE="font-size:14pt font-family:serif">
<xsl:apply-templates />
</TD>
</xsl:template>
<xsl:template match="address">
<TD>
<xsl:apply-templates />
</TD>
</xsl:template>
<xsl:template match="phone">
<TD>
<xsl:apply-templates />
</TD>
</xsl:template>
<xsl:template match="phone" mode="accountNumber">
<xsl:param name="Area_Code"/>
<TD STYLE="font-style:italic">
1-<xsl:value-of select="."/>-001
</TD>
</xsl:template>
</xsl:stylesheet>
2. Insert your cursor after <xsl:apply-templates select="phone" /> and press Enter.
Then start typing the following xsl: apply-templates element:
XML
The list of template modes appears in the mode="" attribute of the xsl:apply-
templates element.
XML
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:alt="http://www.w3.org/1999/XSL/Transform-alternate"
version="1.0">
<xsl:param name="browser" select="'InternetExplorer'"/>
<xsl:template match="/">
<alt:stylesheet>
<xsl:choose>
<xsl:when test="$browser='InternetExplorer'">
<alt:import href="IERoutines.xsl"/>
<alt:template match="/">
<div>
<alt:call-template name="showTable"/>
</div>
</alt:template>
</xsl:when>
<xsl:otherwise>
<alt:import href="OtherBrowserRoutines.xsl"/>
<alt:template match="/">
<div>
<alt:call-template name="showTable"/>
</div>
</alt:template>
</xsl:otherwise>
</xsl:choose>
</alt:stylesheet>
</xsl:template>
</xsl:stylesheet>
XML
Notice how the list of prefixes appeared in the stylesheet-prefix and result-
prefix attributes of the xsl:namespace-alias element.
Related content
XML editor IntelliSense features
Walkthrough: Use XSLT hierarchy
Article • 12/12/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The XSLT Hierarchy tool simplifies many XML development tasks. An XSLT style sheet
often uses includes and imports instructions. Compilation starts from the principal
style sheet, but when you see an error as a result of compiling an XSLT style sheet, the
error may come from a different source than the principal style sheet. Fixing the error or
editing the style sheet may require access to included or imported style sheets. Stepping
through the style sheet in the debugger may open included and imported style sheets,
and you may want to add a breakpoint at some point in one or more of the included
style sheets.
Another scenario where the XSLT Hierarchy tool can be useful is putting breakpoints on
the built-in template rules. Template rules are special templates generated for each
mode of the style sheet and called by xsl:apply-templates when no other template
matches the node. To implement debugging in built-in templates rules, XSLT debugger
generates the file with the rules in the temporary folder and compiles them together
with the principal style sheet. Without stepping into the code from some xsl:apply-
template , it can be difficult to find style sheets that have been included in the principal
style sheet or to find and open the style sheet with the built-in template rules.
XML
XML
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xml:space="preserve">
<xsl:template match="TITLE">
Title - <xsl:value-of select="."/><BR/>
</xsl:template>
<xsl:template match="AUTHOR">
Author - <xsl:value-of select="."/><BR/>
</xsl:template>
<xsl:template match="PUBLISHER">
Publisher - <xsl:value-of select="."/><BR/><!-- removed second <BR/>
-->
</xsl:template>
</xsl:stylesheet>
XML
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="COLLECTION/BOOK">
<xsl:apply-templates select="TITLE"/>
<xsl:apply-templates select="AUTHOR"/>
<xsl:apply-templates select="PUBLISHER"/>
<BR/>
<!-- add this -->
</xsl:for-each>
</xsl:template>
<!-- The following template rule will not be called,
because the related template in the including stylesheet
is called. If we move this template so that
it follows the xsl:include instruction, this one
will be called instead.-->
<xsl:template match="TITLE">
<DIV STYLE="color:blue">
Title: <xsl:value-of select="."/>
</DIV>
</xsl:template>
5. Start debugging.
continued in the referenced style sheet. The hierarchy is visible and the designer
displays the right path.
Related content
XSLT profiler
XML document properties, Properties
window
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The Properties window provides basic information about the document that is active in
the XML editor. The properties that are available vary depending on the type of XML
document that is currently active.
7 Note
All XML document properties are saved in the solution. As a result, you do not have
to reenter these values the next time you open the solution.
Encoding
The character encoding for the file. Changing this property also changes the encoding
attribute on the XML declaration, and vice versa. The new encoding is used to encode
the file when you save the file.
Input
The input document associated with the XSLT style sheet. It is used by the Start XSLT
commands, for example, XML > Start XSLT Without Debugging. A document can be
selected using the browse (...) button.
This property is visible only when an XSLT file is open in the editor.
Output
If a file is not specified, a default file name is generated based on the method attribute
on the xsl:output element, which determines the file extension. The default file is
located in the current user's temporary directory.
Schemas
The schemas to use for validation. The button opens the XSD Schemas dialog box,
which can be used to select the schemas to use.
You can also enter the path to the schemas. If multiple schemas are specified, each
schema path must be enclosed in double quotes.
Stylesheet
The XSLT file that is used to transform the document when the Start XSLT Debugging
and Start XSLT Without Debugging commands are used. If this field is blank, the editor
uses the value provided in the xml-stylesheet processing instruction of the document
or it prompts you for a filename.
When editing an XSLT file, this property can be used to specify that a different style
sheet should be used when the Start XSLT Debugging or Start XSLT Without
Debugging command is selected. For example, you may want to do this when you're
editing a style sheet that's included in a parent style sheet.
See also
XML editor
XML Schemas dialog box
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The XML Schemas dialog box is used to select which XML schema definition language
(XSD) schema(s) to associate with an XML document. You can select a schema from the
schema cache, or specify a schema that is not located in the cache. Selected schema(s)
are considered part of a schema set. The schema set is used for IntelliSense and also
XML document validation.
You can access the XML Schemas dialog box by either clicking the Schemas button on
the document properties window, or by selecting Schemas from the XML menu.
UIElement List
Use
Automatic. This schema is not in use by the current document but is available for
automatic association. If the XML document declares a namespace that matches
the targetNamespace of this schema, the schema will be automatically associated
and is included in the schema set.
Use this schema. This schema is being used by the current document. Either the
user has explicitly requested that this schema be used by clicking on this column,
or the schema was automatically associated based on a matching targetNamespace .
Do not use selected schemas. This schema is not used by the current document,
even if the schema has a matching targetNamespace . This setting can be useful for
resolving conflicts when there is more than one version of the same schema in the
schema cache or solution.
Target Namespace
File Name
Add
Opens the Open XSD Schema dialog, which enables you to select additional schemas to
add to the schema set. When you add a schema to the schema set, the Use column
value is set to Use this schema.
Remove
Removes the currently selected schema from the schema set. This removes the schema
from the in-memory schema cache, but not from the file system.
See also
How to: Select the XML schemas to use
Schema cache
XML Schema Designer overview
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The XML Schema Designer (XSD Designer) is a graphical tool that allows you to visualize
a schema set at different levels of abstraction. The main components of the XSD
Designer are:
XML Schema Explorer, which enables you to browse and navigate the XML Schema
tree and perform searches.
The Start View, which is the launching point for the XSD Designer. From the Start
View, you can navigate to other views of the XSD Designer and see the details of
your schema set.
The Graph View, which enables you to see an overview of a schema set and the
relationships between the schema nodes.
The Content Model View, which provides a graphical representation of the details
of local and global schema nodes, including simple and complex types, elements,
groups, attributes, and attribute groups.
7 Note
XSD Designer components support XML Schema Definition Language (XSD) 1.0.
XML Schema Explorer
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The XML Schema Explorer is integrated with Microsoft Visual Studio and the XML editor
to enable you to work with XML Schema definition language (XSD) schemas. When you
open an XML Schema file, the Schema Set node appears in the XML Schema Explorer.
All the included, imported, or redefined schemas for your target file, as well as any files
that are referenced through an include or import statement, also appear in the XML
Schema Explorer.
Add the search results to the Graph View or Content Model View
Sort the tree by document order, type, or name. For more information, see Sorting,
filtering, and grouping.
Open the XML editor and jump to code locations in the XSD file. For more
information, see Integration with XML editor.
The XML Schema Explorer provides a hierarchal view of the schema set through a tree
view. The XML Schema Explorer also provides search, filtering, navigation, and sorting.
To access the XML Schema Explorer, do one of the following:
If you are on the Start View, click the XML Schema Explorer link.
If you are on the Graph View or the Content Model View and have nodes in your
workspace, use the context (right-click) menu to select the XML Schema Explorer.
You can also select the XML Schema Explorer from the View menu.
You can access the XML Schema Explorer from a .vb file that has a Visual Basic
XML literal associated with an .xsd file. To see the schema set in the XML Schema
Explorer, right-click an XML node in an XML literal or an XML namespace import
and select the Show in Schema Explorer command. For more information, see
Integration of XML literals with XML Schema Explorer.
Tree View
The XML Schema Explorer displays pre-compiled schema set information in a tree
structure. The tree structure is organized as follows:
The fourth level contains the global nodes. This can include elements, groups,
complex types, simple types, attributes, attribute groups, and include , import , and
redefine statements.
Activating a file node opens the selected file (if it is not already open) and
highlights the <schema> node.
Dropping files on the view will add all the global nodes in the file to the XSD Designer
workspace. Dropping namespaces on the view will add all the global nodes in the
namespace to the workspace. The workspace is shared between all the views.
See also
How to: Add nodes to the workspace from the XML Schema Explorer
Search the schema set
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The XML Schema Explorer enables you to search the schema set in the following ways:
Keyword search.
Schema-specific search.
Keyword search
You perform keyword searches by entering a substring in the Search SchemaSet text
box of the XML Schema Explorer toolbar.
The XML Schema Explorer searches the schema set for the following attributes:
Any name or ref attributes that match the specified keyword. You can find
elements, attributes, types, and so on, by name.
You can add the search results to the workspace by clicking the Add highlighted nodes
to Workspace button on the summary results pane.
See also
XML Schema Explorer
Sorting, filtering, and grouping (XML
Schema Explorer)
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
This topic describes the options that are available through the Sorting, Filtering, and
Grouping Options menu on the XML Schema Explorer toolbar.
Filter options
The following filter options are available. By default, the Show Namespaces and Show
Schema Files options are selected.
Show Namespaces.
Sorting options
The following sorting options are available. The default is Sort By Type. Sort By options
do not apply to files and namespaces.
Sort By Type.
Sort By Name.
Document Order.
Sort By Type
When the Sort By Type option is selected, global nodes are sorted in the following
order. Nodes are then sorted alphabetically within each group.
1. import nodes.
2. include nodes.
3. redefine nodes.
4. attribute nodes.
5. attributeGroup nodes.
6. complexType nodes.
7. simpleType nodes.
8. element nodes.
9. group nodes.
Sort By Name
When the Sort By Name option is selected, global nodes are sorted in the following
order:
Document Order
The Document Order option is available when the Show Schema Files option is
selected. When Document Order is selected, global nodes are displayed in the order in
which they appear in the schema file.
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
A context menu is the menu that appears when you right-click on something. The
following context menu items are used to perform schema-specific searches and other
operations.
Option Description
Show Most Likely Finds and highlights all global elements that are not referenced from
Root Elements global elements other than themselves.
Show Global Types Finds and highlights all global types in the schema set.
Show Global Finds and highlights all global elements in the schema set.
Elements
Properties Window Opens the Properties window (if it is not already open). This window
displays information about the node.
Option Description
Show All Finds and highlights files that import the selected namespace.
Inbound
References
Show All For every file in the selected namespace, finds and highlights the following:
Outbound
References - All namespaces referenced in import statements without a schemaLocation
attribute.
- All files in namespaces other than the selected one that are specified in the
schemaLocation attribute in import and include statements.
Option Description
Show Global Finds and highlights all global types in the selected namespace.
Types
Show Global Finds and highlights all global elements in the selected namespace.
Elements
Properties Opens the Properties window (if it is not already open). This window displays
Window information about the node.
Option Description
Show All Finds and highlights all files that specify the selected file in the schemaLocation
Inbound attributes of their include and import statements.
References
Show Global Finds and highlights all global types in this file.
Types
Show Global Finds and highlights all global elements in this file.
Elements
View Code Opens the file that contains the selected node in the XML editor. The item that
is selected in the XML Schema Explorer will also be selected in the XML editor.
Properties Opens the Properties window (if it is not already open). This window displays
Window information about the node.
Option Description
Option Description
Show in Opens the Graph View. If the selected node is not in the workspace, adds it to
Graph View the workspace and selects the node.
Show in Opens the Content Model View. If the selected node is not in the workspace,
Content adds it to the workspace and selects the node.
Model View
View Code Opens the file that contains the selected node in the XML editor. The item that is
selected in the XML Schema Explorer will also be selected in the XML editor.
Properties Opens the Properties window (if it is not already open). This window displays
Window information about the node.
Option Description
Go To Type Navigates to the type definition of the selected element. This is applicable when
Definition the type that is used for the element is a global type.
Go To The For element references, navigates to the actual definition of the element.
Original
Element
Show All For global elements, finds and highlights all references (elements that have
References ref="selectedElement" ) to the selected element.
Show For heads of a substitution group, finds and highlights all elements that are
Members Of members of the substitution group of which the selected element is a member.
Substitution This shows direct and indirect participants.
Group
Show For global elements that are members of a substitution group, finds and
Substitution highlights all direct and indirect heads for the selected element, such as the
Group Heads following:
Generate Available only for global elements. Generates a sample XML file for the global
Sample XML element.
Node type: Global types
In addition to the global node options described above, the context menu for global
type nodes has the following options:
Option Description
Show Base If the selected type is derived from a global type, navigates to the base type of the
Type selected type.
Show All Finds and highlights all references to the selected type. This includes elements and
References attributes of the selected type and types derived from the selected type.
Show All Finds and highlights all types that are directly and indirectly derived from the
Derived selected type.
Types
Option Description
Go To Type When the type that is used for the attribute is a global type, navigates to the
Definition type definition of the selected attribute.
Go To The For attribute references, navigates to the actual definition of the attribute.
Original
Attribute
Show All For global attributes, finds and highlights all references (other attributes that
References have ref="selectedAttribute" ) to the selected attribute.
Option Description
Option Description
Show All Finds and highlights all members of the attribute group.
Members
Show All Finds and highlights all references (attribute groups that have
References ref="selectedAttributeGroup" ) to the selected attribute group.
Option Description
Show All Finds and highlights all members of the named group.
Members
Show All Finds and highlights all references (groups that have ref="selectedGroup" ) to
References the selected group.
See also
XML Schema Explorer
Searching the schema set
Integration of XML literals with XML
Schema Explorer
Article • 12/12/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
Visual Basic supports XML literals, which means that you can incorporate XML fragments
directly into your Visual Basic code. For more information, see XML literals overview.
How to
If an XSD file in your Visual Basic project includes an XML literal, you can view the XML
schema set in the XML Schema Explorer. To view the schema set associated with an
XML literal, right-click on an XML node in an XML literal or an XML namespace import
and select Show in Schema Explorer.
This opens the XML Schema Explorer side by side with your Visual Basic file.
Related content
How to: Use the XML schema designer with XML literals
XML Schema Designer workspace views
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The XML Schema Designer (XSD Designer) is a graphical tool that helps you explore
your XML schemas. In addition to the XML Schema Explorer, which allows you to browse
and navigate the XML Schema tree and perform searches, the XSD Designer provides
three views where you can explore your XSD schema in more detail.
The Start View is the launching point for the XSD Designer; from the Start View,
you can navigate to other views of the XSD Designer and see the details of your
schema set.
The Graph View enables you to see an overview of a schema set and the
relationships between the schema nodes.
The Content Model View provides a graphical representation of the details of local
and global schema nodes, including simple and complex types, elements, groups,
attributes, and attribute groups.
To start exploring the nodes you're interested in, you must add them to the workspace.
The workspace is shared between all the views.
In the "Schema Set Details" section of the Start View, click the add link next to the
global node type.
Drag and drop global nodes, file nodes, and namespace nodes from the XML
Schema Explorer onto any of the three views. For more information, see the
"Dragging and Dropping Nodes" section in XML Schema Explorer.
Use the context (right-click) menu in the XML Schema Explorer. For more
information, see Context menus.
Perform a search in the XSD Explorer and click the Add highlighted nodes to
Workspace button on the summary results pane. For more information, see
Searching the schema set.
Switch views
To switch views, use one of the following:
The context (right-click) menus of the Content Model View and the Graph View.
The watermarks on the Start View page or the watermark on the blank Content
Model View or the Graph View.
Hotkeys: Ctrl+1 for the Start View, Ctrl+2 for the Graph View, and Ctrl+3 for the
Content Model View.
Start View
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The Start View is the launching point for the XML Schema (XSD) Designer. When you
create a new XSD file, you will initially see the Start View.
The Start View contains two main sections, the watermark and the Schema Set Details
pane. It also includes the toolbar, which is available in all the XSD Designer views.
Watermark
The watermark pane contains a list of links to all the XSD Designer views, XML editor,
and XML Schema Explorer. If the schema set has errors, the following text is displayed
at the end of the list: "Use the Error List to view and fix the errors in the set."
The following buttons are enabled in the XSD Designer toolbar when the Start View is
active:
Option Description
Show Start View Switches to the Start View. This view can be accessed by using the keyboard
shortcut: Ctrl+1.
Show Content Switches to the Content Model View. This view can be accessed by using
Model View the keyboard shortcut: Ctrl+2.
Show Graph View Switches to the Graph View. This view can be accessed by using the
keyboard shortcut: Ctrl+3.
See also
XML Schema Explorer
Graph View
Content Model View
XML editor
Content Model View
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The Content Model View provides a graphic representation of local and global schema
nodes and their components, including simple and complex types, elements, model
groups, attributes, and attribute groups. XML comments and processing instructions
cannot be viewed in the Content Model View. The Content Model View contains two
panels: a Workspace panel that contains a list of the nodes in the XML schema designer
workspace, and the design surface where you can see the content model of schema
nodes that are selected in the Workspace panel. The Content Model View also includes
the XML Schema Designer toolbar and the breadcrumb bar.
In the following image, the Workspace panel contains six schema nodes. The
purchaseOrder node is selected in the Workspace panel and is displayed in the design
surface.
Workspace panel
After you add nodes to the workspace, the list of nodes will appear in the Workspace
panel of the Content Model View. When you select nodes in the Workspace panel, they
appear on the Content Model View design surface. To delete nodes from the workspace,
use the XSD Designer toolbar, the Workspace panel right-click menu, or the Delete key.
For information about adding nodes, see the "Adding Nodes to the Workspace" section
in XML schema designer workspace.
Design surface
When a node is selected in the Workspace panel, it is added to the Content Model View
design surface where you can view the details of the node.
If the design surface is blank, the XML editor, the XML Schema Explorer, and the
watermark are shown. The watermark is a list of links to all the XSD Designer views. If
the schema set has errors, the following text is displayed at the end of the list: "Use the
Error List to view and fix the errors in the set."
Breadcrumb bar
The breadcrumb bar at the bottom of the Content Model View shows where the
selected node is located in the schema set.
Context menus
When you right-click an item on the design surface or Workspace panel, a context menu
appears. The following table describes the options that are available for the Content
Model View design surface.
Option Description
Option Description
Show in XML Puts focus on the Schema Explorer and highlights the schema set node.
Schema
Explorer
Generate Available only for global elements. Generates a sample XML file for the global
Sample XML element.
View Code Opens the file that contains the selected node in the XML editor. The item that
is selected in the XML Schema Explorer is also selected in the XML editor.
Properties Opens the Properties window (if it is not already open). This window displays
Window information about the node.
The following table describes the options that are available for the Workspace panel.
Option Description
Show in XML Puts focus on the Schema Explorer and highlights the schema set node.
Schema Explorer
Remove from Removes selected nodes from the workspace and the design surface.
Workspace
Remove all but Removes nodes that are not selected from the workspace and the design
selection from surface.
Workspace
Generate Sample Available only for global elements. Generates a sample XML file for the
XML global element.
View Code Opens the file that contains the selected node in the XML editor. The item
that is selected in the XML Schema Explorer is also selected in the XML
editor.
Properties Window Opens the Properties window (if it is not already open). This window
displays information about the node.
Properties window
Use the right-click (context) menu to initially open the Properties window. By default,
the Properties window appears in the lower right corner of Visual Studio. When you
click a node that is rendered in the Content Model View, the properties of that node are
displayed in the Properties Window.
Option Description
Show Start View Switches to the Start View. This view can be accessed by using the
keyboard shortcut: Ctrl+1.
Show Content Model View Switches to the Content Model View. This view can be accessed by
using the keyboard shortcut: Ctrl+2.
Show Graph View Switches to the Graph View. This view can be accessed by using the
keyboard shortcut: Ctrl+3.
Remove from Workspace Removes selected nodes from the workspace and the design
surface.
Remove all but selection Removes nodes that are not selected from the workspace and the
from Workspace design surface.
Undo/Redo
The undo/redo capability is enabled in the Content Model View for the following
actions:
Adding multiple nodes from the search results window in Schema Explorer.
Zoom
Zoom is available in the lower right corner of the Content Model View.
By holding the Ctrl key and spinning the mouse wheel when the mouse is hovering
over the Content Model View surface.
By using the slider control. The slider shows the current zoom level.
The Zoom slider is opaque when you select it, hover over it, or use Ctrl with the mouse
wheel to zoom; at all other times, it is transparent.
If you make changes to the schema set in the XML editor the changes are synchronized
in the Content Model View. For more information, see Integration with XML editor.
See also
XML Schema Designer Workspace
Graph view
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The Graph View provides a graphic representation of global schema nodes and the
relationships between the nodes. Note that the Graph View does not allow you to alter
the layout of the schema set on the design surface. The Graph View also includes the
XML Schema Designer toolbar and the breadcrumb bar.
The following image shows the Graph View with six global nodes on its design surface.
Design surface
The design surface of the Graph View displays the contents of the XML schema designer
workspace. If the workspace contains any global nodes from the schema set, the nodes
are shown on the Graph View design surface and arrows are drawn between the nodes
that have relationships.
Double-clicking a node in the Graph View will bring up XML editor.
To delete selected nodes from the workspace, use the XSD Designer toolbar or the
Delete key.
If the design surface is blank, the XML editor, the XML Schema Explorer, and the
watermark are shown. The watermark is a list of links to all the XSD Designer views.
If the schema set has errors, the following text is displayed at the end of the list: "Use
the Error List to view and fix the errors in the set."
Breadcrumb bar
The breadcrumb bar at the bottom of the Graph View shows where the selected node is
located in the schema set. If multiple items are selected, the breadcrumb bar will be
blank.
Option Description
Show in XML Puts focus on the Schema Explorer and highlights the schema set node.
Schema Explorer
Generate Sample Available only for global elements. Generates a sample XML file for the
XML global element.
Remove from Removes selected nodes from the workspace and the design surface.
Workspace
Option Description
Remove all but Removes nodes that are not selected from the workspace and the design
selection from surface.
Workspace
View Code Opens the file that contains the selected node in the XML editor. The item
that is selected in the XML Schema Explorer is also selected in the XML
editor.
Properties Window Opens the Properties window (if it is not already open). This window
displays information about the node.
In addition to the common options described above, the context menu for global
elements also has the following options:
Option Description
Add All Adds all the nodes that refer to the element and draws arrows to indicate
References relationships between them.
Add Substitution Adds all substitution group members. This option appears in the view if the
Group Members element is the head or member of a substitution group.
Generate Sample Generates a sample XML file for the global element.
XML
In addition to the common options described above, the context menu for global simple
and global complex types also has the following options:
Option Description
Add Base If the selected type is derived from a global type, adds the base type of the
Type selected type.
Add All Adds all references of the selected type. This includes elements and attributes of
References the selected type, and types derived from the selected type.
Add All Adds all types that are directly and indirectly derived from the selected type.
Derived
Types
Option Description
In addition to the common options described above, the context menu for global
groups and attribute groups also has the following options:
Option Description
Add All Adds all nodes that refer to the group and draws arrows to indicate
References relationships between them.
Add All Adds all members of the group and draws arrows to indicate relationships
Members between them.
In addtion to the common options described above, the context menu for global
attributes also has the following options:
Option Description
Add All Adds all nodes that refer to the group and draws arrows to indicate
References relationships between them.
Properties window
Use the context (right-click) menu to initially open the Properties window. By default,
the Properties window appears in the lower right corner of Visual Studio. When you
click a node that is rendered in the Content Model View, the properties of that node will
be displayed in the Properties Window.
XSD toolbar
The following XSD Toolbar buttons are enabled when the Graph View is active.
Option Description
Show Start View Switches to the Start View. This view can be accessed by using the keyboard
shortcut: Ctrl+1.
Show Content Switches to the Content Model View. This view can be accessed by using the
Model View keyboard shortcut: Ctrl+2.
Option Description
Show Graph Switches to the Graph View. This view can be accessed by using the keyboard
View shortcut: Ctrl+3.
Remove from Removes selected nodes from the workspace and the design surface.
Workspace
Remove all but Removes nodes that are not selected from the workspace and the design
selection from surface. This option is enabled in the Content Model View and in the Graph
Workspace View.
Left to Right Changes the layout in the Graph View to a left-to-right hierarchical
representation of nodes. This option can be accessed by using the keyboard
shortcut: Alt+right arrow.
Right to Left Changes the layout in the Graph View to a right-to-left hierarchical
representation of nodes. This option can be accessed by using the keyboard
shortcut: Alt+left arrow.
Top to Bottom Changes the layout in the Graph View to a top-to-bottom hierarchical
representation of nodes. This option can be accessed by using the keyboard
shortcut: Alt+down arrow.
Bottom to Top Changes the layout in the Graph View to a bottom-to-top hierarchical
representation of nodes. This option can be accessed by using the keyboard
shortcut: Alt+up arrow.
Pan/Scroll
You can pan the design surface by using the scrollbars or by holding the Ctrl key while
you click and drag the mouse. When you pan the design surface using click and drag,
the cursor will change to four crossed arrows pointing in four directions.
Undo/Redo
The undo/redo capability is enabled in the Graph View for the following actions:
Adding multiple nodes from the search results window in Schema Explorer or Start
View queries.
By holding the Ctrl key and spinning the mouse wheel when the mouse is hovering
over the Graph View surface.
By using the slider control. The slider shows the current zoom level.
The Zoom slider is opaque when you select it, hover over it, or use Ctrl with the mouse
wheel to zoom; at all other times, it is transparent.
If you make changes to the schema set in the XML editor, the changes will be
synchronized in the Graph View. For more information, see Integration with XML editor.
See also
Design Surface
Integration with XML editor
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The XML Schema Designer is integrated with the XML editor. If you modify an XSD file in
the XML editor, the change will be reflected in the XML Schema Explorer. If you have the
Graph View or the Content Model View open, the change will also be reflected there.
You can navigate between the XML Schema Designer and the XML editor in the
following ways:
In the XML editor, right-click a node and select Show in XML Schema Explorer.
In the Graph View and the XML Schema Explorer, double-click a node, or right-
click a node and select View Code. In the Content Model View, right-click a node
and select View Code.
The following screenshot shows an XML Schema opened in the XML Schema Explorer.
The XML Schema Explorer displays the schema set in a tree view. The XML editor
displays the text view of the node that is currently active in the XML Schema Explorer.
Sometimes it is helpful to see the code in the XML editor and the graphical designer
side by side. To view both files at the same time, right-click anywhere in the XML editor
and select View Designer. In the Visual Studio Windows menu, select New Horizontal
(or Vertical) Tab Group.
See also
XML Schema Explorer
How to: Create and edit an XSD schema
file
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
This topic describes how to create a new XML Schema (XSD) file and then add content
to the XSD file.
2. In the New File dialog box, select XML Schema and then select Open.
A new file is created. The Start View and an empty XML Schema Explorer window
appear in Visual Studio.
To edit a file
1. Select the Use XML editor to view and edit the underlying XML Schema file link
on the Start View.
2. Copy the XML Schema sample code from Purchase order schema and paste it to
replace the code that was added to the new XSD file by default.
The XML Schema Explorer is updated with the new schema set.
How to: Create an XML document based
on an XSD schema
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The Generate Sample XML feature generates a sample XML file based on your XML
Schema (XSD) file.
The Generate Sample XML feature is only available on global elements, and requires a
valid XML schema set.
This feature typically generates valid XML documents. However, if the schema contains
one or more of the following, the sample might not be valid:
xs:pattern facets.
Also, note that xs:base64Binary content will be generated only if enumerations occur in
the schema for that type.
2. In the XML Schema Explorer, right-click the PurchaseOrder global element, and
then select Generate Sample XML.
When you select this option, the PurchaseOrder.xml file with the following sample
XML content will be generated and opened in the XML editor:
XML
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
This topic explains how to add nodes that are highlighted in the XML Schema Explorer
as the result of a keyword search in the workspace.
7 Note
2. Type "purchaseOrder" in the search text box of the XML Explorer toolbar and click
on the search button.
The search results are highlighted in the XML Schema Explorer and marked by
ticks on the vertical scroll bar.
3. Add the search results to the workspace by clicking the Add highlighted nodes to
Workspace button on the summary results pane.
The purchaseOrder node and the PurchaseOrderType node appear next to each
other on the design surface of the Graph View. Because the two nodes are related
(the purchaseOrder element is of the PurchaseOrderType type), an arrow is drawn
between them.
How to: Switch between views and the
XML editor
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
This topic shows how to switch between the XML Schema Designer (XSD Designer)
views and the XML editor. This example uses the Purchase order schema.
2. To switch to the XML Schema Designer from the XML editor, right-click anywhere
in the XML editor and select View Designer.
3. To switch to the Graph View using the watermark, click the Use the Graph view to
see the relationship between the nodes link on the Start View.
4. Drag the USAddress node from the XML Schema Explorer onto the Graph View.
Right-click the USAddress node in the Graph View and select Show in Content
Model View in the context menu.
The Content Model View with the details of USAddress node appears.
5. To switch to the Start View from the Content Model View using the toolbar, click
the Start View button on the XSD toolbar.
6. To switch between the views using the hotkeys, press Ctrl+1 for the Start View,
Ctrl+2 for the Graph View, and Ctrl+3 for the Content Model View.
7. To go to XML editor from the Content Model View, right-click the node and select
View Code in the context menu.
How to: Add nodes to the workspace
from the XML Schema Explorer
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
This topic explains how to add nodes to the XML Schema Designer workspace from the
XML Schema Explorer. This can be achieved by dragging and dropping nodes from the
XML Schema Explorer onto an XSD Designer view, or by using the XML Schema
Explorer's context menu. You can also add nodes that are highlighted as a result of a
search performed by the XML Schema Explorer. For more information, see How to: Add
schema set search result nodes to the workspace.
7 Note
Only global nodes can be added to the XML Schema Designer workspace.
2. Right click on the PurchaseOrderType node in the XSD Explorer. Select Show in
Graph View.
The purchaseOrderType node appears on the design surface of the Graph View.
2. Right click on the PurchaseOrderType node in the XML Schema Explorer and select
Show All References.
The purchaseOrder node and the PurchaseOrderType node appear next to each
other on the design surface of the Graph View. Because the two nodes are related
(the purchaseOrder element is of the PurchaseOrderType type), an arrow is drawn
between them.
The search results are highlighted in the XML Schema Explorer and marked by
ticks on the vertical scroll bar.
2. Add the search results to the workspace by clicking the Add highlighted nodes to
Workspace button on the summary results pane.
The purchaseOrder node and the PurchaseOrderType node appear next to each
other on the design surface of the Graph View. Because the two nodes are related
(the purchaseOrder element is of the PurchaseOrderType type), an arrow is drawn
between them.
See also
XML Schema Explorer
How to: Add nodes to the workspace
from the Start View
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
This topic describes how to add global nodes to the XML Schema Designer workspace
from the Start View.
In the Schema Set Details section, notice that there are two (2) Global Complex
Types.
3. Click on the add link to the right of the Global Complex Types heading.
The USAddress and PurchaseOrderType complex type nodes will appear on the
design surface of the Graph View.
How to: Get an overview of a schema
set by using the Graph View
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
This topic describes how to use the Graph View to see a high-level view of the nodes in
a schema set and the relationships between the nodes.
2. Click the Use XML editor to view and edit the underlying XML Schema file link on
the Start View.
3. Copy the XML Schema sample code from Sample XML schema: relationships and
paste it to replace the code that was added to the new XSD file by default.
6. Select Schema Set node in the XML Schema Explorer and drag the node to design
surface of the Graph View. You should see all the global nodes, and arrows
connecting the nodes that have relationships.
7. Click on any node on the design surface and look at the breadcrumb bar to see
where the selected node is located in the schema set.
8. Rick-click on any element node on the design surface and select Generate Sample
XML to see the XML instance document.
How to: Examine the content model of
nodes by using the Content Model View
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
This topic describes how to explore your nodes by using the Content Model View.
2. Click Use XML editor to view and edit the underlying XML Schema file on the
Start View.
3. Copy the XML Schema sample code from Sample XML schema: purchase order
schema and paste it to replace the code that was added to the new XSD file by
default.
5. Right-click the purchaseOrder in the XML Explorer and select Show in Content
Model View.
The Content Model View displays the purchaseOrder element on its design surface.
6. Expand the shipTo , billTo , and items nodes either by double-clicking each node
or by clicking the double arrow to the right of each node.
The nodes of the purchaseOrder element are now expanded and you can see the
content model of the element.
7. Click on any node under the purchaseOrder element and look at the breadcrumb
bar to see where in the schema set the selected node is located.
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
This topic describes how to view a schema associated with an XML literal in a Visual
Basic project.
The new project contains one Visual Basic source file, Module1.vb.
3. In Solution Explorer, right-click the project's name, select Add, and then select
Existing Item. The AddExisting Item dialog box appears. Browse to the
PurchaseOrderSchema.xsd file, select it, and then click Add.
Add code
To add Visual Basic code with an XML literal, based on the XSD file included in the
project:
VB
Imports <xmlns:ns="http://tempuri.org/PurchaseOrderSchema.xsd">
Module Module1
Sub Main()
End Sub
End Module
2. Right-click any XML node in an XML literal or an XML namespace import and select
Show in Schema Explorer.
The XML Schema Explorer is displayed side by side with a Visual Basic file that has
the XML literal associated with the XML schema set.
How to: Print diagrams from the Graph
View and the Content Model View
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
This topic describes how to print a diagram from the Graph View or the Content Model
View of XML Schema Designer.
2. Export the diagram to an XPS file by using the Export Diagram as Image context
(right-click) menu item in the design surface of the Graph View or the Content
Model View.
When you export a diagram from the Graph View, the whole design surface is
exported to the XPS file. When you export a diagram from the Content Model View
and more than one node appears on the Content Model View's design surface,
only the first node is exported to the XPS file.
3. Print the saved image in the XPS file by using an XPS viewer.
See also
Graph View
Content Model View
XML Schema Designer workspace
Sample XSD file: Simple schema
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The following XSD file is used in various examples in the XSD Schema Designer
documentation. This file is a simple purchase order schema.
XML
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://tempuri.org/PurchaseOrderSchema.xsd"
targetNamespace="http://tempuri.org/PurchaseOrderSchema.xsd"
elementFormDefault="qualified">
<xsd:element name="PurchaseOrder" type="tns:PurchaseOrderType"/>
<xsd:complexType name="PurchaseOrderType">
<xsd:sequence>
<xsd:element name="ShipTo" type="tns:USAddress" maxOccurs="2"/>
<xsd:element name="BillTo" type="tns:USAddress"/>
</xsd:sequence>
<xsd:attribute name="OrderDate" type="xsd:date"/>
</xsd:complexType>
<xsd:complexType name="USAddress">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="street" type="xsd:string"/>
<xsd:element name="city" type="xsd:string"/>
<xsd:element name="state" type="xsd:string"/>
<xsd:element name="zip" type="xsd:integer"/>
</xsd:sequence>
<xsd:attribute name="country" type="xsd:NMTOKEN" fixed="US"/>
</xsd:complexType>
</xsd:schema>
7 Note
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The following XSD file is used in various examples in the XSD Schema Designer
documentation. This file is a purchase order schema.
XML
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://tempuri.org/PurchaseOrderSchema.xsd"
targetNamespace="http://tempuri.org/PurchaseOrderSchema.xsd"
elementFormDefault="qualified">
<xsd:element name='comment' type='xsd:string'/>
<xsd:complexType name='USAddress'>
<xsd:annotation>
<xsd:documentation>
Purchase order schema for Example.Microsoft.com.
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name='name' type='xsd:string'/>
<xsd:element name='street' type='xsd:string'/>
<xsd:element name='city' type='xsd:string'/>
<xsd:element name='state' type='xsd:string'/>
<xsd:element name='zip' type='xsd:decimal'/>
</xsd:sequence>
<xsd:attribute name='country' type='xsd:NMTOKEN' fixed='US'/>
</xsd:complexType>
<xsd:simpleType name='SKU'>
<xsd:restriction base='xsd:string'>
<xsd:pattern value='\d{3}\w{3}'/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name='Items'>
<xsd:sequence>
<xsd:element name='item' minOccurs='0' maxOccurs='unbounded'>
<xsd:complexType>
<xsd:sequence>
<xsd:element name='productName' type='xsd:string'/>
<xsd:element name='quantity'>
<xsd:simpleType>
<xsd:restriction base='xsd:positiveInteger'>
<xsd:minInclusive value='1'/>
<xsd:maxExclusive value='100'/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name='USPrice' type='xsd:decimal'/>
<xsd:element ref='tns:comment'/>
<xsd:element name='shipDate' type='xsd:date' minOccurs='0'/>
</xsd:sequence>
<xsd:attribute name='partNum' type='tns:SKU'/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name='PurchaseOrderType'>
<xsd:sequence>
<xsd:element name='shipTo' type='tns:USAddress'/>
<xsd:element name='billTo' type='tns:USAddress'/>
<xsd:element ref='tns:comment' minOccurs='0'/>
<xsd:element name='items' type='tns:Items'/>
</xsd:sequence>
<xsd:attribute name='orderDate' type='xsd:date'/>
<xsd:attribute name='confirmDate' type='xsd:date' use='required'/>
</xsd:complexType>
</xsd:schema>
7 Note
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The following XSD file is used in various examples in the XSD Schema Designer
documentation. This file is a purchase order schema with annotations and
documentation.
XML
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:attributeGroup name="NameAgeAttributes">
<xs:attribute name="age" type="xs:integer" use="required"/>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:attributeGroup>
<xs:complexType name="PetType">
<xs:attributeGroup ref="NameAgeAttributes"/>
</xs:complexType>
7 Note
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
You can debug XSLT code in Visual Studio. The XSLT debugger supports setting
breakpoints, viewing XSLT execution states, and so on. The XSLT debugger can be used
to debug XSLT style sheets or XSLT applications.
You can execute code one line at a time by stepping into, stepping over, or stepping out
of the code. The commands for using the code-stepping functionality of the XSLT
debugger are the same as those for the other Visual Studio debuggers.
Once you start debugging, the XSLT debugger opens windows to show the input
document and the XSLT output.
7 Note
The XSLT debugger is only available in the Professional and Enterprise editions of
Visual Studio.
2. Select Start XSLT Debugging from the XML menu or press Alt+F5.
7 Note
Stepping into XSLT from the XslTransform class is not supported. The
XslCompiledTransform class is the only XSLT processor that supports stepping into
XSLT while debugging.
The XSLT style sheet is loaded in a new document window and the XSLT debugger
starts.
Alternatively, you can add a break point to the style sheet and run your
application.
Example
The following is an example of a C# XSLT program. It shows how to enable XSLT
debugging.
C#
using System;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
namespace ConsoleApplication
{
class Program
{
private const string sourceFile = @"c:\data\xsl_files\books.xml";
private const string stylesheet = @"c:\data\xsl_files\below-
average.xsl";
private const string outputFile = @"c:\data\xsl_files\output.xml";
XSLT profiler
The XSLT profiler is a tool that lets developers measure, evaluate, and target
performance-related problems in XSLT code by creating detailed XSLT performance
reports. For more information, see XSLT profiler.
See also
Walkthrough: Debug an XSLT style sheet
First look at the Visual Studio debugger
Debugging basics: Breakpoints
Walkthrough: Debug an XSLT style sheet
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
The steps in this walkthrough demonstrate how to use the XSLT debugger. Steps include
viewing variables, setting breakpoints, and stepping through the code. The debugger
lets you execute code one line at a time.
To prepare for this walkthrough, first copy the two sample files to your local computer.
One is the style sheet, and one is the XML file we'll use as input to the style sheet. In this
walkthrough, the style sheet we use finds all books whose cost is below the average
book price.
7 Note
The XSLT debugger is only available in the Professional and Enterprise editions of
Visual Studio.
Start debugging
1. From the File menu, choose Open > File.
3. Click the browse button (...) on the Input field of the document properties window.
(If the Properties window is not visible, right-click anywhere on the open file in the
editor, and then choose Properties.)
This sets the source document file that's used for the XSLT transformation.
6. On the menu bar, choose XML > Start XSLT Debugging (or, press Alt+F5).
In the editor, the debugger is positioned on the xsl:if element of the style sheet.
Another file named below-average.xml opens in the editor; this is the output file
that will be populated as each node in the input file books.xml is processed.
The Autos, Locals, and Watch 1 windows appear at the bottom of the Visual Studio
window. The Locals window displays all the local variables and their current values.
This includes variables defined in the style sheet and also variables that the
debugger uses to track the nodes that are currently in context.
Watch window
We'll add two variables to the Watch 1 window so we can examine their values as the
input file is processed. (You can also use the Locals window to examine values if the
variables you want to watch are already there.)
1. From the Debug menu, choose Windows > Watch > Watch 1.
3. On the next line, type self::node() in the Name field, and then press Enter.
4. Expand the self::node() node, and then expand the node who's value is price .
You can see the value of the book price for the current book node and compare it
to the $bookAverage value. Because the book price is below the average, the
xsl:if condition should succeed when you continue the debugging process.
Because the first book node satisfied the xsl:if condition, the book node is
added to the below-average.xml output file. The debugger continues to execute
until it is positioned again on the xsl:if element in the style sheet. The debugger
is now positioned on the second book node in the books.xml file.
In the Watch 1 window, the self::node() value changes to the second book node.
By examining the value of the price element, you can determine that the price is
above the average, thus the xsl:if condition should fail.
2. Press F5 to continue.
Because the second book node does not meet the xsl:if condition, the book
node is not added to the below-average.xml output file. The debugger continues
to execute until it's positioned again on the xsl:if element in the style sheet. The
debugger is now positioned on the third book node in the books.xml file.
In the Watch 1 window, the self::node() value changes to the third book node. By
examining the value of the price element, you can determine that the price is
below the average. The xsl:if condition should succeed.
3. Press F5 to continue.
Because the xsl:if condition was satisfied, the third book is added to the below-
average.xml output file. All books in the XML document have been processed and
the debugger stops.
Sample files
The following two files are used by the walkthrough.
below-average.xsl
XML
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8"/>
<xsl:template match="/">
<xsl:variable name="bookCount" select="count(/bookstore/book)"/>
<xsl:variable name="bookTotal" select="sum(/bookstore/book/price)"/>
<xsl:variable name="bookAverage" select="$bookTotal div $bookCount"/>
<books>
<!--Books That Cost Below Average-->
<xsl:for-each select="/bookstore/book">
<xsl:if test="price < $bookAverage">
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</books>
</xsl:template>
</xsl:stylesheet>
books.xml
XML
<?xml version='1.0'?>
<!-- This file represents a fragment of a book store inventory database -->
<bookstore>
<book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
<book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
<title>The Gorgias</title>
<author>
<name>Plato</name>
</author>
<price>9.99</price>
</book>
</bookstore>
See also
Debugging XSLT
Evaluate XPath expressions
Article • 12/12/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
You can evaluate XPath expressions by using the QuickWatch window during
debugging. The XPath expression must be valid according to the W3C XPath 1.0
recommendation. The current XSLT context (that is, the self::node() node in the Locals
window) provides the evaluation context for the XPath expression.
7 Note
2. To start debugging, choose XML > Start XSLT Debugging on the menu bar (or,
press Alt+F5).
4. Enter ./price/text() in the Expression field of the QuickWatch dialog box, and
then choose Reevaluate.
The price of the current book node appears in the Value box.
5. Change the XPath expression to ./price/text() < $bookAverage and click
Reevaluate.
The Value box shows that the XPath expression evaluates to true .
Related content
Debugging XSLT
Debugger user interface (XSLT)
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
This article describes the debugger windows and dialog boxes. It only discusses user
interface pieces that have XSLT-specific debugging behavior.
Locals window
The Locals window displays information about any variables defined in the style sheet.
The Locals window contains three columns of information:
Name
This column contains the names of all local variables in the current scope. Node sets
have a tree control that you can drill down to see its subfolders.
Value
This column shows the value contained by each variable. Attribute, processing
instruction, comment, text, and CData nodes display the text value of the node.
Namespace nodes display the namespace URI.
Type
This column identifies the data type of each variable listed in the Name column.
The Locals window also displays the predefined context variables that track the context
of the XSLT transformation. The following table describes the predefined context
variables used by the XSLT debugger.
Name Description
position() The position, or index number, of the context node, relative to the context size.
Output window
The Output window shows any error messages or security exceptions that occur during
debugging. It also shows debugger output.
Task List
The Task List lists all the compilation errors in the style sheet. Double-clicking the error
takes the cursor to the line with the error.
The Task List includes any errors that occur in the script blocks in the XSLT file.
7 Note
The XSLT debugger has no warnings, so they never appear in the Task List.
Breakpoints window
The Breakpoints window shows all breakpoints set in the current project. If a breakpoint
is added while the window is in view, the window is automatically updated to show the
new breakpoint.
The Breakpoints window should behave the same way as other Visual Studio debuggers.
Watch window
The Watch window is used to evaluate variables. You can also change the values of the
variables.
The variables displayed in the Watch window are for the current context (the top-most
item on the call stack). If you change the context, the watch window updates and
displays variables set for that context.
The call stack represents the various contexts that the XSLT execution is going through.
For example, if there is a call from template "a" to template "b", template "a" and
template "b" appear in the Call Stack window with the current context at the top of the
list. The user is able to see the query that is currently executing.
If the templates do not have a name in the XSLT file, the names generated by the XSLT
processor are used.
Clicking an item other than the one at the top of the list indicates to the viewer where
the XSLT execution branch happened using the standard green highlighting and green
arrows.
Built-in XSLT functions such as document() and key() are not allowed.
Disassembly window
The Disassembly window shows the assembly code that is generated by the XSLT
compiler. This window can be used in the same manner as all other Visual Studio
disassembly windows.
See also
Debugging XSLT
First look at the debugger
Inspect variables in the autos and locals windows in Visual Studio
XSLT default templates
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
A default template is used during XSLT processing when there is no matching explicit
template rule in the style sheet. The default template, also referred to as built-in
template rule, is defined in section 5.8 of the W3C XSLT 1.0 Recommendation. The
default template allows the XSLT processor to process a node, even though there is no
explicit template rule that matches it. However, because the built-in template rule is not
explicitly defined in the style sheet, this may lead to unexpected or confusing XSLT
transformation results.
The XSLT debugger now displays the code of XSLT default templates. When you step
through an XSLT transformation, if a default template is used, the debugger displays the
default template in a window. This enables you to step through the code of the default
template and set breakpoints on its instructions.
See also
Debugging XSLT
Security considerations when working
with XML data
Article • 03/10/2023
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
This topic discusses security issues that you need to know about when working with the
XML editor or the XSLT debugger.
XML editor
The XML editor is based on the Visual Studio Text Editor. It relies on the System.Xml and
System.Xml.Xsl classes to handle many of the XML processes.
Schemas that point to an external location in the catalog file are automatically
downloaded when the XML editor first loads. The XmlSchemaSet class is used to
compile the schemas. The catalog file that ships with the XML editor does not have
links to any external schemas. The user has to explicitly add a reference to the
external schema before the XML editor downloads the schema file. HTTP
downloading can be disabled via the Miscellaneous Tools Options page for the
XML editor.
XSLT debugger
The XSLT debugger utilizes the Visual Studio managed debug engine and classes from
the System.Xml and System.Xml.Xsl namespace.
The XSLT debugger runs each XSLT transformation in a sandboxed application
domain. The code access security policy of your computer is used to determine the
restricted permissions based on where the XSLT style sheet is located. For example,
style sheets from an Internet location have the most restricted permissions,
whereas style sheets copied to your hard drive run with Full Trust.
The XSLT expression evaluator is loaded by the managed debug engine. The
managed debug engine assumes that all code is run from the user's local
computer. Accordingly, the XslCompiledTransform class downloads the XSLT file to
the user's local computer. The possibility that an elevation in execution privilege
could occur is mitigated by executing all XSLT transformations in a new application
domain with restricted permissions
See also
Application domains