Steve, Thanks a lot for time to explain. This helps a lot ! Regards Ajay
--- On Fri, 10/14/11, Steve Hathaway <shath...@e-z.net> wrote: From: Steve Hathaway <shath...@e-z.net> Subject: Re: How do implement EntityResolver for XSLT XML transformation To: xalan-c-users@xml.apache.org Date: Friday, October 14, 2011, 10:57 AM Ajay, If you are going to write and implement your own entity resolver, you need to understand the API interface of the XercesC library. The Entity Resolver (either class XMLEntityResolver or class EntityReslover) is instantiated in by the current Xerces XMLReader to resolve external entities and make their contents known by pushing a new XMLReader onto the stack, becoming the new XMLReader. This interrupts the current bytestream of input with a new bytestream of input. When the resolved entity bytestream has been consumed, the reader is removed from the stack and the previous reader resumes operation where interrupted. See also the Xerces ReaderMgr. You should look at the various input sources in the xercesc/framework directory. Your entity resolver is actually an instance of a Xerces based class. The knowledge of the resolver can be registered to the XalanTransformer so it can be used in place of an insecure default entity resolver. There are two classes for entity resolvers: XMLEntityResolver and EntityResolver The registration of one entity resolver class automatically removes the registration of the other entity resolver class. You can check to see if a custom entity resolver of either class has been registered. Refer to: class XalanTransformer { public: void setEntityResolver(EntityResolver* theResolver) { m_entityResolver = theResolver; if (theResolver != 0 && m_xmlEntityResolver != 0) { m_xmlEntityResolver = 0; } } EntityResolver * getEntityResolver() const { return m_entityResolver; } void setXMLEntityResolver(XMLEntityResolver* theResolver) { m_xmlEentityResolver = theResolver; if (theResolver != 0 && m_entityResolver != 0) { m_entityResolver = 0; } } XMLEntityResolver * getXMLEntityResolver() const { return m_xmlEntityResolver; } private: // data members EntityResolver * m_entityResolver; XMLEntityResolver * m_xmlEntityResolver; } ------ The above active entity resolver get instantiated to the Xerces::SAX2XMLReaderImpl when when creating a XML reader and pushing it onto the active reader stack. The actual EntityResolver or XMLEntityResolver is responsible for creating the Xerces XML Reader to be pushed onto the stack as the active reader. If no resource is resolved, then the current XML reader remains active. ------- The application specific XML entity resolver should be registered with the XalanTransformer if it is to be used to create Xerces XML readers. If no application specific XML entity resolver is created, then a default XML entity resolver is used. The insecurity of the default XML entity resolver is that system data files are directly accessed, and a global DNS is used to resolve network resources that are not local to the computer. ------- Xalan has its own document handlers to use for Xerces reader callback functions. ------- The registered entity resolver in XalanTransformer becomes the entityHandler() as known in the Xerces::SAX2XMLReaderImpl fScanner->setEntityHandler(this); The entity handler actually implements the class Xerces::XMLEntityHandler as known by the ReaderMgr which controls the stack of active XML readers. The entity handler is invoked by the current XML Scanner to place a new reader on the stack as the active XML reader. This actually interrups the XML scanning process to insert XML content from a resolved entity resource. -------- I hope this helps. Entity resolvers is a complex topic. Trusted entity resolvers are required for trusted XML applications. You might also wish to look at some of the specifications archived at: http://www.oasis-open.org/standards#xmlcatalogsv1.1 Sincerely, Steven J. Hathaway On 10/12/2011 8:24 AM, ajay bhadauria wrote: Hi, I am using transform method to transform input xml source to output xml. In the xslt, I have document () call to resolve external entities. The external enties are available in memory instead of file-system files during transformation. Please help me how do I write my own entity resolver to resolve external enties during xml transformation . Any code example referenece will be great. Thanks Ajay