validate

  • Thread starter Thread starter MarkL
  • Start date Start date
M

MarkL

I'm trying to get an XML document from a local or remote resource by using:

//fromLocaton is a stream from either a local or remote resource.
XPathDocument xmlDocument = new XPathDocument(fromLocation);

Is there a way of determining that the fromLocation actually exists and
holds XML data before creating the XPathDocument?
 
Hello MarkL,
I'm trying to get an XML document from a local or remote resource by using:

//fromLocaton is a stream from either a local or remote resource.
XPathDocument xmlDocument = new XPathDocument(fromLocation);

Is there a way of determining that the fromLocation actually exists and
holds XML data before creating the XPathDocument?

Well... from your question I gather that you're using the constructor
overload that takes a stream object. If that is so, then no, you can't
figure out on this level whether the basic resource exists - of course,
the fact that a stream has already been constructed for the resource may
be an indicator that the resource exists, but you can't be totally sure of
that without knowing the details of the stream implementation.

If you are in fact using the constructor that takes a string for a file
name, not a stream - your syntax example allows for that interpretation -
then of course you can use the helper methods from System.IO.Path and/or
System.IO.File to check for the file.


Oliver Sturm
 

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

Back
Top