Solved

XPath question

Posted on 2013-01-18
3
491 Views
Last Modified: 2013-02-05
Hello again EE, I have little questions for vb.net

First,
lets say I have this:

<div class="Main">
   <td class="Event">
      <a href="abc" title="hello"></a>
      <a href="ggg" title="hi"></a>
    </td>
</div>

with xpath.. how can i get href and title of all tag <a> that is preceded only by a TD with class names="Event" ?  in this example, i would only get the first <a> not the second one..



Question two:
lets say I wan to search for a string in a HTML source that is not in any tag.. its juste a text between tags like:   <td><a href="dddd"></a><br />200 items left</td>

is there a way to get it ?

thanks for the help.
0
Comment
Question by:PhilippeRenaud
  • 2
3 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
1) Try:

Dim anchors As XmlNodeList = xdoc.SelectNodes("//td[@class='Event']/a[1]")

For Each anchor As XmlNode In anchors
    Dim href As String = anchor.Attributes("href").Value
    Dim title As String = anchor.Attributes("title").Value
Next

Open in new window


2) I assume you are talking about the "200 items left" bit. That is actually a part of the <td> tag. Nevertheless, you might be able to use:

For Each td As XmlNode In xdoc.SelectNodes("//td")
    Dim text As String = td.InnerText
Next

Open in new window

0
 
LVL 1

Author Closing Comment

by:PhilippeRenaud
Comment Utility
thanks
0
 
LVL 1

Author Comment

by:PhilippeRenaud
Comment Utility
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now