|
-
Apr 13th, 2008, 04:14 AM
#1
Thread Starter
New Member
[RESOLVED] [2005] Another XML Query
Hi Guys,
I have an XML file
Code:
<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>
I need a way to search the XML file for a DVDTitle the title I want it to find is held within a textbox, and ammend the <copies> +1 and <rental> -1 nods when I click on a button .
Heres the vb code I've got so far, the code was ammended from nmadd's thread
http://www.vbforums.com/showthread.php?t=478692
The vb code I have is the following:
Code:
Dim xd As New XmlDocumen
Dim nod As XmlNode = xd.SelectSingleNode("/DVDInfo/DVD/DVDTitle"(Me.DVD_Title.text))
xd.Load("C:\Documents and Settings\Huw Friedhoff\Desktop\Project Interface9\Project interface\DVD.xml")
If Me.CopiesTextBlock.Text = "0" Then
MessageBox.Show("No copies available for Rent")
ElseIf nod IsNot Nothing Then
nod.ChildNodes(5).InnerText = nod.ChildNodes(5).Innertext - 1
nod.Childnodes(6).InnerText = nod.ChildNodes(6).Innertext + 1
Else
Messagebox.show("Could not find the DVD you requested")
End If
xd.Save("C:\Documents and Settings\Huw Friedhoff\Desktop\Project Interface9\Project interface\DVD.xml")
MessageBox.Show("Changes have been made to the file")
I dont know how to tell to get the dvd title from the textbox, the current line I have is
Code:
Dim nod As XmlNode = xd.SelectSingleNode("/DVDInfo/DVD/DVDTitle"(Me.DVD_Title.text))
Any help would be appriciated,
Rusty.
Last edited by Rustyfuture; Apr 13th, 2008 at 05:17 AM.
-
Apr 13th, 2008, 04:29 AM
#2
Re: [2005] Another XML Query
Once again, load it into an XMLDocument. Then, .SelectSingleNode("/DVDInfo/DVD[DVDTitle/text() = 'The Matrix']/Rental")
That gives you the Rental node. Work from there.
-
Apr 13th, 2008, 05:13 AM
#3
Thread Starter
New Member
Re: [2005] Another XML Query
 Originally Posted by mendhak
Once again, load it into an XMLDocument. Then, .SelectSingleNode("/DVDInfo/DVD[DVDTitle/text() = 'The Matrix']/Rental")
That gives you the Rental node. Work from there.
Thanks for your help mendhak, but I still don't understand how to tell it to take the text from the texbox and match that to the name of the DVD.
the only way I could think of doing it was
Code:
Dim nod As XmlNode = xd.SelectSingleNode("/DVDInfo/DVD/DVDTitle" = Me.txttitle.Text)
but the error message I put in kicks in to say it can't find the dvd.
-
Apr 13th, 2008, 05:26 AM
#4
Re: [2005] Another XML Query
You'd substitute the hardcoded bit with your textbox value.
.SelectSingleNode("/DVDInfo/DVD[DVDTitle/text() = '" & txttitle.Text &"']/Rental")
-
Apr 13th, 2008, 06:03 AM
#5
Thread Starter
New Member
Re: [2005] Another XML Query
Thanks very much for your help mendhak.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|