Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 322437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:56:20+00:00 2026-05-12T08:56:20+00:00

Imports System.Xml.Linq Imports System.Linq Partial Class test2 Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As

  • 0
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

The above code is producing the following error:

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 

Why?

edit:

Dim xml As XElement = New XElement("book", _
                New XElement("title", "My Title"), _
                New XElement("author", "Kyle"), _
                New XElement("publisher", "WROX") _
            )

The above code works, but obviously is not as elegant as the original and I would still appreciate an explanation of why my original syntax is wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:56:20+00:00Added an answer on May 12, 2026 at 8:56 am

    The code works fine for me as is, but maybe try starting the XML literal on a new line?

        Dim xml As XElement = _
                <book>
                    <title>My Title</title>
                    <author>Kyle</author>
                    <publisher>WROX</publisher>
                </book>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this class that contains vars for db connection; Imports Microsoft.VisualBasic Imports System.Data.SqlClient
I have the following test method: Imports System.Web Imports System.Web.Services Imports System.Web.Services.Protocols <WebService(Namespace:=http://tempuri.org/)> _
I have the following code : Imports System.Data.OleDb Private Sub getData() Dim connStr As
Im trying push some data into a CRM system via an XML import. I
I have tried the following code but has no effect: Imports system.Runtime.InteropServices <DllImport(UxTheme.DLL, BestFitMapping:=False,
I am trying to write extension methods in VB.NET Imports System.Runtime.CompilerServices Module ExtensionMethods <Extension()>
We are developing a c# application that imports address-data into a CRM-system. The CSV-file
import java.lang.System; public class Splitter{ public static void main(String args[]){ String path_separator = Path
in a web application, i want to insert the XML file content into an
i do a simple application with nhibernate: class utilisateur.hbm.xml <?xml version=1.0 encoding=utf-8 ?> <hibernate-mapping

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.