Loading an XML Document?


A

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
 
Ad

Advertisements

M

Mike

Andrew said:
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.

--
 
M

Mike

Andrew said:
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.

--
 
C

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

*************************************************
| Think outside the box! |
*************************************************
 
C

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

*************************************************
| Think outside the box! |
*************************************************
 
A

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
 
Ad

Advertisements

A

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top