Imports System.Xml.Linq
Imports System.Linq
Partial Class test2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim xml As XElement = <book>
<title>My Title</title>
<author>Kyle</author>
<publisher>WROX</publisher>
</book>
End Sub
End Class
Приведенный выше код вызывает следующую ошибку:
Compiler Error Message: BC30201: Expression expected.
Source Error:
Line 8:
Line 9: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Line 10: Dim xml As XElement = <book>
Line 11: <title>My Title</title>
Line 12: <author>Kyle</author>
Source File: C:\Inetpub\wwwroot\myproject\web\test2.aspx.vb Line: 10
Почему?
редактирование:
Dim xml As XElement = New XElement("book", _
New XElement("title", "My Title"), _
New XElement("author", "Kyle"), _
New XElement("publisher", "WROX") _
)
Приведенный выше код работает, но, очевидно, не так элегантно, как оригинал, и я все равно был бы признателен за объяснение, почему мой оригинальный синтаксис неверен.