Home All Groups Group Topic Archive Search About

Loading an XML Document?

Author
20 May 2009 6:56 PM
Andrew Raastad
Got a strange one here.... I am trying to load an XML document into memory
in order to do stuff.  Not a big deal, done it before, and it has always
been pretty straight forward.... except this time it is weirding out on me.

I have a load method which takes as an argument the web url of the document,
then loads the info of the XML document into a DataTable for later use:

        Private Sub LoadComponents(ByVal WebURL As String)
            Dim xmlDom As New Xml.XmlDocument
            Dim MainNode As Xml.XmlNode

            Try
                xmlDom.Load(WebURL)
                MainNode = xmlDom.SelectSingleNode("xml")
                For Each ComponentNode As Xml.XmlNode In MainNode.ChildNodes
                    With _ComponentsDT
                        Dim dr As DataRow = _ComponentsDT.NewRow
                        dr("Source") =
ComponentNode.SelectSingleNode("source").FirstChild.Value
                        dr("Description") =
ComponentNode.SelectSingleNode("description").FirstChild.Value
                        dr("Register") =
CType(ComponentNode.SelectSingleNode("register").FirstChild.Value, Boolean)
                        dr("SaveTo") =
ComponentNode.SelectSingleNode("saveto").FirstChild.Value
                        dr("FileName") =
ComponentNode.SelectSingleNode("filename").FirstChild.Value
                        dr("FileVersion") =
ComponentNode.SelectSingleNode("filever").FirstChild.Value
                        _ComponentsDT.Rows.Add(dr)
                    End With
                Next

            Catch ex As Exception
                Throw New Exception("Components:LoadComponents() Failed:" &
vbCrLf & ex.ToString)

            End Try
        End Sub

The "WbeURL" value is something like:
"http://pminstaller/_mnpstatic/html/components.xml".  If I manually open a
browser to this location I get the XML no problem.  However, when the app
runs, it errors out on the xmlDom.Load() statement with the error:

"Syetem.IO.DirectoryNotFoundException: Could not find a part of the path
'C:\Documents and Settings\andrewr\Local
Settings\Apps\2.0\1KRLVKPP.ZQ3\791GDX2R.D1Q\npws..tion_aaa3415bf7745aed_0001.0001_d8b10cd45618a9f3\http\pminstaller\_mnpstatic\html\components.xml'."

Where the hell did this come from??  I passed in a web URL and the very next
line it is trying to open something from the local file system.  You can see
the Web URL in the error there at the end, but I have verified that this is
NOT what is being passed in but rather the URL.

Help??

-- Andrew

Author
20 May 2009 9:33 PM
Mike
Andrew Raastad wrote:
Show quoteHide quote
>
> The "WbeURL" value is something like:
> "http://pminstaller/_mnpstatic/html/components.xml".  If I manually open
> a browser to this location I get the XML no problem.  However, when the
> app runs, it errors out on the xmlDom.Load() statement with the error:
>
> "Syetem.IO.DirectoryNotFoundException: Could not find a part of the path
> 'C:\Documents and Settings\andrewr\Local
> Settings\Apps\2.0\1KRLVKPP.ZQ3\791GDX2R.D1Q\npws..tion_aaa3415bf7745aed_0001.0001_d8b10cd45618a9f3\http\pminstaller\_mnpstatic\html\components.xml'."
>
>
> Where the hell did this come from??  I passed in a web URL and the very
> next line it is trying to open something from the local file system. 
> You can see the Web URL in the error there at the end, but I have
> verified that this is NOT what is being passed in but rather the URL.

See if the XmlDocument.Load() method documented remark here means
anything to you:

http://msdn.microsoft.com/en-us/library/system.io.directorynotfoundexception.aspx

Btw, if this is a server side request there is extra security here, so
    it may be related to the exception.

--
Author
21 May 2009 2:12 PM
Cowboy (Gregory A. Beamer)
It is your attempting to load by URL rather than file path or UNC that is
causing it. When the method cannot find the file in question, it attempts to
find it in the directory path for the application's user's information. That
is why you see the local directory call.

If you want to read off a URL, you are best served by invoking the NET
libraries and pulling the file that way. You can then load the XML file from
a MemoryStream of the document. In addition to "fixing" the issue, this will
also give you the ability to fully instrument the pull and ensure there is a
doc before you start trying to work on it.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Blog: http://gregorybeamer.spaces.live.com
Twitter: @gbworld

*************************************************
Show quoteHide quote
|   Think outside the box!                              |
*************************************************


"Andrew Raastad" <notgi***@email.com> wrote in message
news:205C8CB8-FBB8-46CA-B221-56147A67900C@microsoft.com...
> Got a strange one here.... I am trying to load an XML document into memory
> in order to do stuff.  Not a big deal, done it before, and it has always
> been pretty straight forward.... except this time it is weirding out on
> me.
>
> I have a load method which takes as an argument the web url of the
> document, then loads the info of the XML document into a DataTable for
> later use:
>
>        Private Sub LoadComponents(ByVal WebURL As String)
>            Dim xmlDom As New Xml.XmlDocument
>            Dim MainNode As Xml.XmlNode
>
>            Try
>                xmlDom.Load(WebURL)
>                MainNode = xmlDom.SelectSingleNode("xml")
>                For Each ComponentNode As Xml.XmlNode In
> MainNode.ChildNodes
>                    With _ComponentsDT
>                        Dim dr As DataRow = _ComponentsDT.NewRow
>                        dr("Source") =
> ComponentNode.SelectSingleNode("source").FirstChild.Value
>                        dr("Description") =
> ComponentNode.SelectSingleNode("description").FirstChild.Value
>                        dr("Register") =
> CType(ComponentNode.SelectSingleNode("register").FirstChild.Value,
> Boolean)
>                        dr("SaveTo") =
> ComponentNode.SelectSingleNode("saveto").FirstChild.Value
>                        dr("FileName") =
> ComponentNode.SelectSingleNode("filename").FirstChild.Value
>                        dr("FileVersion") =
> ComponentNode.SelectSingleNode("filever").FirstChild.Value
>                        _ComponentsDT.Rows.Add(dr)
>                    End With
>                Next
>
>            Catch ex As Exception
>                Throw New Exception("Components:LoadComponents() Failed:" &
> vbCrLf & ex.ToString)
>
>            End Try
>        End Sub
>
> The "WbeURL" value is something like:
> "http://pminstaller/_mnpstatic/html/components.xml".  If I manually open a
> browser to this location I get the XML no problem.  However, when the app
> runs, it errors out on the xmlDom.Load() statement with the error:
>
> "Syetem.IO.DirectoryNotFoundException: Could not find a part of the path
> 'C:\Documents and Settings\andrewr\Local
> Settings\Apps\2.0\1KRLVKPP.ZQ3\791GDX2R.D1Q\npws..tion_aaa3415bf7745aed_0001.0001_d8b10cd45618a9f3\http\pminstaller\_mnpstatic\html\components.xml'."
>
> Where the hell did this come from??  I passed in a web URL and the very
> next line it is trying to open something from the local file system.  You
> can see the Web URL in the error there at the end, but I have verified
> that this is NOT what is being passed in but rather the URL.
>
> Help??
>
> -- Andrew
Author
21 May 2009 3:12 PM
Andrew Raastad
I am not too proud to admit when I have made a mistake... and this time I
chalk it up to going at the project too long without break or rest.  I found
the problem, and it was simply a missing character in the URL passed in.
When I came back and looked at it with fresh eyes this morning, I saw that
while it *looked* like the URL was being passed in, the actual value was:
"http//pminstaller/_mnpstatic/html/components.xml"  Notice the missing ":"?
I didn't.  And as such the code was interpreting this as a UNC path, and
finding nothing matching, it blew up.  Just goes to show that Mt Dew, Pizza,
energy drinks, etc. is no substitute for sleep.  Regardless, thanks to all
who offered help.

-- Andrew


Show quoteHide quote
"Andrew Raastad" <notgi***@email.com> wrote in message
news:205C8CB8-FBB8-46CA-B221-56147A67900C@microsoft.com...
> Got a strange one here.... I am trying to load an XML document into memory
> in order to do stuff.  Not a big deal, done it before, and it has always
> been pretty straight forward.... except this time it is weirding out on
> me.
>
> I have a load method which takes as an argument the web url of the
> document, then loads the info of the XML document into a DataTable for
> later use:
>
>        Private Sub LoadComponents(ByVal WebURL As String)
>            Dim xmlDom As New Xml.XmlDocument
>            Dim MainNode As Xml.XmlNode
>
>            Try
>                xmlDom.Load(WebURL)
>                MainNode = xmlDom.SelectSingleNode("xml")
>                For Each ComponentNode As Xml.XmlNode In
> MainNode.ChildNodes
>                    With _ComponentsDT
>                        Dim dr As DataRow = _ComponentsDT.NewRow
>                        dr("Source") =
> ComponentNode.SelectSingleNode("source").FirstChild.Value
>                        dr("Description") =
> ComponentNode.SelectSingleNode("description").FirstChild.Value
>                        dr("Register") =
> CType(ComponentNode.SelectSingleNode("register").FirstChild.Value,
> Boolean)
>                        dr("SaveTo") =
> ComponentNode.SelectSingleNode("saveto").FirstChild.Value
>                        dr("FileName") =
> ComponentNode.SelectSingleNode("filename").FirstChild.Value
>                        dr("FileVersion") =
> ComponentNode.SelectSingleNode("filever").FirstChild.Value
>                        _ComponentsDT.Rows.Add(dr)
>                    End With
>                Next
>
>            Catch ex As Exception
>                Throw New Exception("Components:LoadComponents() Failed:" &
> vbCrLf & ex.ToString)
>
>            End Try
>        End Sub
>
> The "WbeURL" value is something like:
> "http://pminstaller/_mnpstatic/html/components.xml".  If I manually open a
> browser to this location I get the XML no problem.  However, when the app
> runs, it errors out on the xmlDom.Load() statement with the error:
>
> "Syetem.IO.DirectoryNotFoundException: Could not find a part of the path
> 'C:\Documents and Settings\andrewr\Local
> Settings\Apps\2.0\1KRLVKPP.ZQ3\791GDX2R.D1Q\npws..tion_aaa3415bf7745aed_0001.0001_d8b10cd45618a9f3\http\pminstaller\_mnpstatic\html\components.xml'."
>
> Where the hell did this come from??  I passed in a web URL and the very
> next line it is trying to open something from the local file system.  You
> can see the Web URL in the error there at the end, but I have verified
> that this is NOT what is being passed in but rather the URL.
>
> Help??
>
> -- Andrew