本文整理汇总了C++中DOMLSOutput::release方法的典型用法代码示例。如果您正苦于以下问题:C++ DOMLSOutput::release方法的具体用法?C++ DOMLSOutput::release怎么用?C++ DOMLSOutput::release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMLSOutput
的用法示例。
在下文中一共展示了DOMLSOutput::release方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dumpTree
/// Dump DOM tree using XercesC handles
void dumpTree(DOMNode* doc, ostream& os) {
if ( doc ) {
DOMImplementation *imp = DOMImplementationRegistry::getDOMImplementation(Strng_t("LS"));
MemBufFormatTarget *tar = new MemBufFormatTarget();
DOMLSOutput *out = imp->createLSOutput();
DOMLSSerializer *wrt = imp->createLSSerializer();
out->setByteStream(tar);
wrt->getDomConfig()->setParameter(Strng_t("format-pretty-print"), true);
wrt->write(doc, out);
os << tar->getRawBuffer() << endl << flush;
out->release();
wrt->release();
return;
}
printout(ERROR,"dumpTree","+++ Cannot dump invalid document.");
}
示例2: commit
int XmlParser::commit(const char* xmlFile) {
try {
// Obtain DOM implementation supporting Load/Save
DOMImplementationLS* pImplementation = dynamic_cast<DOMImplementationLS *>(DOMImplementationRegistry::getDOMImplementation(DualString("LS").asXMLString()));
if (pImplementation == NULL){
throw( std::runtime_error( "Unable to obtain suitable DOMImplementation!" ) ) ;
}
DOMLSSerializer *pSerializer = pImplementation->createLSSerializer();
DOMLSOutput *pOutput = pImplementation->createLSOutput();
#if 1
// Change output format to be pretty (but it isn't)
DOMConfiguration *pConfiguration = pSerializer->getDomConfig();
if (pConfiguration->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
pConfiguration->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
#if 0
// Overrides above but seems to have little effect!
if (pConfiguration->canSetParameter(XMLUni::fgDOMWRTCanonicalForm, true))
pConfiguration->setParameter(XMLUni::fgDOMWRTCanonicalForm, true);
#endif
#if 1
//
if (pConfiguration->canSetParameter(XMLUni::fgDOMWRTEntities, true))
pConfiguration->setParameter(XMLUni::fgDOMWRTEntities, true);
#endif
#endif
LocalFileFormatTarget *pTarget = new LocalFileFormatTarget(DualString( xmlFile ).asXMLString());
pOutput->setByteStream(pTarget);
// mergeDocument->normalizeDocument(); // Needed?
pSerializer->write(mergeDocument, pOutput);
delete pTarget;
pOutput->release();
pSerializer->release();
} catch( const xercesc::XMLException& e ){
return -1;
}
return 0;
}
示例3: PrintXMLdoc
void PrintXMLdoc(const XERCES_CPP_NAMESPACE::DOMDocument* doc)
{
DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(L"Core");
DOMLSSerializer *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
DOMLSOutput *theOutputDesc = ((DOMImplementationLS*)impl)->createLSOutput();
DOMConfiguration* serializerConfig=theSerializer->getDomConfig();
if (serializerConfig->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
serializerConfig->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
XMLFormatTarget *outputStream = new StdOutFormatTarget();
theOutputDesc->setByteStream(outputStream);
theSerializer->write(doc, theOutputDesc);
theOutputDesc->release();
theSerializer->release();
delete outputStream;
}
示例4: Write
bool XMLIO::Write (DOMImplementation* impl, DOMNode* node, string filename) {
XMLFormatTarget* mft;
if (filename.empty())
mft = new StdOutFormatTarget();
else
mft = new LocalFileFormatTarget (StrX(filename).XMLchar());
// Xerces 2
#ifdef XSEC_XERCES_HAS_SETIDATTRIBUTE
DOMWriter* serializer = ((DOMImplementationLS*)impl)->createDOMWriter();
if (serializer->canSetFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true))
serializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
serializer->writeNode(mft, *node);
serializer->release();
#endif
#ifdef XSEC_XERCES_HAS_BOOLSETIDATTRIBUTE
DOMLSSerializer* serializer = ((DOMImplementationLS*) impl)->createLSSerializer();
DOMLSOutput* output = ((DOMImplementationLS*)impl)->createLSOutput();
DOMConfiguration* configuration = serializer->getDomConfig();
if (configuration->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
configuration->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
output->setByteStream (mft);
serializer->write(node, output);
output->release();
serializer->release();
#endif
return true;
}
示例5: save
//save the document to an external file
void ResultXML::save()
{
//create the serializer for saving the document
DOMLSSerializer *serializer = (DOMLSSerializer*)imp->createLSSerializer();
//configure for saving it in a well presented human readable format
if(serializer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true)){
serializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
}
//set the output for serializing as a stream
DOMLSOutput *output = ((DOMImplementationLS*)imp)->createLSOutput();
output->setByteStream(ftarget);
//use the serializer to save the document and catch any errors encountered
try{
serializer->write(root, output);
}
catch (const XMLException& e) {
char* msg = XMLString::transcode(e.getMessage());
cout << "Error Exception Encountered: " << endl << msg << endl;
XMLString::release(&msg);
}
catch (const DOMException& e) {
char* msg = XMLString::transcode(e.getMessage());
cout << "Error Exception Encountered: " << endl << msg << endl;
XMLString::release(&msg);
}
catch (...) {
cout << "Error Unknown Exception" << endl;
}
//force the release of resources held by the serializer and output manager
output->release();
serializer->release();
}
示例6: OutputXML
void OutputXML(xercesc::DOMDocument* pmyDOMDocument, std::string filePath)
{
//Return the first registered implementation that has the desired features. In this case, we are after a DOM implementation that has the LS feature... or Load/Save.
DOMImplementation *implementation = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("LS"));
// Create a DOMLSSerializer which is used to serialize a DOM tree into an XML document.
DOMLSSerializer *serializer = ((DOMImplementationLS*)implementation)->createLSSerializer();
// Make the output more human readable by inserting line feeds.
if (serializer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
serializer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
// The end-of-line sequence of characters to be used in the XML being written out.
serializer->setNewLine(XMLString::transcode("\r\n"));
// Convert the path into Xerces compatible XMLCh*.
XMLCh *tempFilePath = XMLString::transcode(filePath.c_str());
// Specify the target for the XML output.
XMLFormatTarget *formatTarget = new LocalFileFormatTarget(tempFilePath);
// Create a new empty output destination object.
DOMLSOutput *output = ((DOMImplementationLS*)implementation)->createLSOutput();
// Set the stream to our target.
output->setByteStream(formatTarget);
// Write the serialized output to the destination.
serializer->write(pmyDOMDocument, output);
// Cleanup.
serializer->release();
XMLString::release(&tempFilePath);
delete formatTarget;
output->release();
}
示例7: main
//.........这里部分代码省略.........
static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(gLS);
DOMLSParser *parser = ((DOMImplementationLS*)impl)->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
DOMConfiguration *config = parser->getDomConfig();
config->setParameter(XMLUni::fgDOMNamespaces, true);
config->setParameter(XMLUni::fgXercesSchema, true);
config->setParameter(XMLUni::fgXercesSchemaFullChecking, true);
if(config->canSetParameter(XMLUni::fgXercesDoXInclude, true)){
config->setParameter(XMLUni::fgXercesDoXInclude, true);
}
// enable datatype normalization - default is off
//config->setParameter(XMLUni::fgDOMDatatypeNormalization, true);
// And create our error handler and install it
XIncludeErrorHandler errorHandler;
config->setParameter(XMLUni::fgDOMErrorHandler, &errorHandler);
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc = 0;
try
{
// load up the test source document
XERCES_STD_QUALIFIER cerr << "Parse " << testFileName << " in progress ...";
parser->resetDocumentPool();
doc = parser->parseURI(testFileName);
XERCES_STD_QUALIFIER cerr << " finished." << XERCES_STD_QUALIFIER endl;
}
catch (const XMLException& toCatch)
{
XERCES_STD_QUALIFIER cerr << "\nError during parsing: '" << testFileName << "'\n"
<< "Exception message is: \n"
<< StrX(toCatch.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl;
}
catch (const DOMException& toCatch)
{
const unsigned int maxChars = 2047;
XMLCh errText[maxChars + 1];
XERCES_STD_QUALIFIER cerr << "\nDOM Error during parsing: '" << testFileName << "'\n"
<< "DOMException code is: " << toCatch.code << XERCES_STD_QUALIFIER endl;
if (DOMImplementation::loadDOMExceptionMsg(toCatch.code, errText, maxChars))
XERCES_STD_QUALIFIER cerr << "Message is: " << StrX(errText) << XERCES_STD_QUALIFIER endl;
}
catch (...)
{
XERCES_STD_QUALIFIER cerr << "\nUnexpected exception during parsing: '" << testFileName << "'\n";
}
if (!errorHandler.getSawErrors() && doc) {
DOMLSSerializer *writer = ((DOMImplementationLS*)impl)->createLSSerializer();
DOMLSOutput *theOutputDesc = ((DOMImplementationLS*)impl)->createLSOutput();
try {
// write out the results
XERCES_STD_QUALIFIER cerr << "Writing result to: " << outputFileName << XERCES_STD_QUALIFIER endl;
XMLFormatTarget *myFormTarget = new LocalFileFormatTarget(outputFileName);
theOutputDesc->setByteStream(myFormTarget);
writer->write(doc, theOutputDesc);
delete myFormTarget;
}
catch (const XMLException& toCatch)
{
XERCES_STD_QUALIFIER cerr << "\nXMLException during writing: '" << testFileName << "'\n"
<< "Exception message is: \n"
<< StrX(toCatch.getMessage()) << "\n" << XERCES_STD_QUALIFIER endl;
}
catch (const DOMException& toCatch)
{
const unsigned int maxChars = 2047;
XMLCh errText[maxChars + 1];
XERCES_STD_QUALIFIER cerr << "\nDOM Error during writing: '" << testFileName << "'\n"
<< "DOMException code is: " << toCatch.code << XERCES_STD_QUALIFIER endl;
if (DOMImplementation::loadDOMExceptionMsg(toCatch.code, errText, maxChars))
XERCES_STD_QUALIFIER cerr << "Message is: " << StrX(errText) << XERCES_STD_QUALIFIER endl;
}
catch (...)
{
XERCES_STD_QUALIFIER cerr << "\nUnexpected exception during writing: '" << testFileName << "'\n";
}
writer->release();
theOutputDesc->release();
}
//
// Delete the parser itself. Must be done prior to calling Terminate, below.
//
parser->release();
// And call the termination method
XMLPlatformUtils::Terminate();
return 0;
}
示例8: saveItemLists
void CTibiaItem::saveItemLists()
{
if (!xmlInitialised)
{
XMLPlatformUtils::Initialize();
xmlInitialised = 1;
}
XercesDOMParser *parser = new XercesDOMParser();
try
{
//int itemNr;
char pathBuf[2048];
sprintf(pathBuf, "%s\\data\\tibiaauto-items.xml", CInstallPath::getInstallPath().c_str());
DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("Core"));
xercesc::DOMDocument *doc = impl->createDocument(0, XMLString::transcode("item-definitions"), 0);
doc->createComment((const unsigned short *)"<!-- Tibia Items for Tibia -->");
DOMElement *root = doc->getDocumentElement();
//ITEMS
DOMNode *itemsNode = doc->createElement(XMLString::transcode("items"));
root->appendChild(itemsNode);
//recursively save data structure to XML
saveItemsBranch(itemsNode, itemTree, doc);
//FOOD
DOMNode *foodNode = doc->createElement(XMLString::transcode("foods"));
root->appendChild(foodNode);
{
int size = foodList.GetCount();
for (int i = 0; i < size; i++)
{
char buf[512];
DOMElement* itemElem = doc->createElement(XMLString::transcode("item"));
foodNode->appendChild(itemElem);
char* name = foodList.GetTextAtIndex(i);
int id = foodList.GetValueAtIndex(i);
int time = foodList.GetExtraInfoAtIndex(i);
sprintf(buf, "0x%x", id);
itemElem->setAttribute(XMLString::transcode("id"), XMLString::transcode(buf));
itemElem->setAttribute(XMLString::transcode("name"), XMLString::transcode(name));
sprintf(buf, "%d", time);
itemElem->setAttribute(XMLString::transcode("time"), XMLString::transcode(buf));
}
}
//CONSTS
/* never any need to save constants anymore
DOMNode *constsNode = doc->createElement(XMLString::transcode("consts"));
root->appendChild(constsNode);
int size = constCodeList.GetCount();
for (int i=0;i<size;i++){
char buf[512];
DOMElement* itemElem = doc->createElement(XMLString::transcode("const"));
constsNode->appendChild(itemElem);
char* code=constCodeList.GetTextAtIndex(i);
int value=constCodeList.GetValueAtIndex(i);
sprintf(buf, "0x%x", value);
itemElem->setAttribute(XMLString::transcode("value"), XMLString::transcode(buf));
itemElem->setAttribute(XMLString::transcode("code"), XMLString::transcode(code));
}
*/
XMLCh tempStr[100];
XMLString::transcode("LS", tempStr, 99);
impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
DOMLSSerializer* theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
DOMConfiguration* dc = theSerializer->getDomConfig();
if (dc->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
dc->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
XMLFormatTarget *outFile = new LocalFileFormatTarget(pathBuf);
DOMLSOutput *lsOut = ((DOMImplementationLS*)impl)->createLSOutput();
lsOut->setByteStream(outFile);
theSerializer->write(doc, lsOut);
theSerializer->release();
lsOut->release();
delete outFile;
}
catch (...)
{
AfxMessageBox("Unable to save item definitions!");
}
delete parser;
}
示例9: main
//.........这里部分代码省略.........
if (goutputfile)
myFormTarget=new LocalFileFormatTarget(goutputfile);
else
myFormTarget=new StdOutFormatTarget();
theOutputDesc->setByteStream(myFormTarget);
// get the DOM representation
DOMDocument *doc = parser->getDocument();
//
// do the serialization through DOMLSSerializer::write();
//
if(gXPathExpression!=NULL)
{
XMLCh* xpathStr=XMLString::transcode(gXPathExpression);
DOMElement* root = doc->getDocumentElement();
try
{
DOMXPathNSResolver* resolver=doc->createNSResolver(root);
DOMXPathResult* result=doc->evaluate(
xpathStr,
root,
resolver,
DOMXPathResult::ORDERED_NODE_SNAPSHOT_TYPE,
NULL);
XMLSize_t nLength = result->getSnapshotLength();
for(XMLSize_t i = 0; i < nLength; i++)
{
result->snapshotItem(i);
theSerializer->write(result->getNodeValue(), theOutputDesc);
}
result->release();
resolver->release ();
}
catch(const DOMXPathException& e)
{
XERCES_STD_QUALIFIER cerr << "An error occurred during processing of the XPath expression. Msg is:"
<< XERCES_STD_QUALIFIER endl
<< StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
retval = 4;
}
catch(const DOMException& e)
{
XERCES_STD_QUALIFIER cerr << "An error occurred during processing of the XPath expression. Msg is:"
<< XERCES_STD_QUALIFIER endl
<< StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
retval = 4;
}
XMLString::release(&xpathStr);
}
else
theSerializer->write(doc, theOutputDesc);
theOutputDesc->release();
theSerializer->release();
//
// Filter, formatTarget and error handler
// are NOT owned by the serializer.
//
delete myFormTarget;
delete myErrorHandler;
if (gUseFilter)
示例10: saveItemLists
void CTibiaItem::saveItemLists()
{
if (!xmlInitialised)
{
XMLPlatformUtils::Initialize();
xmlInitialised = 1;
}
char installPath[1024] = { '\0' };
unsigned long installPathLen = 1023;
HKEY hkey = NULL;
if (!RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Tibia Auto\\", 0, KEY_READ, &hkey))
{
RegQueryValueEx(hkey, TEXT("Install_Dir"), NULL, NULL, (unsigned char *)installPath, &installPathLen);
RegCloseKey(hkey);
}
if (!strlen(installPath))
{
AfxMessageBox("ERROR! Unable to read TA install directory! Please reinstall!");
PostQuitMessage(-1);
return;
}
XercesDOMParser *parser = new XercesDOMParser();
try
{
//int itemNr;
char pathBuf[2048];
sprintf(pathBuf, "%s\\data\\tibiaauto-items.xml", installPath);
DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("Core"));
xercesc::DOMDocument *doc = impl->createDocument(0, XMLString::transcode("item-definitions"), 0);
doc->createComment((const unsigned short *)"<!-- Tibia Items for Tibia -->");
DOMElement *root = doc->getDocumentElement();
//ITEMS
DOMNode *itemsNode = doc->createElement(XMLString::transcode("items"));
root->appendChild(itemsNode);
//recursively save data structure to XML
saveItemsBranch(itemsNode, itemTree, doc);
//FOOD
DOMNode *foodNode = doc->createElement(XMLString::transcode("foods"));
root->appendChild(foodNode);
{
int size = foodList.GetCount();
for (int i = 0; i < size; i++)
{
char buf[512];
DOMElement* itemElem = doc->createElement(XMLString::transcode("item"));
foodNode->appendChild(itemElem);
char* name = foodList.GetTextAtIndex(i);
int id = foodList.GetValueAtIndex(i);
int time = foodList.GetExtraInfoAtIndex(i);
sprintf(buf, "0x%x", id);
itemElem->setAttribute(XMLString::transcode("id"), XMLString::transcode(buf));
itemElem->setAttribute(XMLString::transcode("name"), XMLString::transcode(name));
sprintf(buf, "%d", time);
itemElem->setAttribute(XMLString::transcode("time"), XMLString::transcode(buf));
}
}
//CONSTS
/* never any need to save constants anymore
DOMNode *constsNode = doc->createElement(XMLString::transcode("consts"));
root->appendChild(constsNode);
int size = constCodeList.GetCount();
for (int i=0;i<size;i++){
char buf[512];
DOMElement* itemElem = doc->createElement(XMLString::transcode("const"));
constsNode->appendChild(itemElem);
char* code=constCodeList.GetTextAtIndex(i);
int value=constCodeList.GetValueAtIndex(i);
sprintf(buf, "0x%x", value);
itemElem->setAttribute(XMLString::transcode("value"), XMLString::transcode(buf));
itemElem->setAttribute(XMLString::transcode("code"), XMLString::transcode(code));
}
*/
XMLCh tempStr[100];
XMLString::transcode("LS", tempStr, 99);
impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
DOMLSSerializer* theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
DOMConfiguration* dc = theSerializer->getDomConfig();
if (dc->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
dc->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
XMLFormatTarget *outFile = new LocalFileFormatTarget(pathBuf);
DOMLSOutput *lsOut = ((DOMImplementationLS*)impl)->createLSOutput();
lsOut->setByteStream(outFile);
theSerializer->write(doc, lsOut);
theSerializer->release();
lsOut->release();
delete outFile;
}
//.........这里部分代码省略.........