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

  • Home
  • SEARCH
  • 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 970443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:48:21+00:00 2026-05-16T02:48:21+00:00

I am trying to use xml documents to store data for a movie database,

  • 0

I am trying to use xml documents to store data for a movie database, but am having an issue, I am new to using xml for documents and have been using tutorials and MSDN to figure it out but I am stuck thanks in advance

here is the code I am using

Imports <"...\movies.xml">

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

    Dim movieToAdd As Movie = getMovieInfo()
    MovieBindingSource.AddNew()
    Dim doc = XDocument.Load("..\..\movies.xml")
    Dim movieAdd = (<temp>
                        <Movie>
                            <MovieID><%= movieToAdd.MovieID %></MovieID>
                            <MovieTitle><%= movieToAdd.MovieTitle %></MovieTitle>
                            <Studio><%= movieToAdd.Studio %></Studio>
                            <Director><%= movieToAdd.Direcotor %></Director>
                            <ReleaseYear><%= movieToAdd.ReleaseYear %></ReleaseYear>
                            <Genre><%= movieToAdd.Genre %></Genre>
                            <Rating><%= movieToAdd.Rating %></Rating>
                            <DVD><%= movieToAdd.DVD %></DVD>
                            <BluRay><%= movieToAdd.BluRay %></BluRay>
                            <VHS><%= movieToAdd.VHS %></VHS>
                            <ScreenFormat><%= movieToAdd.ScreenFormat %></ScreenFormat>
                            <MovieCase><%= movieToAdd.MovieCase %></MovieCase>
                            <RunTime><%= movieToAdd.RunTime %></RunTime>
                            <NumberOfDiscs><%= movieToAdd.NumberOfDiscs %></NumberOfDiscs>
                        </Movie>
                    </temp>)
    Try
        Dim addMovie = doc.<movies:Movies>(0)
        addMovie.Add(movieAdd.Nodes())
        doc.Save("..\..\movies.xml")
    Catch ex As Exception
        Throw ex
    End Try
End Sub

Private Function getMovieInfo() As Movie

    Dim movieToAdd As New Movie

    movieToAdd.MovieID = CInt(MovieIDTextBox.Text)
    movieToAdd.MovieTitle = MovieTitleTextBox.Text
    movieToAdd.Studio = StudioTextBox.Text
    movieToAdd.Direcotor = DirecotorTextBox.Text
    movieToAdd.ReleaseYear = ReleaseYearTextBox.Text
    movieToAdd.Genre = GenreComboBox.SelectedText
    movieToAdd.Rating = RatingComboBox.SelectedText
    movieToAdd.ScreenFormat = ScreenFormatComboBox.SelectedText
    movieToAdd.NumberOfDiscs = NumberOfDiscsTextBox.Text
    movieToAdd.RunTime = CInt(RunTimeTextBox.Text)
    movieToAdd.BluRay = CBool(BluRayCheckBox.CheckState)
    movieToAdd.DVD = CBool(DVDCheckBox.CheckState)
    movieToAdd.VHS = CBool(VHSCheckBox.CheckState)
    movieToAdd.MovieCase = CBool(MovieCaseCheckBox.CheckState)

    Return movieToAdd
End Function

Inn xml file I get this

<Movie xmlns="">
  <MovieID>22</MovieID>
  <MovieTitle>test</MovieTitle>
  <Studio>test</Studio>
  <Director>test</Director>
  <ReleaseYear>2121</ReleaseYear>
  <Genre></Genre>
  <Rating></Rating>
  <DVD>false</DVD>
  <BluRay>false</BluRay>
  <VHS>false</VHS>
  <ScreenFormat></ScreenFormat>
  <MovieCase>false</MovieCase>
  <RunTime>123</RunTime>
  <NumberOfDiscs>2</NumberOfDiscs>
</Movie>

Why do I get that xmlns = "" in the movie parent node?

Of I remove the parent node from the movieAdd variable it puts xlmns = in all the nodes

Can anyone show me what I am doing 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-16T02:48:21+00:00Added an answer on May 16, 2026 at 2:48 am

    It seems (although you didn’t share it) that the movies XML file uses namespaces. So I assume that somewhere in that file (probably on the root element) you will have something like xmlns=”mymovieurl”.
    The important thing to realize is that each XML element and attribute is identified by a pair of strings. The local name (Movie, DVD, VHS, …) and the namespace URI (empty, mymovieurl, …). In your code above, since you didn’t specify a default namespace all your elements are in the empty namespace (their namespace URI is an empty string).
    But your XML file to which you’re adding these have its elements in some non-empty namespace (mymovieurl).
    In order to preserve the namespace for the element you’re adding the code has to inject the xmlns=”” attribute which marks that element and all its children to be in the empty namespace (just like you specified it in your code).

    The solution depends on what you want to achieve. I assume that you want to add the elements into the namespace the rest of the file uses.

    One simple way to do that is to add
    Imports

    That means that all elements in your code without a prefix should belong to the namespace “mymovieurl”. (Just change that to whatever namespace URI you movies file is using).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.