[RESOLVED][2005] Getting data between <player> tags
Hello,
I was just wondering if you could help me extract & format data between <player> tags (obviously a css-assosiated tag), i'm working on a website for my guild on WAR and the player data is posted on a community site like so:
Code:
<player>
<div>name</div>
<div>level</div>
<div>rlevel</div>
<div>guild</div>
<div>rank</div>
</player>
There are also assosiated players that i'd also like to extract, the html is formatted exactly the same, it's just lower down the page.
I was wondering how i'd go about formatting it like so:
Player1 name, Level, Plevel, Guild, Rank
Player2 name, Level, Plevel, Guild, Rank
Any help is appreciated,
Thanks
Re: [2005] Getting data between <player> tags
try this:
vb Code:
Dim xmlDoc As New Xml.XmlDocument
Dim xmlRoot As Xml.XmlNode
xmlDoc.LoadXml("<player>" & Environment.NewLine & _
"<div>name</div>" & Environment.NewLine & _
"<div>level</div>" & Environment.NewLine & _
"<div>rlevel</div>" & Environment.NewLine & _
"<div>guild</div>" & Environment.NewLine & _
"<div>rank</div>" & Environment.NewLine & _
"</player>")
xmlRoot = xmlDoc.DocumentElement
Dim nodes As XmlNodeList = xmlRoot.SelectNodes("div")
Dim msg As String = String.Empty
For Each node As XmlNode In nodes
msg &= node.InnerText & ","
Next
msg = msg.Remove(msg.Length - 1, 1)
MsgBox(msg)
Re: [2005] Getting data between <player> tags
Thanks but theres more html around it i was trying to ignore so i'm trying to copy and paste it into a textbox and then process it, i just get a divide by zero error when i try to replace:
xmlDoc.LoadXml("<player>" & Environment.NewLine & _
"<div>name</div>" & Environment.NewLine & _
"<div>level</div>" & Environment.NewLine & _
"<div>rlevel</div>" & Environment.NewLine & _
"<div>guild</div>" & Environment.NewLine & _
"<div>rank</div>" & Environment.NewLine & _
"</player>")
with:
xmlDoc.LoadXml(textbox1.text)
1 Attachment(s)
Re: [2005] Getting data between <player> tags
i tried it with a textbox. worked ok.
edit: ignore the buttons. i tested it in my xml learning program
Re: [2005] Getting data between <player> tags
try with:
Code:
<html>
<title>test</title>
<head>
</head>
<player>
<div>name</div>
<div>level</div>
<div>rlevel</div>
<div>guild</div>
<div>rank</div>
</player>
</html>
I really appreciate the help. sorry if i didnt get the point accross that it's within html.
Re: [2005] Getting data between <player> tags
this works:
vb Code:
Dim xmlDoc As New Xml.XmlDocument
Dim xmlRoot As Xml.XmlNode
xmlDoc.LoadXml(TextBox1.Text)
xmlRoot = xmlDoc.DocumentElement
Dim nodes As XmlNodeList = xmlRoot.SelectNodes("player/div")
Dim msg As String = String.Empty
For Each node As XmlNode In nodes
msg &= node.InnerText & ","
Next
msg = msg.Remove(msg.Length - 1, 1)
MsgBox(msg)
Re: [2005] Getting data between <player> tags
if you want to post the whole html, i'll have a look at it
Re: [2005] Getting data between <player> tags
the 2nd part (1st part by PM) of the answer to your other question is:
vb Code:
Dim addressesAcquired As Boolean = False
Private Sub WebBrowser1_ProgressChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged
If Not addressesAcquired And e.CurrentProgress = e.MaximumProgress Then
Dim regAddress As String = String.Empty
Dim corrAddress As String = String.Empty
Dim rx As New Regex("(?<=<h2>Registered Address</h2>).+(?=</div><div class=""corrAddress"">)")
Dim xmlDoc As New Xml.XmlDocument
Dim xmlRoot As Xml.XmlNode
xmlDoc.LoadXml(rx.Match(WebBrowser1.DocumentText).Value)
xmlRoot = xmlDoc.DocumentElement
Dim nodes As Xml.XmlNodeList = xmlRoot.SelectNodes("div")
Dim msg As String = String.Empty
For Each node As Xml.XmlNode In nodes
msg &= node.InnerText & Environment.NewLine
Next
regAddress = msg & Environment.NewLine & Environment.NewLine
rx = New Regex("(?<=<h2>Correspondence Address</h2>).+(?=</div></div><hr /><h2>Associated Organisations</h2>)")
xmlDoc.LoadXml(rx.Match(WebBrowser1.DocumentText).Value)
xmlRoot = xmlDoc.DocumentElement
nodes = xmlRoot.SelectNodes("div")
msg = String.Empty
For Each node As Xml.XmlNode In nodes
msg &= node.InnerText & Environment.NewLine
Next
corrAddress = msg
rx = New Regex("(?<=<th class=""col1"">).+(?=</table><table class=""total"")")
Dim splitHTML As String = rx.Match(WebBrowser1.DocumentText).Value
splitHTML = splitHTML.Substring(splitHTML.IndexOf("<tr>"))
splitHTML = splitHTML.Replace("<tr>", "")
splitHTML = splitHTML.Replace("</tr>", "")
splitHTML = "<splitHTML>" & splitHTML & "</splitHTML>"
xmlDoc.LoadXml(splitHTML)
xmlRoot = xmlDoc.DocumentElement
nodes = xmlRoot.SelectNodes("td")
msg = CStr("Stock Type" & vbTab).PadRight(40) & "Owned" & vbTab & "Managed On Behalf of Others" & Environment.NewLine
Dim counter As Integer = 1
For Each node As Xml.XmlNode In nodes
If counter = 1 Then
msg &= CStr(node.InnerText & vbTab).PadRight(40)
counter += 1
ElseIf counter = 2 Then
msg &= node.InnerText & vbTab
counter += 1
Else
msg &= node.InnerText & Environment.NewLine
counter = 1
End If
Next
Debug.Print(regAddress & corrAddress & msg)
addressesAcquired = True
End If
End Sub