Compartilhar via


IntelliSense XML no Visual Basic

The Visual Basic Code Editor includes IntelliSense features for XML that provide word completion for elements defined in an XML schema. Se você incluir um esquema XML IntelliSenseImports XElement e XDocument objetos. The following illustration shows the IntelliSense members list for an XElement object.

XML IntelliSense

IntelliSense XML no Visual Basic

Enabling XML IntelliSense in Visual Basic

To enable XML IntelliSense in Visual Basic, you must include an XSD schema file in your Visual Basic project. You must also import the target namespace for the XSD schema into your code file by using the Imports statement. Alternatively, you can add the target namespace to the project-level namespace list by using the References page of the Visual Basic Project Designer. For examples, see Como: Habilitar o XML IntelliSense no Visual Basic. For more information, see Instrução Imports (Namespace XML) and Referências de página, Designer de projeto (Visual Basic).

Note that by default you cannot see XSD schema files in Visual Basic projects. You may have to click the Show All Files button to select an XSD file to include in your project.

Gerando um esquema Arquivo (inferência do esquema)

You can create an XSD schema for an existing XML file by inferring the XSD schema by using Visual Studio XML tools.

  • A partir do SP1, você pode usar o XML para o Assistente de esquema para criar um conjunto de esquema XML é deduzido a partir de um ou mais documentos XML e incluí-lo em seu projeto. Você pode usar qualquer combinação de documentos XML na formulário de arquivos de texto, XML , de endereços de Internet HTTP ou XML , o que é digitado ou colado em XML para o Assistente de esquema. Para acessar o XML para o Assistente de esquema, clique AdicionarNovo Item no projeto menu e adicione um XML esquema omodelo do dados ou Itens comunsgrupo demodelo . Depois que você incluiu todas as fontes de documento XML para inferir o conjunto de esquema XML do, clique em OK para criar o inferido do esquema definido. Para obter mais informações, consulte XML para assistente de esquema (Visual Basic) e Como: Criar um esquema XML definido usando o assistente de XML para esquema (Visual Basic)

  • Você também pode usar o Editor deXML Visual Studioinferir um conjunto deesquema XSDde um arquivo XML . Para criar um XMLesquema é definida usando o Editor de XML , em aberto um XML noXML Designer Visual Studiode arquivo e clique em Create Schema sobre o XMLmenu. Depois que você criar oesquema de XSDdefinido, você pode salvar o conjunto de esquema de criado em um ou mais arquivos XSD e incluí-los em seu projeto. Para obter mais informações, consulteComo: Habilitar o XML IntelliSense no Visual Basic.

Observe que os diferentes conjuntos deesquema XSDpodem ser deduzidos a partir de vários documentos XML que devem ter o mesmo esquema. This can occur when particular elements and attributes are found in one XML file and not in another, or when elements are included in different order, for example. Você deve examinar os conjuntos deesquema XSDinferidos abrangência e a precisão quando você usa ainferênciadoesquema XSD.

Member List

After you type a period (.) to delimit an instance of an XElement or XDocument object (or an instance of IEnumerable(Of XElement) or IEnumerable(Of XDocument)), Visual Basic IntelliSense displays a list of possible object members. The initial list includes three options that represent XML axis properties, as described in the following list.

Option

Description

< >

Select this option to show a list of possible child elements. For more information, see Literal de elemento XML (Visual Basic) and the Elements method.

@

Select this option to show a list of possible attributes. For more information, see Propriedades de eixo XML (Visual Basic).This option is available only for objects of type XElement.

…< >

Select this option to show a list of possible descendant elements. For more information, see Como: Acessar Elementos Descendant XML (Visual Basic) and the Elements method.

Select or begin typing any of the XML options from the list. The member list will then display potential members from the XML schema that are specific to the selected option. If you have XML namespaces imported that are associated with a specific XML namespace prefix, a list of potential XML namespace prefixes is included in the member list.

For example, consider the following XSD schema.

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" 
           elementFormDefault="qualified" 
           targetNamespace="http://SamplePurchaseOrder" 
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="PurchaseOrders">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="PurchaseOrder">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Address" />
              <xs:element name="Items" />
              <xs:element name="Comment" />
            </xs:sequence>
            <xs:attribute name="PurchaseOrderNumber" type="xs:unsignedShort" use="required" />
            <xs:attribute name="OrderDate" type="xs:string" use="required" />
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Valid XML for the XSD schema would resemble the following.

<?xml version="1.0"?>
<PurchaseOrders xmlns="http://SamplePurchaseOrder">
  <PurchaseOrder PurchaseOrderNumber="12345" OrderDate="2000-1-1">
    <Address />
    <Items />
    <Comment />
  </PurchaseOrder>
</PurchaseOrders>

If you include this XSD schema file in a project and import the target namespace from the XSD schema into your code file or project, Visual Basic IntelliSense displays members from the schema as you type your Visual Basic code. If the target namespace for the XSD schema is imported as the default namespace and you type the following, IntelliSense displays a list of possible child elements for the PurchaseOrder XML element.

Dim po = <PurchaseOrder />
po.<

The list consists of the Address, Comment, and Items elements.

Certainty Levels for IntelliSense List Items

Determining the XSD type to use for IntelliSense is not exact. As a result, XML IntelliSense will often show an expanded list of possible members. To aid you in selecting an item from the IntelliSense member list, items are displayed with an indication of the level of certainty that XML IntelliSense has for a particular member.

Sometimes XML IntelliSense can identify a specific type from the XSD schema. In these cases, it will display possible child elements, attributes, or descendant elements for that XSD type with a high degree of certainty. These items are identified with a check mark.

However, sometimes XML IntelliSense is not able to identify a specific type from the XSD schema. In these cases, it will display an expanded list of possible child elements, attributes, or descendant elements from the XSD schema for the project with a low degree of certainty. These items are identified with a question mark.

Consulte também

Tarefas

Como: Habilitar o XML IntelliSense no Visual Basic

Como: Criar um esquema XML definido usando o assistente de XML para esquema (Visual Basic)

Referência

XML para assistente de esquema (Visual Basic)

Instrução Imports (Namespace XML)

Literal de elemento XML (Visual Basic)

Propriedade de eixo de atributo XML (Visual Basic)

Propriedade de eixo descendente XML (Visual Basic)

Referências de página, Designer de projeto (Visual Basic)