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?