You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by "Dantzler, DeWayne C" <de...@boeing.com> on 2009/11/04 04:20:48 UTC

How do I get Xerces to find the location of a DTD specified in an XML file?

 
Hello 

Scenario: I have a local dtd on my system and I'm running my code in the same directory as the dtd. I thought Xerces would look for the dtd relative to the current directory or if an absolute path is specified, use it. 
 
I have an xml file specified as follows:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mpd SYSTEM "mpdjpl03.dtd" [
<!ENTITY E67895 SYSTEM "E67895.tif" NDATA ccitt4>
<!ENTITY W28741 SYSTEM "W28741.tif" NDATA ccitt4>
<!ENTITY W28833 SYSTEM "W28833.tif" NDATA ccitt4>
.... Rest of xml file


I've generated code as follows:

    try
    {
		//The parser should use the default DTD called out in the XML file 
		//by the DOCTYPE declaration to resolve external ENTITY's  
		//------------- Example given below ------------- 
		//<!DOCTYPE mpd SYSTEM "mpboe03.dtd" [
		//<!ENTITY E67895 SYSTEM "E67895.tif" NDATA ccitt4>
		//<!ENTITY W28741 SYSTEM "W28741.tif" NDATA ccitt4>
		
		//Turn on the necessary features to allow validation by an internal DTD
	      //Val_Auto   - turn on validation only if an internal/external DTD subset has been seen!!
		_XmlDOMParser->setValidationScheme(_XmlDOMParser->Val_Auto);
		_XmlDOMParser->setDoSchema(false);
            _XmlDOMParser->parse(xmlDoc);
    }
    catch(....ALL EXCEPTIONs)
 
Results: I get the following Exception even though the permissions on the dtd is 777
"Parser Error Message: An exception occurred! Type:RuntimeException, Message:Could not open DTD file 'mpboe03.dtd'"

What must I do (syntax or SAX feature) for Xerces to locate the dtd?

RE: How do I get Xerces to find the location of a DTD specified in an XML file?

Posted by "Dantzler, DeWayne C" <de...@boeing.com>.
I've found a workaround. If I define an entity resolver to use the systemid passed by the parser which is the path specified in the DOCTYPE declaration in the XML file (i.e <!DOCTYPE mpd SYSTEM "mpboe03.dtd" ), I can verify the accessibility of the file and pass it to the parser to use as an inputsource.

Thanks Alberto

-----Original Message-----
From: Dantzler, DeWayne C 
Sent: Wednesday, November 04, 2009 8:40 AM
To: c-users@xerces.apache.org
Subject: RE: How do I get Xerces to find the location of a DTD specified inan XML file?

Sorry, I apologize. It was a typo and the name of the dtd in the XML is mpboe03. And I'm running Xerces2.7.0, but will be migrating to Xerces3.0.1 very soon. So, how does Xerces resolve paths to dtd's in an XML file? Does it attempt to look for the file in current directory the application is running under or should absolute paths be used?

Thanks 


-----Original Message-----
From: Alberto Massari [mailto:amassari@datadirect.com]
Sent: Tuesday, November 03, 2009 11:25 PM
To: c-users@xerces.apache.org
Subject: Re: How do I get Xerces to find the location of a DTD specified inan XML file?

Have you checked that in the same folder there is another DTD named mpboe03.dtd? From what you say, it looks you placed mpdjp103.dtd

Alberto


Dantzler, DeWayne C wrote:
>  
> Hello
>
> Scenario: I have a local dtd on my system and I'm running my code in the same directory as the dtd. I thought Xerces would look for the dtd relative to the current directory or if an absolute path is specified, use it. 
>  
> I have an xml file specified as follows:
>
> <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mpd SYSTEM 
> "mpboe03.dtd" [ <!ENTITY E67895 SYSTEM "E67895.tif" NDATA ccitt4> 
> <!ENTITY W28741 SYSTEM "W28741.tif" NDATA ccitt4> <!ENTITY W28833 
> SYSTEM "W28833.tif" NDATA ccitt4> .... Rest of xml file
>
>
> I've generated code as follows:
>
>     try
>     {
> 		//The parser should use the default DTD called out in the XML file 
> 		//by the DOCTYPE declaration to resolve external ENTITY's  
> 		//------------- Example given below ------------- 
> 		//<!DOCTYPE mpd SYSTEM "mpboe03.dtd" [
> 		//<!ENTITY E67895 SYSTEM "E67895.tif" NDATA ccitt4>
> 		//<!ENTITY W28741 SYSTEM "W28741.tif" NDATA ccitt4>
> 		
> 		//Turn on the necessary features to allow validation by an internal DTD
> 	      //Val_Auto   - turn on validation only if an internal/external DTD subset has been seen!!
> 		_XmlDOMParser->setValidationScheme(_XmlDOMParser->Val_Auto);
> 		_XmlDOMParser->setDoSchema(false);
>             _XmlDOMParser->parse(xmlDoc);
>     }
>     catch(....ALL EXCEPTIONs)
>  
> Results: I get the following Exception even though the permissions on 
> the dtd is 777 "Parser Error Message: An exception occurred! Type:RuntimeException, Message:Could not open DTD file 'mpboe03.dtd'"
>
> What must I do (syntax or SAX feature) for Xerces to locate the dtd?
>   


RE: How do I get Xerces to find the location of a DTD specified in an XML file?

Posted by "Dantzler, DeWayne C" <de...@boeing.com>.
I do apologize for not providing sufficient details. I'm running on HP-UX ddpsdev1 B.11.11 U 9000/800 and xmlDoc is a variable assigned to the name of the XML file that specifies the dtd. It is the file that I'm trying to parse. I've set the permissions on the file to 777 and I tried using an absolute path to the dtd with the same results:
Type:RuntimeException, Message:Could not open DTD file 'fullpath/mpboe03.dtd'


-----Original Message-----
From: Alberto Massari [mailto:amassari@datadirect.com] 
Sent: Wednesday, November 04, 2009 8:51 AM
To: c-users@xerces.apache.org
Subject: Re: How do I get Xerces to find the location of a DTD specified inan XML file?

When a relative path is found, the path of the including file is used as base path; missing that, the current directory (as reported by the OS) is used. What is the xmlDoc variable? What platform you are running on?

Alberto

Dantzler, DeWayne C wrote:
> Sorry, I apologize. It was a typo and the name of the dtd in the XML is mpboe03. And I'm running Xerces2.7.0, but will be migrating to Xerces3.0.1 very soon. So, how does Xerces resolve paths to dtd's in an XML file? Does it attempt to look for the file in current directory the application is running under or should absolute paths be used?
>
> Thanks
>
>
> -----Original Message-----
> From: Alberto Massari [mailto:amassari@datadirect.com]
> Sent: Tuesday, November 03, 2009 11:25 PM
> To: c-users@xerces.apache.org
> Subject: Re: How do I get Xerces to find the location of a DTD specified inan XML file?
>
> Have you checked that in the same folder there is another DTD named 
> mpboe03.dtd? From what you say, it looks you placed mpdjp103.dtd
>
> Alberto
>
>
> Dantzler, DeWayne C wrote:
>   
>>  
>> Hello
>>
>> Scenario: I have a local dtd on my system and I'm running my code in the same directory as the dtd. I thought Xerces would look for the dtd relative to the current directory or if an absolute path is specified, use it. 
>>  
>> I have an xml file specified as follows:
>>
>> <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mpd SYSTEM 
>> "mpboe03.dtd" [ <!ENTITY E67895 SYSTEM "E67895.tif" NDATA ccitt4> 
>> <!ENTITY W28741 SYSTEM "W28741.tif" NDATA ccitt4> <!ENTITY W28833 
>> SYSTEM "W28833.tif" NDATA ccitt4> .... Rest of xml file
>>
>>
>> I've generated code as follows:
>>
>>     try
>>     {
>> 		//The parser should use the default DTD called out in the XML file 
>> 		//by the DOCTYPE declaration to resolve external ENTITY's  
>> 		//------------- Example given below ------------- 
>> 		//<!DOCTYPE mpd SYSTEM "mpboe03.dtd" [
>> 		//<!ENTITY E67895 SYSTEM "E67895.tif" NDATA ccitt4>
>> 		//<!ENTITY W28741 SYSTEM "W28741.tif" NDATA ccitt4>
>> 		
>> 		//Turn on the necessary features to allow validation by an internal DTD
>> 	      //Val_Auto   - turn on validation only if an internal/external DTD subset has been seen!!
>> 		_XmlDOMParser->setValidationScheme(_XmlDOMParser->Val_Auto);
>> 		_XmlDOMParser->setDoSchema(false);
>>             _XmlDOMParser->parse(xmlDoc);
>>     }
>>     catch(....ALL EXCEPTIONs)
>>  
>> Results: I get the following Exception even though the permissions on 
>> the dtd is 777 "Parser Error Message: An exception occurred! Type:RuntimeException, Message:Could not open DTD file 'mpboe03.dtd'"
>>
>> What must I do (syntax or SAX feature) for Xerces to locate the dtd?
>>   
>>     
>
>
>   


Re: How do I get Xerces to find the location of a DTD specified in an XML file?

Posted by Alberto Massari <am...@datadirect.com>.
When a relative path is found, the path of the including file is used as 
base path; missing that, the current directory (as reported by the OS) 
is used. What is the xmlDoc variable? What platform you are running on?

Alberto

Dantzler, DeWayne C wrote:
> Sorry, I apologize. It was a typo and the name of the dtd in the XML is mpboe03. And I'm running Xerces2.7.0, but will be migrating to Xerces3.0.1 very soon. So, how does Xerces resolve paths to dtd's in an XML file? Does it attempt to look for the file in current directory the application is running under or should absolute paths be used?
>
> Thanks 
>
>
> -----Original Message-----
> From: Alberto Massari [mailto:amassari@datadirect.com] 
> Sent: Tuesday, November 03, 2009 11:25 PM
> To: c-users@xerces.apache.org
> Subject: Re: How do I get Xerces to find the location of a DTD specified inan XML file?
>
> Have you checked that in the same folder there is another DTD named mpboe03.dtd? From what you say, it looks you placed mpdjp103.dtd
>
> Alberto
>
>
> Dantzler, DeWayne C wrote:
>   
>>  
>> Hello
>>
>> Scenario: I have a local dtd on my system and I'm running my code in the same directory as the dtd. I thought Xerces would look for the dtd relative to the current directory or if an absolute path is specified, use it. 
>>  
>> I have an xml file specified as follows:
>>
>> <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mpd SYSTEM 
>> "mpboe03.dtd" [ <!ENTITY E67895 SYSTEM "E67895.tif" NDATA ccitt4> 
>> <!ENTITY W28741 SYSTEM "W28741.tif" NDATA ccitt4> <!ENTITY W28833 
>> SYSTEM "W28833.tif" NDATA ccitt4> .... Rest of xml file
>>
>>
>> I've generated code as follows:
>>
>>     try
>>     {
>> 		//The parser should use the default DTD called out in the XML file 
>> 		//by the DOCTYPE declaration to resolve external ENTITY's  
>> 		//------------- Example given below ------------- 
>> 		//<!DOCTYPE mpd SYSTEM "mpboe03.dtd" [
>> 		//<!ENTITY E67895 SYSTEM "E67895.tif" NDATA ccitt4>
>> 		//<!ENTITY W28741 SYSTEM "W28741.tif" NDATA ccitt4>
>> 		
>> 		//Turn on the necessary features to allow validation by an internal DTD
>> 	      //Val_Auto   - turn on validation only if an internal/external DTD subset has been seen!!
>> 		_XmlDOMParser->setValidationScheme(_XmlDOMParser->Val_Auto);
>> 		_XmlDOMParser->setDoSchema(false);
>>             _XmlDOMParser->parse(xmlDoc);
>>     }
>>     catch(....ALL EXCEPTIONs)
>>  
>> Results: I get the following Exception even though the permissions on 
>> the dtd is 777 "Parser Error Message: An exception occurred! Type:RuntimeException, Message:Could not open DTD file 'mpboe03.dtd'"
>>
>> What must I do (syntax or SAX feature) for Xerces to locate the dtd?
>>   
>>     
>
>
>   


RE: How do I get Xerces to find the location of a DTD specified in an XML file?

Posted by "Dantzler, DeWayne C" <de...@boeing.com>.
Sorry, I apologize. It was a typo and the name of the dtd in the XML is mpboe03. And I'm running Xerces2.7.0, but will be migrating to Xerces3.0.1 very soon. So, how does Xerces resolve paths to dtd's in an XML file? Does it attempt to look for the file in current directory the application is running under or should absolute paths be used?

Thanks 


-----Original Message-----
From: Alberto Massari [mailto:amassari@datadirect.com] 
Sent: Tuesday, November 03, 2009 11:25 PM
To: c-users@xerces.apache.org
Subject: Re: How do I get Xerces to find the location of a DTD specified inan XML file?

Have you checked that in the same folder there is another DTD named mpboe03.dtd? From what you say, it looks you placed mpdjp103.dtd

Alberto


Dantzler, DeWayne C wrote:
>  
> Hello
>
> Scenario: I have a local dtd on my system and I'm running my code in the same directory as the dtd. I thought Xerces would look for the dtd relative to the current directory or if an absolute path is specified, use it. 
>  
> I have an xml file specified as follows:
>
> <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mpd SYSTEM 
> "mpboe03.dtd" [ <!ENTITY E67895 SYSTEM "E67895.tif" NDATA ccitt4> 
> <!ENTITY W28741 SYSTEM "W28741.tif" NDATA ccitt4> <!ENTITY W28833 
> SYSTEM "W28833.tif" NDATA ccitt4> .... Rest of xml file
>
>
> I've generated code as follows:
>
>     try
>     {
> 		//The parser should use the default DTD called out in the XML file 
> 		//by the DOCTYPE declaration to resolve external ENTITY's  
> 		//------------- Example given below ------------- 
> 		//<!DOCTYPE mpd SYSTEM "mpboe03.dtd" [
> 		//<!ENTITY E67895 SYSTEM "E67895.tif" NDATA ccitt4>
> 		//<!ENTITY W28741 SYSTEM "W28741.tif" NDATA ccitt4>
> 		
> 		//Turn on the necessary features to allow validation by an internal DTD
> 	      //Val_Auto   - turn on validation only if an internal/external DTD subset has been seen!!
> 		_XmlDOMParser->setValidationScheme(_XmlDOMParser->Val_Auto);
> 		_XmlDOMParser->setDoSchema(false);
>             _XmlDOMParser->parse(xmlDoc);
>     }
>     catch(....ALL EXCEPTIONs)
>  
> Results: I get the following Exception even though the permissions on 
> the dtd is 777 "Parser Error Message: An exception occurred! Type:RuntimeException, Message:Could not open DTD file 'mpboe03.dtd'"
>
> What must I do (syntax or SAX feature) for Xerces to locate the dtd?
>   


Re: How do I get Xerces to find the location of a DTD specified in an XML file?

Posted by Alberto Massari <am...@datadirect.com>.
Have you checked that in the same folder there is another DTD named 
mpboe03.dtd? From what you say, it looks you placed mpdjp103.dtd

Alberto


Dantzler, DeWayne C wrote:
>  
> Hello 
>
> Scenario: I have a local dtd on my system and I'm running my code in the same directory as the dtd. I thought Xerces would look for the dtd relative to the current directory or if an absolute path is specified, use it. 
>  
> I have an xml file specified as follows:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE mpd SYSTEM "mpdjpl03.dtd" [
> <!ENTITY E67895 SYSTEM "E67895.tif" NDATA ccitt4>
> <!ENTITY W28741 SYSTEM "W28741.tif" NDATA ccitt4>
> <!ENTITY W28833 SYSTEM "W28833.tif" NDATA ccitt4>
> .... Rest of xml file
>
>
> I've generated code as follows:
>
>     try
>     {
> 		//The parser should use the default DTD called out in the XML file 
> 		//by the DOCTYPE declaration to resolve external ENTITY's  
> 		//------------- Example given below ------------- 
> 		//<!DOCTYPE mpd SYSTEM "mpboe03.dtd" [
> 		//<!ENTITY E67895 SYSTEM "E67895.tif" NDATA ccitt4>
> 		//<!ENTITY W28741 SYSTEM "W28741.tif" NDATA ccitt4>
> 		
> 		//Turn on the necessary features to allow validation by an internal DTD
> 	      //Val_Auto   - turn on validation only if an internal/external DTD subset has been seen!!
> 		_XmlDOMParser->setValidationScheme(_XmlDOMParser->Val_Auto);
> 		_XmlDOMParser->setDoSchema(false);
>             _XmlDOMParser->parse(xmlDoc);
>     }
>     catch(....ALL EXCEPTIONs)
>  
> Results: I get the following Exception even though the permissions on the dtd is 777
> "Parser Error Message: An exception occurred! Type:RuntimeException, Message:Could not open DTD file 'mpboe03.dtd'"
>
> What must I do (syntax or SAX feature) for Xerces to locate the dtd?
>