Thanks Alberto for the info... -----Original Message----- From: Alberto Massari [mailto:[EMAIL PROTECTED] Sent: Friday, December 31, 2004 8:41 AM To: xerces-c-dev@xml.apache.org Subject: Re: verifying domdocument
Hi Vince, Xerces doesn't currently perform validation of an in-memory DOM tree; but in order to detect validation error you can parse the generated file right after you wrote it. Alberto At 10.43 30/12/2004 -0500, Jairam, Roopnaraine wrote: >Hi all, > >I have a function that takes a domdocument* and writes it to the xml file. >My question is can I verify that the document adheres to my schema before >I save it. I have created xml documents that were invalid (while >debugging) according to my schema, but I didn't know it until I parsed the >xml doc. > >DWORD XML::writeToFile(xercesc::DOMDocument* document) >{ > DWORD status = ERROR_SUCCESS; > > if (document == NULL) > return ERROR_INVALID_HANDLE; > > XMLCh tempStr[100]; > XMLString::transcode("LS", tempStr, 99); > DOMImplementation *impl = > DOMImplementationRegistry::getDOMImplementation(tempStr); > DOMWriter* theSerializer = > ((DOMImplementationLS*)impl)->createDOMWriter(); > XMLCh* utf16str = NULL; > const XMLByte* str = NULL; > > // optionally you can set some features on this serializer > if > (theSerializer->canSetFeature(XMLUni::fgDOMWRTDiscardDefaultContent, true)) > theSerializer->setFeature(XMLUni::fgDOMWRTDiscardDefaultContent, > true); > > if (theSerializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, > true)) > theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, > true); > LocalFileFormatTarget myFileTarget( m_xmlFileName ); > > try > { > theSerializer->writeNode( &myFileTarget, *document); > > } > catch (const XMLException& toCatch) > { > status = ERROR_CANTWRITE; > > } > catch (const DOMException& toCatch) > { > status = ERROR_CANTWRITE; > } > catch (...) > { > status = ERROR_CANTWRITE; > } > > theSerializer->release(); > return status; >} > >Vince. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]