|
Hi all,
I'm trying to use an XPath query on an HTML page, but XPathDocument throws an error and will not continue. The code I am using at the moment is this:
Dim doc As XPathDocument
Dim nav As XPathNavigator
Dim elems As XPathNodeIterator
Dim req As WebRequest = WebRequest.Create("http://www.geocaching.com/seek/cache_details.aspx?guid=e77eaad6-4a01-4c14-827f-808e9d771270")
Dim response As HttpWebResponse = CType(req.GetResponse(), HttpWebResponse)
'Create an XPathDocument from the stream
doc = New XPathDocument(response.GetResponseStream) '<<<<<<----- Error raised on this line
'Create the navigator
nav = doc.CreateNavigator
'Grab something using XPath
elems = nav.Select("id('CacheName')")
The error message I'm given is "'if' is an unexpected token. The expected token is 'CDATA['. Line 13, position 8." as an XmlException. I assume that this is due to invalid HTML, as the code works fine for other URLs.
Any ideas how to get this to work?
Thanks very much in advance.
|
|
|
|
|
Member 4369916 wrote: I'm trying to use an XPath query on an HTML page,
Using the standard XPathNavigator in the .NET Framework, that's not going to work. HTML, though it resembles XML, is not XML. There's too much flexibility allowed in HTML that is totally unacceptable in an XML document, as you've found out.
You'd have to derive your own XPathNavigator class to handle HTML, in which you'd have to provide code for some 20+ methods to get this to work. You can find an example of this here[^].
|
|
|
|
|
Of course, HTML isn't XML unless it's XHTML! Thanks for the link, I think writing my own class to parse the HTML is a bit beyond me but the class on zverovich.net looks pretty good.
Thanks very much for your help!
|
|
|
|
|
Hello
I need to create a save function which saves the changes done to my application at runtime, so it can be openned later. Does anyone have an idea?
Thank You
|
|
|
|
|
|
I have two forms form1 and form 2.
Form1 is added as a control to form 2.
There is a listbox (listbox1) on form2 that i want update from form1 but I am unable to this.Actually i am unable to update anything on the main form from the embedded form.
I typed this in form1,
"form2.listbox1.items.add"
but it isn't working.Please advise
|
|
|
|
|
I would think you would have to use events to trigger changes to a parent form...
|
|
|
|
|
ok....how would the code look like for such an event?
I tried this snippet which i found online but it didnt work
I am quite new to this so i dont know exactly what it does
In child form...
Public Class
Public Event addtolist as EventHandler
'
Private sub()
'
' some code
'
'
RaiseEvent addtolist 'where i want to add to the listbox in parent form
'
'
End Sub
End Class
But I don't know what to do after this.Where do I add the code to add text to the listbox in parent form?
|
|
|
|
|
In your parent class you have to subscribe or handle that event and then trigger whatever you want done. Good use of research, you're making great progress.
|
|
|
|
|
Ok...but how would i handle or subscribe to that event from the child class?
Do i create a sub in the parent class with the same name as the event?
|
|
|
|
|
check this[^], this[^], and this[^].
Specifically do research on the handles[^] keyword. You are throwing an event, you need to handle it.
Best of luck you're almost there.
|
|
|
|
|
Youve got it backwards. You expose the event in the child form, then subscribe to it in the parent form. Look up AddHandler and RemoveHandler to subscribe and unsubscribe to events of objects.
|
|
|
|
|
Yep, sorry I missed over that, those links will still help you out (to the OP)
|
|
|
|
|
ok..so should it be something like this
in child class..
In child form...
Public Class1
Public Event addtolist (Byval s as string) '' s is what is to printed in the listbox in parent class
'
Private sub()
dim obj as new class1
addhandler obj.addtolist,address of class2.addtolistbox
' some code
'
'
RaiseEvent addtolist(s) 'where i want to add to the listbox in parent form
'
'
End Sub
End Class1
In parent form.....
public class2
public sub addtolistbox(ByVal sender As Object, _
ByVal e As System.EventArgs)
listbox1.items.add(e.argument)
end sub
end class2
Is this how what you mean Dave?
EliottA,thanks for the comments and links.they were useful
|
|
|
|
|
OK, last time...
The CHILD form exposes the public Event and calls RaiseEvent when it needs a subscriber to know of a change. This much you got right. The child form does NOT use AddHandler and RemoveHandler on it's own events because it's not subscribing to itself.
The PARENT form needs to call AddHandler to subscribe to the events exposed by the child form. But, it can only do this if the parent form has a method that matches the header exposed by the event AND has an child form object (an instance of a class is called an "object"). So, after your parent form creates a child form object, it calls AddHandler to wire up the event exposed by the child form object to the method in the parent form that handles the event.
|
|
|
|
|
|
Thanks for description dave..
ok..so should it be something like this..i am sorry I havent tried it yet because visual studio is on my other laptop that I dont have with me right now..so just doing some research on it..I'll try it as soon as i get have it.
In child form...
Public Class1
Public Event addtolist (Byval s as string) '' s is what is to printed in the listbox in parent class
'
Private sub()
' some code
'
'
RaiseEvent addtolist(s) 'where i want to add to the listbox in parent form
'
'
End Sub
End Class1
In parent form.....
public class2
public obj as new class1
addhandler obj.addtolist,addressof addtolistbox
public sub addtolistbox(ByVal sender As Object, _
ByVal e As System.EventArgs)
listbox1.items.add(e.argument)
end sub
end class2
Just one thing i didn't get..sorry to bother you..
"it can only do this if the parent form has a method that matches the header exposed by the event",I don't know what you meant by this.
Do you mean the method in the parent form that handles the event should have the same name as the event ie; 'addtolist'?
|
|
|
|
|
Yeah, pretty much got it. Except for one thing:
public sub addtolistbox(ByVal sender As Object, _
ByVal e As System.EventArgs)
This is wrong. Like I said, the method signatures have to match. So, you event is defined like this:
Public Event addtolist(ByVal s as string)
so your event handler has to look the same:
Private Sub AddToListbox(ByVal str As String)
You don't have to have the same variable names, just the same types in the same order.
|
|
|
|
|
i tried it the way you said but it isn't working.
In the parent form, I created on object of the child form and put the AddHandler syntax in the form load sub.
|
|
|
|
|
What do you mean "it isnt' working"? What IS happening? Have you steped through the code using the debugger to see where it's going and what it's doing??
|
|
|
|
|
Yes I have done it..when it reaches the RaiseEvent it doesn't go the event handler..it just goes to the next line.
|
|
|
|
|
That would probably be because there is nothing subscribed to the event.
|
|
|
|
|
well I have done exactly as you said.
This is in the parent form,I have added this in the form load event of the parent form
Dim obj1 As New childform
AddHandler obj1.addtolist, AddressOf addtolistbox
and this is sub that is subscribed to the event..
Private Sub addtolistbox(ByVal str As String)
ListBox1.Items.Add(str)
End Sub
In the child form....
Public Event addtolist(ByVal s As String)
and in the sub where I want to add to listbox in parent form,
RaiseEvent addtolist(ds1.Tables(0).Rows(0)("Reader_location").ToString & " Connected ")
|
|
|
|
|
salam sir;
how can made login form in vb6 and vb.net?please send me coding
thanks sir
mohammedali
|
|
|
|
|
1. Cross post
2. We don't do your work for you
3. This can easily be found on the internet.
Blog link to be reinstated at a later date.
|
|
|
|