You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Jordan C N Chong <ch...@cs.utwente.nl> on 2001/09/17 14:10:01 UTC

Error caused by existence of a file.

Dear all,

	I actually have this question for long. Please have a look at the following
code (only several lines):

	DOM_Document doc; DOM_Element root;
	DOM_Node node, child;
	DOM_NodeList list; DOMParser parser;

	// Parse the license with XML4C
	parser.parse(path); //path is the name and location of the file
	doc = parser.getDocument();
	root = doc.getDocumentElement();
	list = root.getElementsByTagName("WORK");

	Now the problem is at the parser.parse(path). The "path" must be the full
path of the file, if not, the application will crash at "root" and "list". I
wonder, IF THERE IS A WAY TO CHECK THE EXISTENCE OF THE FILE BEFORE PARSING
IT? I tried to set a check at "doc", like "if (doc == NULL)..." but it
doesn't do anything at all...

	Please help. Thousand thanks.


Best regards,
--------------------------------------------
Jordan Cheun Ngen, Chong
INF-4067 Universiteit Twente
Postbus 217
7500 AE Enschede
The Netherlands

Distributed and Embedded Systems (DIES)
--------------------------------------------
Office Phone: +31 53 4894655
Web site: http://www.cs.utwente.nl/~chong
Email Add.: chong@cs.utwente.nl
============================================


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Error caused by existence of a file.

Posted by "Jason E. Stewart" <ja...@openinformatics.com>.
"Jordan C N Chong" <ch...@cs.utwente.nl> writes:

> Now the problem is at the parser.parse(path). The "path" must be the
> full path of the file, if not, the application will crash at "root"
> and "list". 

I'm assuming that by 'full path' you mean fully qualified or absolute
path, i.e. '/home/jasons/foo.xml' vs relative path,
i.e. '../xml/foo.xml'?  It should accept either relative or absolute
paths. 

> I wonder, IF THERE IS A WAY TO CHECK THE EXISTENCE OF
> THE FILE BEFORE PARSING IT? 

See PlatformUtils.hpp, there are a number of file utility methods.

> I tried to set a check at "doc", like "if (doc == NULL)..." but it
> doesn't do anything at all...

You won't get a NULL pointer, you will get a DOM_Document that has a
null implementation object, you check that using the
DOM_Node::isNull() method.

  if (doc->isNull()) ...

or

  if (doc.isNull()) ...

for you reference fans.

jas.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org