简体   繁体   中英

How to get XML IntelliSense working in VS 2015?

Visual Studio supports XML IntelliSense for Visual Basic (it suggests XML element and attribute names as you type). I am attempting to use VS 2015 to update a project I started a few years ago in VS 2012 or 2013. The project uses XML and I had set up to use XML IntelliSense. The project compiles under VS 2015 and runs correctly, but XML IntelliSense is not working (no element names are suggested).

To try to troubleshoot the problem, I created the following XML file (stored as Test.xml in My Documents):

<?xml version="1.0" encoding="utf-8"?>
<Root xmlns="http://www.finetime.com">
    <Parent>
        <Child>Data</Child>
    </Parent>
</Root>

I created a new Windows Forms project with a single button Button1 on a single form Form1 and added the following XML schema to the project (the XSD file is shown in Solution Explorer):

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.finetime.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.finetime.com">
  <xs:element name="Root">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="Parent">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Child" type="xs:string" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

The code for Form1 looks like this:

Imports <xmlns:ft="http://www.finetime.com">

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim xmlPath As String = IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, "Test.xml")
        Dim xmlDoc As XDocument = XDocument.Load(xmlPath)
        Dim root As XElement = xmlDoc.<ft:Root>.First
        Dim data As String = root.<ft:Parent>.<ft:Child>.Value
        MessageBox.Show(data)
    End Sub
End Class

The project compiles, runs, and displays "Data" in the MessageBox when the button is clicked, but XML word completion doesn't happen.

For example, when I type Dim root As XElement = xmlDoc.<ft: I would expect to be shown choices of XML element names to complete the statement, but nothing appears. Am I missing a step?

It appears as though XML Intellisense was not included for VB under the Roslyn rebuild (VS2015). This is documented in a MS Connect ticket: https://connect.microsoft.com/VisualStudio/feedback/details/1085407/intellisense-not-working-with-xml-to-schema .

Posted by Kevin [MSFT] on 1/14/2015 at 9:43 AM Hi,

Thanks for the feedback. Unfortunately, this is one of the corners of the VB IDE experience that has not yet been re-built as part of the Roslyn project. We have a workitem on our backlog to consider implementing this in the future.

-- Kevin Pilch-Bisson Visual Studio Managed Languages

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM