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 radada <pa...@yahoo.fr> on 2009/04/28 17:20:31 UTC

Oh... Tricky one : )

Hi there again

For some reasons, which would be too long to describe, I want to subclass
the DOMDocument class into a XMLDocument class.
In other words, XMLDocument inherits from DOMDocument.
Here's the tricky question : since the DMODocument uses a factory to be
create (createDocument method from DOMImplementationRegistry), how can I
build an XMLDocument.

Do you know if this works : 

XMLDocument:: XMLDocument()
{
   DOMImplementation *impl =
DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("LS"));   
   this = (XMLDocument*) impl->createDocument();
}

If not, what solutions can I have other than creating a class that does not
inherits from DOMDocument and simply have a DOMDocument variable?

Thanks :) 
-- 
View this message in context: http://www.nabble.com/Oh...-Tricky-one-%3A-%29-tp23279310p23279310.html
Sent from the Xerces - C - Dev mailing list archive at Nabble.com.


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


Re: Oh... Tricky one : )

Posted by Ben Griffin <be...@redsnapper.net>.
I use something just like that,
Though I have a static impl.

	DOMDocument* newDoc() {
		return impl->createDocument(); //no root element.
	}



On 28 Apr 2009, at 16:20, radada wrote:

>
> Hi there again
>
> For some reasons, which would be too long to describe, I want to  
> subclass
> the DOMDocument class into a XMLDocument class.
> In other words, XMLDocument inherits from DOMDocument.
> Here's the tricky question : since the DMODocument uses a factory to  
> be
> create (createDocument method from DOMImplementationRegistry), how  
> can I
> build an XMLDocument.
>
> Do you know if this works :
>
> XMLDocument:: XMLDocument()
> {
>   DOMImplementation *impl =
> DOMImplementationRegistry 
> ::getDOMImplementation(XMLString::transcode("LS"));
>   this = (XMLDocument*) impl->createDocument();
> }
>
> If not, what solutions can I have other than creating a class that  
> does not
> inherits from DOMDocument and simply have a DOMDocument variable?
>
> Thanks :)
> -- 
> View this message in context: http://www.nabble.com/Oh...-Tricky-one-%3A-%29-tp23279310p23279310.html
> Sent from the Xerces - C - Dev mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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: Oh... Tricky one : )

Posted by radada <pa...@yahoo.fr>.
Thx for your answers.
The compiler did raised an error, though I tried that after posting here : )

I did thought of modifying the xerces source code, but I don't want to
mess-up everything. And besides, if a new version is released, I would have
to implement this code again, and it could fail.

Which leaves me with the last option : "Create your own implementation
registry and use it instead"
How can I do that? I mean, if a class inherits from DOMDocument, how can I
use a Factory in my class's constructor?

Don't you think that the solution would be to call the DOMDocument
constructor (protected, but I can use it since I inherit from DOMDocument)
in my class's constructor?

Thanks again.


David Bertoni wrote:
> 
> radada wrote:
>> Hi there again
>> 
>> For some reasons, which would be too long to describe, I want to subclass
>> the DOMDocument class into a XMLDocument class.
>> In other words, XMLDocument inherits from DOMDocument.
> DOMDocument is an abstract base class, so you will need to implement 
> every pure virtual function in your derived class.  Perhaps it would be 
> better to derive your class from DOMDocumentImpl, but that could be 
> tricky, because DOMDocumentImpl was probably not designed to be a base 
> class.
> 
>> Here's the tricky question : since the DMODocument uses a factory to be
>> create (createDocument method from DOMImplementationRegistry), how can I
>> build an XMLDocument.
>> 
>> Do you know if this works : 
>> 
>> XMLDocument:: XMLDocument()
>> {
>>    DOMImplementation *impl =
>> DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("LS"));   
>>    this = (XMLDocument*) impl->createDocument();
>> }
> It is illegal to assign to the "this" pointer, and the compiler will 
> emit an error if your code does this.  I'm surprised your compiler didn't.
> 
> Even if you were allowed to assign to the this pointer, the cast is 
> illegal.  Casting a pointer doesn't change the type of the object being 
> pointed to.
> 
>> 
>> If not, what solutions can I have other than creating a class that does
>> not
>> inherits from DOMDocument and simply have a DOMDocument variable?
> I can think of several ways to do this:
> 
>    1. Create your own implementation registry and use it instead.
>    2. Modify the Xerces-C source code to create an instance of your type 
> instead of DOMDocumentImpl.
> 
> I would caution you to be very careful when doing this, because you need 
> to ensure your implementation is 100% compliant with the existing 
> implementation.
> 
> Dave
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: c-dev-help@xerces.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Oh...-Tricky-one-%3A-%29-tp23279310p23291386.html
Sent from the Xerces - C - Dev mailing list archive at Nabble.com.


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


Re: Oh... Tricky one : )

Posted by David Bertoni <db...@apache.org>.
radada wrote:
> Hi there again
> 
> For some reasons, which would be too long to describe, I want to subclass
> the DOMDocument class into a XMLDocument class.
> In other words, XMLDocument inherits from DOMDocument.
DOMDocument is an abstract base class, so you will need to implement 
every pure virtual function in your derived class.  Perhaps it would be 
better to derive your class from DOMDocumentImpl, but that could be 
tricky, because DOMDocumentImpl was probably not designed to be a base 
class.

> Here's the tricky question : since the DMODocument uses a factory to be
> create (createDocument method from DOMImplementationRegistry), how can I
> build an XMLDocument.
> 
> Do you know if this works : 
> 
> XMLDocument:: XMLDocument()
> {
>    DOMImplementation *impl =
> DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("LS"));   
>    this = (XMLDocument*) impl->createDocument();
> }
It is illegal to assign to the "this" pointer, and the compiler will 
emit an error if your code does this.  I'm surprised your compiler didn't.

Even if you were allowed to assign to the this pointer, the cast is 
illegal.  Casting a pointer doesn't change the type of the object being 
pointed to.

> 
> If not, what solutions can I have other than creating a class that does not
> inherits from DOMDocument and simply have a DOMDocument variable?
I can think of several ways to do this:

   1. Create your own implementation registry and use it instead.
   2. Modify the Xerces-C source code to create an instance of your type 
instead of DOMDocumentImpl.

I would caution you to be very careful when doing this, because you need 
to ensure your implementation is 100% compliant with the existing 
implementation.

Dave

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