I am currently reading a stream like this:
wc = New System.Net.WebClient()
strm = wc.OpenRead(url)
Data.ReadXml(strm, XmlReadMode.InferSchema)
strm.Close()
Besides the Dataset reading the stream I would also like to be able to output the text to the log file. Or for testing to a debug.print statement.
How can I do that? I have tried adding a new stream reader after the wc.openread but then there is no data for the dataset to read.
Any help would be appreciated..
Rick
after the
Data.ReadXml(strm, XmlReadMode.InferSchema)
call the Data.GetXml
Dim xmlString As String = Data.GetXml
Sample below,
Dim Data As New DataSet
Using wc = New System.Net.WebClient()
Using strm = wc.OpenRead("http://news.yahoo.com/rss/entertainment")
Data.ReadXml(strm, XmlReadMode.InferSchema)
Dim xmlString As String = Data.GetXml
Debug.WriteLine(xmlString)
End Using
End Using
Related
I want to use an XML-File for my Dataset to save changes.
datatable.ReadXml("C:\test.xml")
works fine. But I want to use an Xml Resource file. So I tried
Dim xmlDoc as String
xmlDoc = MyApplication.My.Resources.xmlTestFile
datatable.ReadXml(xmlDoc)
gives me the error Illigal sign in path and debugging shows me that xmlDoc is empty.
Could anyone help me get this working?
ReadXml requires a filename not content
use
Dim ds As New DataSet()
Using stringReader As New StringReader(.......RESOURCE.HERE.......)
ds = New DataSet()
ds.ReadXml(stringReader)
End Using
Dim dt As DataTable = ds.Tables(0)
I have a some data in SQL Server in a VARBINARY column, I just want to know how to display it into a PictureBox in VB.NET. How to do this?
Binary data looks something like:
0x1F8B0800000000000400EDBD07601C499625262F6DCA7B7F4AF54AD7E.....(and a great many more bytes to come)......
Private Sub sample()
Dim command, commandReader As New NpgsqlCommand
command.Connection = GetConnection()
command.CommandText = "select imgField from imgtable"
Dim productImageByte As Byte() = TryCast(command.ExecuteScalar, Byte())
If productImageByte IsNot Nothing Then
Using productImageStream As Stream = New System.IO.MemoryStream(productImageByte)
PPicBoxPhoto.Image = Image.FromStream(productImageStream)
End Using
End If
End Sub
NOTE : This a sample of my code that I'm using for my requirement, using PostgreSQL database and the image data type is bytea
I am writing code where I am trying to grab the HTML from a DNS report online (http://viewdns.info/dnsreport/?domain=google.com), but I am having some issues. The one line of the HTML file (Line 231) that I actually need is cutting itself off after around 680 characters. All of the lines after the important one are reading correctly, however. The code for grabbing the HTML is shown below, and I have tried it in two separate ways.
This is the first way I tried:
Public Function getWebResourceData(ByVal strURL As String) As String
Dim webClient As New System.Net.WebClient
Dim result As String = webClient.DownloadString("http://viewdns.info/dnsreport/?" & TextBox1.Text)
return result
End Function
And this is the second:
Public Function getWebResourceData(ByVal strURL As String) As String
Dim rt As String = ""
Dim wRequest As WebRequest
Dim wResponse As WebResponse
Dim SR As StreamReader
wRequest = WebRequest.Create(strURL)
wResponse = wRequest.GetResponse
SR = New StreamReader(wResponse.GetResponseStream)
rt = SR.ReadToEnd
SR.Close()
return rt
End Function
Im really not sure what else could be wrong at this point. I have also tried saving the result to a text file to see if that was the issue, but that was incorrect as well. I have looked into the hex codes for the area where the string is stopping, but there isn't anything out of the ordinary. The split occurs between the back to back alligator brackets (shown as parentheses) here: (/tr)(tr)
But there are numerous sets of these tags throughout the HTML that there are no issues with.
Both of your functions don't return what they have read. I have tested the second one and it works correctly.
Sub Main
Dim ret = getWebResourceData("http://viewdns.info/dnsreport/?domain=google.com")
Console.WriteLine(ret.Length)
' Output = 21605
End Sub
Public Function getWebResourceData(ByVal strURL As String) As String
Dim rt As String = ""
Dim wRequest As WebRequest
Dim wResponse As WebResponse
Dim SR As StreamReader
wRequest = WebRequest.Create(strURL)
wResponse = wRequest.GetResponse
SR = New StreamReader(wResponse.GetResponseStream)
rt = SR.ReadToEnd
SR.Close()
return rt
End Function
I have a function which reads a string to an XMLDocument.
I wish to then output the XML in that document to the screen.
Dim L As String = P.ToString()
Dim xmlDoc As XmlDocument = New XmlDocument()
xmlDoc.LoadXml(L)
Context.Response.Write(xmlDoc)
the above does not work, I have also tried using
Return(xmlDoc)
with no success. How should I perform this function? Should I not be using XMLDocument?
One of the possible ways is to use a StringWriter:
Using stringWriter = New StringWriter()
Using xmlTextWriter = XmlWriter.Create(stringWriter)
xmlDoc.WriteTo(xmlTextWriter)
xmlTextWriter.Flush()
result = stringWriter.GetStringBuilder().ToString()
End Using
End Using
On the example above, your XML will be stored into the result variable.
The C# equivalent code may be found on this thread.
StringWriter stringWriter = new StringWriter();
XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);
document.WriteTo(xmlTextWriter);
Console.WriteLine(stringWriter.ToString());
Console.Read();
Ok so I got my little chunck of code that goes out and brings back xml from google for my location after i send it the lat and long. What I now need to be able to do is just get one line out of it.
From the second result set I need to get formatted_address.
Never done any xml parsing in vb.net so I am way lost.
Dim webClient As New System.Net.WebClient
Dim result As String = webClient.DownloadString("http://maps.googleapis.com/maps/api/geocode/xml?latlng=44.46944050638752,-88.08779155546756&sensor=false")
Return result
After that I am lost!
In case anyone needs to know. I figured it out. Here is what i did:
Dim myAddress As String = "Nothing"
Dim webClient As New System.Net.WebClient
Dim result As String = webClient.DownloadString("http://maps.googleapis.com/maps/api/geocode/xml?latlng=lat,long&sensor=false")
Dim xmlDoc As New XmlDocument()
xmlDoc.LoadXml(result)
Dim m_nodelist As XmlNodeList
m_nodelist = xmlDoc.SelectNodes("/GeocodeResponse/result/formatted_address")
myAddress = m_nodelist(1).InnerText
result = myAddress