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 Harish Aroli <Ha...@travimp.com> on 2008/06/12 19:55:49 UTC

An exception occurred! Type:RuntimeException, Message:The primary document entity could not be opened

Hello,

When I tried validating a XML file  against a XML schema using DOM parser, I am getting the error (through ErrorHandler) as     "An exception occurred! Type:RuntimeException,  Message:The primary document entity could not be opened".  I am not getting how to resolve this.  No idea what is going wrong.

Platform: AIX using xlc.
Xercesc Version "  xerces-c27.0

Here is the code snippet:

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
std::string xml_msg; // I was updating this variable with the xml file.
CDomErrorHandler* errorChecker = new CDomErrorHandler();  // The error handler overrided from ErrorHandler.
m_DomTreeParser = new XercesDOMParser();
m_DomTreeParser->setErrorHandler(errorChecker);

m_DomTreeParser->setValidationScheme( XercesDOMParser::Val_Always );
m_DomTreeParser->setDoNamespaces( true );
m_DomTreeParser->setDoSchema(true );
 m_DomTreeParser->setValidationSchemaFullChecking(true);
// m_DomTreeParser->setExternalNoNamespaceSchemaLocation("sample.xsd");                     // I tried both this and the one in  below line also.
m_DomTreeParser->loadGrammar("sample.xsd", Grammar::SchemaGrammarType, true);
m_DomTreeParser->parse( xml_msg.c_str() );

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Any help is appreciated, really.

Thanks!
Harish

Cheers!
 
Harish A V



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


Invalid document structure

Posted by Harish Aroli <Ha...@travimp.com>.

Cheers!
 
Harish A V


Re: An exception occurred! Type:RuntimeException, Message:The primarydocumententity could not be o

Posted by Harish Aroli <Ha...@travimp.com>.
Hello,

When I am giving the fake xml file name,  I am getting the error as "Invalid document structure".

I was doing it like this,

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

           const char* xmlPath ="sample.xml";
           MemBufInputSource* memBufIS = new MemBufInputSource( (const XMLByte*)((xml_msg).c_str())   \
                                                                                           ,strlen((xml_msg).c_str()),xmlPath,false);

            parser->parse(*memBufIS);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  

Any help is appreciated, really.

Thanks!
Harish

Cheers!
 
Harish A V


>>> David Bertoni <db...@apache.org> 6/12/2008 5:35 PM >>>
Harish Aroli wrote:
> Hello,
> em
> I got the problem but not the solution  !!!!!!
Calm down please...

> 
> I am storing the XML input from the page to a std::string xml_msg variable.
> 
> While parsing I am giving it as parser->parse(xml_msg.c_str());  
And that API takes a system ID, so supplying the stream of bytes for an 
XML document isn't going to work.

> 
> parse() will normaly take the full or local path of the xml file or the inputsource class.  But here I am passing the XML message itself.
> Here the parse() function is taking the full xml message as the path or name of xml file which is having the xml message  and is giving issues as there is no such file exists.
> 
> I don't want to read it from file.  I am already having the xml message ready and stored inside a std::string variable.
> 
> Is there any way to handle this.
Yes.  Instead of using an API incorrectly, take a look at the MemParse 
sample application.

The extra twist in your use case will be to set the system ID of the 
InputSource to a fake XML file name with the same directory as the 
schema file.  So, pretend sample.xsd is in /home/user/sample:

MemBufInputSource is(...)

is.setSystemId("/home/user/sample/sample.xml");

Now the parser can resolve the relative reference to sample.xsd using 
the base URI of the primary document.

Another solution would be to use an EntityResolver, but that's more 
complicated.

Dave

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



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


Re: An exception occurred! Type:RuntimeException, Message:The primarydocument entity could not be o

Posted by David Bertoni <db...@apache.org>.
Harish Aroli wrote:
> Hello,
> em
> I got the problem but not the solution  !!!!!!
Calm down please...

> 
> I am storing the XML input from the page to a std::string xml_msg variable.
> 
> While parsing I am giving it as parser->parse(xml_msg.c_str());  
And that API takes a system ID, so supplying the stream of bytes for an 
XML document isn't going to work.

> 
> parse() will normaly take the full or local path of the xml file or the inputsource class.  But here I am passing the XML message itself.
> Here the parse() function is taking the full xml message as the path or name of xml file which is having the xml message  and is giving issues as there is no such file exists.
> 
> I don't want to read it from file.  I am already having the xml message ready and stored inside a std::string variable.
> 
> Is there any way to handle this.
Yes.  Instead of using an API incorrectly, take a look at the MemParse 
sample application.

The extra twist in your use case will be to set the system ID of the 
InputSource to a fake XML file name with the same directory as the 
schema file.  So, pretend sample.xsd is in /home/user/sample:

MemBufInputSource is(...)

is.setSystemId("/home/user/sample/sample.xml");

Now the parser can resolve the relative reference to sample.xsd using 
the base URI of the primary document.

Another solution would be to use an EntityResolver, but that's more 
complicated.

Dave

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


Re: An exception occurred! Type:RuntimeException, Message:The primarydocument entity could not be o

Posted by Harish Aroli <Ha...@travimp.com>.
Hello,

I got the problem but not the solution  !!!!!!

I am storing the XML input from the page to a std::string xml_msg variable.

While parsing I am giving it as parser->parse(xml_msg.c_str());  

parse() will normaly take the full or local path of the xml file or the inputsource class.  But here I am passing the XML message itself.
Here the parse() function is taking the full xml message as the path or name of xml file which is having the xml message  and is giving issues as there is no such file exists.

I don't want to read it from file.  I am already having the xml message ready and stored inside a std::string variable.

Is there any way to handle this.

 Any help is appreciated, really.

Thanks!
Harish

Cheers!
 
Harish A V


>>> Alberto Massari <am...@datadirect.com> 6/12/2008 2:05 PM >>>
Harish Aroli wrote:
> Hello,
>
> When I tried validating a XML file  against a XML schema using DOM parser, I am getting the error (through ErrorHandler) as     "An exception occurred! Type:RuntimeException,  Message:The primary document entity could not be opened".  I am not getting how to resolve this.  No idea what is going wrong.
>   

This exception means that the document could not be found; given that 
you are simply specifying "sample.xsd", verify what is the current 
directory, or try specifying a full path.

Alberto

> Platform: AIX using xlc.
> Xercesc Version "  xerces-c27.0
>
> Here is the code snippet:
>
> ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
> std::string xml_msg; // I was updating this variable with the xml file.
> CDomErrorHandler* errorChecker = new CDomErrorHandler();  // The error handler overrided from ErrorHandler.
> m_DomTreeParser = new XercesDOMParser();
> m_DomTreeParser->setErrorHandler(errorChecker);
>
> m_DomTreeParser->setValidationScheme( XercesDOMParser::Val_Always );
> m_DomTreeParser->setDoNamespaces( true );
> m_DomTreeParser->setDoSchema(true );
>  m_DomTreeParser->setValidationSchemaFullChecking(true);
> // m_DomTreeParser->setExternalNoNamespaceSchemaLocation("sample.xsd");                     // I tried both this and the one in  below line also.
> m_DomTreeParser->loadGrammar("sample.xsd", Grammar::SchemaGrammarType, true);
> m_DomTreeParser->parse( xml_msg.c_str() );
>
> /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>
> Any help is appreciated, really.
>
> Thanks!
> Harish
>
> Cheers!
>  
> Harish A V
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org 
> For additional commands, e-mail: c-dev-help@xerces.apache.org 
>
>
>   


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



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


Re: An exception occurred! Type:RuntimeException, Message:The primary document entity could not be opened

Posted by Alberto Massari <am...@datadirect.com>.
Harish Aroli wrote:
> Hello,
>
> When I tried validating a XML file  against a XML schema using DOM parser, I am getting the error (through ErrorHandler) as     "An exception occurred! Type:RuntimeException,  Message:The primary document entity could not be opened".  I am not getting how to resolve this.  No idea what is going wrong.
>   

This exception means that the document could not be found; given that 
you are simply specifying "sample.xsd", verify what is the current 
directory, or try specifying a full path.

Alberto

> Platform: AIX using xlc.
> Xercesc Version "  xerces-c27.0
>
> Here is the code snippet:
>
> ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
> std::string xml_msg; // I was updating this variable with the xml file.
> CDomErrorHandler* errorChecker = new CDomErrorHandler();  // The error handler overrided from ErrorHandler.
> m_DomTreeParser = new XercesDOMParser();
> m_DomTreeParser->setErrorHandler(errorChecker);
>
> m_DomTreeParser->setValidationScheme( XercesDOMParser::Val_Always );
> m_DomTreeParser->setDoNamespaces( true );
> m_DomTreeParser->setDoSchema(true );
>  m_DomTreeParser->setValidationSchemaFullChecking(true);
> // m_DomTreeParser->setExternalNoNamespaceSchemaLocation("sample.xsd");                     // I tried both this and the one in  below line also.
> m_DomTreeParser->loadGrammar("sample.xsd", Grammar::SchemaGrammarType, true);
> m_DomTreeParser->parse( xml_msg.c_str() );
>
> /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>
> Any help is appreciated, really.
>
> Thanks!
> Harish
>
> Cheers!
>  
> Harish A V
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: c-dev-help@xerces.apache.org
>
>
>   


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