I need some help edit a simple tool, that read a xml file from local pc.
I need to make it able to read xml from web instead of local pc, until I get error.
Can anyone give me an hint if I send project?
Oct 28, 2017 01:06 PM
(This post was last modified: Oct 28, 2017 01:06 PM by Barret.)
(Oct 28, 2017 11:37 AM)aGFjaw-- Wrote: I need some help edit a simple tool, that read a xml file from local pc.
I need to make it able to read xml from web instead of local pc, until I get error.
Can anyone give me an hint if I send project?
uri class in .net works only if http://, https:// or file:// is used on the beginning of an address.
Oct 28, 2017 01:37 PM
(This post was last modified: Oct 28, 2017 01:37 PM by aGFjaw--.)
Sure, but there should be an error somewhere.
Little screenshoot under spoiler.
![[Image: xml-error.png]](https://s1.postimg.org/1f3f0valfj/xml-error.png)
(Oct 28, 2017 11:37 AM)aGFjaw-- Wrote: I need some help edit a simple tool, that read a xml file from local pc.
I need to make it able to read xml from web instead of local pc, until I get error.
Can anyone give me an hint if I send project?
Can you share that link of that xml web or any code ?? 😅 😅 😅
If I an not mistaken, you will need to create a stream that fetches the XML file from a specific URL.
Example Code:
Code Dim URLString As [String] = " http://localhost/books.xml"
Dim reader As New XmlTextReader(URLString)
Oct 28, 2017 05:06 PM
(This post was last modified: Oct 28, 2017 05:06 PM by Rhez.)
(Oct 28, 2017 01:37 PM)aGFjaw-- Wrote: Sure, but there should be an error somewhere.
Little screenshoot under spoiler.
![[Image: xml-error.png]](https://s1.#.org/1f3f0valfj/xml-error.png)
Maybe because you have an empty variable?
On your button mnuOpen, you need to browse first for nothing before the variable "Filename" get the data.
Here is full code.
Code Imports System.Xml
Imports System.Text
Imports System.IO
Public Class MainForm
Dim mFileName As String = String.Empty
Dim mDocument As XmlDocument = Nothing
Private Sub mnuOpen_Click(sender As System.Object, e As System.EventArgs) Handles mnuOpen.Click
If OpenDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
'FileName = OpenDialog.FileName
FileName = "http://vb.net-informations.com/xml/img/product.xml"
LoadFile()
End If
End Sub
Private Sub LoadFile()
If mDocument Is Nothing Then
mDocument = New XmlDocument
End If
Dim Content As String = File.ReadAllText(FileName, Encoding.Default)
mDocument.LoadXml(Content)
rtbXmlSource.Text = Content
trvNodes.Nodes.Clear()
FillTreeView(trvNodes.Nodes, mDocument.DocumentElement)
End Sub
Private Sub FillTreeView(TreeNodes As TreeNodeCollection, Xml_Node As XmlNode)
Dim NewNode = TreeNodes.Add(Xml_Node.Name)
NewNode.Tag = Xml_Node
For Each Node As XmlNode In Xml_Node.ChildNodes
FillTreeView(NewNode.Nodes, Node)
Next
trvNodes.ExpandAll()
End Sub
Private Property FileName As String
Get
Return mFileName
End Get
Set(value As String)
lblFileName.Text = value
mFileName = value
End Set
End Property
Private Sub trvNodes_AfterSelect(sender As System.Object, e As System.Windows.Forms.TreeViewEventArgs) Handles trvNodes.AfterSelect
If trvNodes.SelectedNode IsNot Nothing Then
PropertyGrid1.SelectedObject = trvNodes.SelectedNode.Tag
End If
End Sub
End Class
Its a good idea to download that file in Temp folder and then read it from XmlReader and on
OnFormClosingEvent delete that xml file from Temp directory.
Yes, I thought to do so, but I would like to read it directly from the web.
if you can share that link then i will create and upload the project.
Oct 29, 2017 01:55 AM
(This post was last modified: Oct 29, 2017 01:56 AM by aGFjaw--.)
Thanks for releasing it to us
Oct 29, 2017 10:17 AM
(This post was last modified: Oct 29, 2017 10:18 AM by CoderEX.)
You would replace the OpenFileDialog code with the code I provided up top. You need to create a stream that requests/reads the file from a specific URL.
Already tried but it does not work.
I also tried with WebClient.
There should be more stuffs to edit, something I don't understand.
(Oct 29, 2017 11:34 AM)aGFjaw-- Wrote: Already tried but it does not work.
I also tried with WebClient.
There should be more stuffs to edit, something I don't understand.
What does your current code look like? I looked at the last code you posted, and it seems like you are still using OpenFileDialog.
|