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 Daniel Burrell <da...@gmail.com> on 2008/08/02 06:22:53 UTC
Add doctype
Hey,
What would be the best way to add a doctype declaration tag to a document
that doesn't have one?
I've tried this, but it doesn't work, gives some sort of unhandled error:
DOMNode *theRootNode;
theRootNode = //somehow find the node we should insert before, how
do i find this node?
DOMNode *theDocTypeNode;
theDocTypeNode = doc->createDocumentType(XMLString::transcode(
"collection" ), 0, XMLString::transcode( gDtdFile )) ;
doc->insertBefore(theDocTypeNode,theRootNode);
Also, is there an 'insertAfter' function?
Re: Add doctype
Posted by Daniel Burrell <da...@gmail.com>.
Thanks
On Sun, Aug 3, 2008 at 3:40 AM, David Bertoni <db...@apache.org> wrote:
> Daniel Burrell wrote:
>
>> Hey,
>> What would be the best way to add a doctype declaration tag to a document
>> that doesn't have one?
>>
>> I've tried this, but it doesn't work, gives some sort of unhandled error:
>>
> Why don't you use a try/catch block to catch the DOMException and get the
> error code? Or better yet, you can debug into the call and see what's
> happening.
>
>
>> DOMNode *theRootNode;
>> theRootNode = //somehow find the node we should insert before, how
>> do i find this node?
>> DOMNode *theDocTypeNode;
>> theDocTypeNode = doc->createDocumentType(XMLString::transcode(
>> "collection" ), 0, XMLString::transcode( gDtdFile )) ;
>> doc->insertBefore(theDocTypeNode,theRootNode);
>>
> These calls to XMLString::transcode() return pointers that you need to
> deallocate. See the documentation for XMLString::transcode() for more
> information. Also, what is the value of theRootNode? Your comment seems to
> indicate that you don't know what child to use. I would recommend you use
> the document element by calling DOMDocument::getDocumentElement().
>
> I pasted the following code into the CreateDOMDocument sample at line 148:
>
> DOMNode *theDocTypeNode =
> theDocTypeNode = doc->createDocumentType(
> XMLString::transcode("collection" ),
> 0,
> XMLString::transcode( "foo.dtd"));
> doc->insertBefore(theDocTypeNode,rootElem);
>
> which worked correctly.
>
>
>> Also, is there an 'insertAfter' function?
>>
> No.
>
> Dave
>
Re: Add doctype
Posted by David Bertoni <db...@apache.org>.
Daniel Burrell wrote:
> Hey,
> What would be the best way to add a doctype declaration tag to a document
> that doesn't have one?
>
> I've tried this, but it doesn't work, gives some sort of unhandled error:
Why don't you use a try/catch block to catch the DOMException and get
the error code? Or better yet, you can debug into the call and see
what's happening.
>
> DOMNode *theRootNode;
> theRootNode = //somehow find the node we should insert before, how
> do i find this node?
> DOMNode *theDocTypeNode;
> theDocTypeNode = doc->createDocumentType(XMLString::transcode(
> "collection" ), 0, XMLString::transcode( gDtdFile )) ;
> doc->insertBefore(theDocTypeNode,theRootNode);
These calls to XMLString::transcode() return pointers that you need to
deallocate. See the documentation for XMLString::transcode() for more
information. Also, what is the value of theRootNode? Your comment
seems to indicate that you don't know what child to use. I would
recommend you use the document element by calling
DOMDocument::getDocumentElement().
I pasted the following code into the CreateDOMDocument sample at line 148:
DOMNode *theDocTypeNode =
theDocTypeNode = doc->createDocumentType(
XMLString::transcode("collection" ),
0,
XMLString::transcode( "foo.dtd"));
doc->insertBefore(theDocTypeNode,rootElem);
which worked correctly.
>
> Also, is there an 'insertAfter' function?
No.
Dave