Solved

Processing an XML file from an HTTP source

Posted on 2008-10-03
7
157 Views
Last Modified: 2013-11-05
What changes need to be made to the following code (if it can be done) to replace XmlPath with a URL. Currently it calculates the application path.

This is a VB 2005 Windows Application.
Public Sub ReadXML()

        Dim XmlPath As String = String.Empty

        Dim XmlFile As String = AppConstants.XmlFileName

        Dim XmlDoc As New XmlDocument

        Dim XmlNode As XmlNode

        Dim XmlNodes As XmlNode
 

        XmlPath = System.IO.Path.GetDirectoryName( _

           System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
 

        If XmlPath.Substring(0, 6) = "file:\" Then XmlPath = XmlPath.Substring(6)
 

        Dim XmlFullPath As String = System.IO.Path.Combine(XmlPath, XmlFile)
 

        Dim ImportJob As ImportFile

        Dim SourcePath As String = String.Empty

        Dim DestinationPath As String = String.Empty
 

        Try

            XmlDoc.Load(XmlFullPath)

            For Each XmlNode In XmlDoc.DocumentElement.ChildNodes

                Select Case XmlNode.Name

                    Case "COPYJOB"

                        Dim JobClass As New ImportFile

                        For Each XmlNodes In XmlNode.ChildNodes

                            With JobClass

                                Select Case XmlNodes.Name

                                    Case "SOURCEDIRECTORY"

                                        SourcePath = XmlNodes.InnerText

                                        .SourcePath = XmlNodes.InnerText

                                    Case "DESTINATIONDIRECTORY"

                                        DestinationPath = XmlNodes.InnerText

                                        .DestinationPath = XmlNodes.InnerText

                                    Case "HEADERID"

                                        .HeaderID = XmlNodes.InnerText

                                    Case "IMPORTGROUP"

                                        .ImportGroup = XmlNodes.InnerText

                                    Case "FILEPATTERN"

                                        .FileName = XmlNodes.InnerText

                                    Case "INCLUDESUBDIRS"

                                End Select

                            End With

                        Next

                End Select

            Next

            Me.Show()
 

            ' Check for and process any existing files

            lblMessage.Text = AppConstants.MessageLabelProcessExistingFiles

            Me.Refresh()

            For Each ImportJob In ImportJobCollection

                ImportJob.ProcessExistingFiles()

            Next

            lblMessage.Text = String.Empty

            Me.Refresh()
 

        Catch ex As ApplicationException

            Select Case ex.Message

                Case AppConstants.SourcePathNotFound

                    MsgBox("The source directory " + SourcePath + " could not be located." _

                        + vbCrLf + vbCrLf + "The application is being shut down.", _

                        MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Critical Error")

                    Me.Close()

                Case AppConstants.DestinationPathNotFound

                    MsgBox("The destination directory " + DestinationPath + " could not be located." _

                        + vbCrLf + vbCrLf + "The application is being shut down.", _

                        MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Critical Error")

                    Me.Close()

            End Select

        Catch ex As System.IO.DirectoryNotFoundException

            MsgBox("The XML configuration file " + XmlFullPath + " could not be located." _

                + vbCrLf + vbCrLf + "The application is being shut down.", _

                MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Critical Error")

            Me.Close()

        Catch ex As System.IO.IOException

            MsgBox("The XML configuration file " + XmlFullPath + " could not be located." _

                + vbCrLf + vbCrLf + "The application is being shut down.", _

                MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Critical Error")

            Me.Close()

        Catch ex As Exception

            '            

        End Try

    End Sub

Open in new window

0
Comment
Question by:dbbishop
  • 4
  • 3
7 Comments
 
LVL 8

Expert Comment

by:rlh68
Comment Utility
Simply pass the url to the Load method, like so...
XmlDoc.Load("http://news.google.com/news?hl=en&um=1&tab=wn&q=&nolr=1&output=rss")
Note, I am using google's RSS feed in this example. This if fine since RSS is XML.
 
0
 
LVL 15

Author Comment

by:dbbishop
Comment Utility
Okay, clarification:
AppConstants.XmlFileName is a constant that contains the name of the XML File.

XmlPath is a string that will eventually contin the applications' folder path, thus an example youd be:
c:\Program Files\myApplication\

AppConstants.XmlFileName will remain the same and I wish to also make XmlPath a constant that points to an internal URL on our intranet.
Assuming the location on the Intranet is \\192.71.161.34\AppParms\EMIData\ and the file is parms.xml, what would the full URL look like?

The above example has other arguements (hl=, um=, tab=,nolr, output=) Are al required or (I assume) just the output= without the filetype (.xml).
0
 
LVL 8

Assisted Solution

by:rlh68
rlh68 earned 350 total points
Comment Utility
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 8

Expert Comment

by:rlh68
Comment Utility
And if you want to use your url paramters simply append them to your url, using a ? to deliminate between the url and the parameters, like so...
\\192.71.161.34\AppParms\EMIData\parms.xml?hl=,um=,tab=,nolr=,output=
Depending on how you code web server to process the parameters, some or all may be required.
0
 
LVL 15

Author Comment

by:dbbishop
Comment Utility
This is not a web app. It is a windows application written in VB 2005. We are getting ready to deploy it and I was asked if we could put the parms file in a single location accessible by all users. It is an internal application but not all users will have access to a common shared drive so I was wondering if we could put the parms file on one of our intranet servers and access it through the application. I have no web development experience.

If XmlDoc.Load("\\192.71.161.34\AppParms\EMIData\parms.xml")
will work exactly the same way as
XmlDoc.Load("C:\Program Files\myApplication\parms.xml")
then I am fine.

0
 
LVL 8

Accepted Solution

by:
rlh68 earned 350 total points
Comment Utility

Yes,
XmlDoc.Load(\\192.71.161.34\AppParms\EMIData\parms.xml)
will work as long as the users have access to the network share.

Sorry about mentioning the webserver, when I saw this line I got side tracked,
\\192.71.161.34\AppParms\EMIData\parms.xml?hl=,um=,tab=,nolr=,output=

FYI, if you needed to process parameters (unless it can be done with XML and XSLT) you would need to have a web server process the request. The web server would pick off the parameters, then choose an xml datasource (possibly based on the params) to return to the application. I know this is more than you need but I wanted to mention for future reference.
0
 
LVL 15

Author Closing Comment

by:dbbishop
Comment Utility
Thanks. The parameters were added to my reply only because they were in your original comment and I was wanting to know if they were something required as part of the load or just optional arguments. Your original example did not explicitly reference an XML file.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

10 Experts available now in Live!

Get 1:1 Help Now