1) Is there any way to tell if a node is still valid?

Right now there is a chance that my document could be released and someone
could still have a reference open to a wrapper object.  I would like to be
able to look at a DOMNode, etc and tell if it is valid before trying to
perform an operation on it.  Is there any easy way to do this?

2) Why do I get a crash when I try to release the doc in the DOMPrint
example?  I can understand that it is not a "created" object, but why does
the following crash (note that I am only including part of the DOMPrint
example for brevity, assume anything not seen here is exactly the same as
the sample shipped).  Note that the doc is released right after the
writeNode line.

try
        {
            // get a serializer, an instance of DOMWriter
            XMLCh tempStr[100];
            XMLString::transcode("LS", tempStr, 99);
            DOMImplementation *impl          =
DOMImplementationRegistry::getDOMImplementation(tempStr);
            DOMWriter         *theSerializer = ((DOMImplementationLS*)impl)
->createDOMWriter();

            // set user specified end of line sequence and output encoding
            theSerializer->setNewLine(gMyEOLSequence);
            theSerializer->setEncoding(gOutputEncoding);

            // plug in user's own filter
            if (gUseFilter)
            {
                // even we say to show attribute, but the DOMWriter
                // will not show attribute nodes to the filter as
                // the specs explicitly says that DOMWriter shall
                // NOT show attributes to DOMWriterFilter.
                //
                // so DOMNodeFilter::SHOW_ATTRIBUTE has no effect.
                // same DOMNodeFilter::SHOW_DOCUMENT_TYPE, no effect.
                //
                myFilter = new DOMPrintFilter(DOMNodeFilter::SHOW_ELEMENT
|
                                              DOMNodeFilter::SHOW_ATTRIBUTE
|

DOMNodeFilter::SHOW_DOCUMENT_TYPE);
                theSerializer->setFilter(myFilter);
            }

            // plug in user's own error handler
            DOMErrorHandler *myErrorHandler = new DOMPrintErrorHandler();
            theSerializer->setErrorHandler(myErrorHandler);

            // set feature if the serializer supports the feature/mode
            if
(theSerializer->canSetFeature(XMLUni::fgDOMWRTSplitCdataSections,
gSplitCdataSections))

theSerializer->setFeature(XMLUni::fgDOMWRTSplitCdataSections,
gSplitCdataSections);

            if
(theSerializer->canSetFeature(XMLUni::fgDOMWRTDiscardDefaultContent,
gDiscardDefaultContent))

theSerializer->setFeature(XMLUni::fgDOMWRTDiscardDefaultContent,
gDiscardDefaultContent);

            if
(theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
gFormatPrettyPrint))

theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint,
gFormatPrettyPrint);

            if (theSerializer->canSetFeature(XMLUni::fgDOMWRTBOM,
gWriteBOM))
                theSerializer->setFeature(XMLUni::fgDOMWRTBOM, gWriteBOM);

            //
            // Plug in a format target to receive the resultant
            // XML stream from the serializer.
            //
            // StdOutFormatTarget prints the resultant XML stream
            // to stdout once it receives any thing from the serializer.
            //
            XMLFormatTarget *myFormTarget;
            if (goutputfile)
                myFormTarget = new LocalFileFormatTarget(goutputfile);
            else
                myFormTarget = new StdOutFormatTarget();

            // get the DOM representation
            DOMNode                     *doc = parser->getDocument();

            //
            // do the serialization through DOMWriter::writeNode();
            //
            theSerializer->writeNode(myFormTarget, *doc);
           doc->release();

            delete theSerializer;

            //
            // Filter, formatTarget and error handler
            // are NOT owned by the serializer.
            //
            delete myFormTarget;
            delete myErrorHandler;

            if (gUseFilter)
                delete myFilter;

        }
        catch (XMLException& e)
        {
            cerr << "An error occurred during creation of output
transcoder. Msg is:"
                << endl
                << StrX(e.getMessage()) << endl;
            retval = 4;
        }

    }

Thanks!!!!


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to