updating an XML file in VB

2 views
Skip to first unread message

RustyFuture

unread,
Apr 12, 2008, 6:57:12 AM4/12/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi Guys,

I have a friend who is developing a dvd store in Visual basic ( It's a
WPF application) and stores the data in an XML file.

the content of the XML look like this:

<DVDInfo>
<DVD>
<DVDTitle>The Exorcist</DVDTitle>
<Director>William Friedkin</Director>
<Cast>Linda Blair</Cast>
<Description>Horror</Description>
<Rating>18</Rating>
<Cost>7.99</Cost>
<Copies>0</Copies>
<Rental>0</Rental>
<Image>Exorcist.jpeg</Image>
</DVD>
<DVD>
<DVDTitle>The Matrix</DVDTitle>
<Director>Wachowski</Director>
<Cast>Keanu Reaves</Cast>
<Description>Action</Description>
<Rating>15</Rating>
<Cost>7.99</Cost>
<Copies>20</Copies>
<Rental>0</Rental>
<Image>Matrix.jpeg</Image>
</DVD>
<DVD>
<DVDTitle>The Sahara</DVDTitle>
<Director>Breck Eisner</Director>
<Cast>Matthew McConaughey</Cast>
<Description>Action</Description>
<Rating>12</Rating>
<Cost>8.99</Cost>
<Copies>20</Copies>
<Rental>0</Rental>
<Image>sahara.jpeg</Image>
</DVD>
<DVD>
<DVDTitle>Constantine</DVDTitle>
<Director>Francis Lawrence</Director>
<Cast>Keanu Reaves</Cast>
<Description>Horror</Description>
<Rating>15</Rating>
<Cost>5.99</Cost>
<Copies>20</Copies>
<Rental>0</Rental>
<Image>Constantine.jpeg</Image>
</DVD>
</DVDInfo>

He needs a way to update the file so he can add other DVD's into the
file from a form in vb

He has a Textbox input for each node from DVD title through to Image
and a button on the form.

I had thought of using the XMLreader and XMLWriter within VB but don't
know how to go about it.

Can someone help?

thanks guys,

Cerebrus

unread,
Apr 12, 2008, 10:21:59 AM4/12/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting

Andrew Badera

unread,
Apr 12, 2008, 10:45:30 AM4/12/08
to DotNetDe...@googlegroups.com
"My" "friend" took a "class" once where "he" needed "help" on "his" "homework."
--
--Andy Badera
http://andrew.badera.us/ http://flipbitsnotburgers.blogspot.com/
and...@badera.us
(518) 641-1280
Google me: http://www.google.com/search?q=andrew+badera

CK

unread,
Apr 12, 2008, 10:46:31 AM4/12/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
You've got 2 easy options.

1 - Create an object oriented system where each DVD element is an
object with Title, Director, Cost etc. as properties. You can then
store these in some kind of collection and create a new one from your
form data to add to the collection. Then when you need the xml, you
can serialize your collection.

2 - Open the document as an XmlDocument and use the xml namespace to
create new elements and add them. e.g:
(Please forgice any syntax errors, I'm a C# guy and am writing from an
old memory of doing this)

Dim dvdxml As XmlDocument = XmlDocument.Open(filepath)
Dim newDvd as XmlNode
newDvd = XmlDocument.CreateElement()
etc.

Cerebrus

unread,
Apr 13, 2008, 9:46:23 AM4/13/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Personally, I wouldn't even consider any other option other than the
first... of course fine tuning it to the requirement. ;-)

RustyFuture

unread,
Apr 13, 2008, 2:12:16 PM4/13/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Thanks guys, I've got it working now using the XMLdocument by CK.

Andrew Badera

unread,
Apr 14, 2008, 12:43:14 PM4/14/08
to DotNetDe...@googlegroups.com
So wait, "you've" got it working or "your friend" got i working?

Next time, don't be a lying asshat. Kthxbai.
Reply all
Reply to author
Forward
0 new messages