本文整理汇总了C++中DOMDocument::release方法的典型用法代码示例。如果您正苦于以下问题:C++ DOMDocument::release方法的具体用法?C++ DOMDocument::release怎么用?C++ DOMDocument::release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMDocument
的用法示例。
在下文中一共展示了DOMDocument::release方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_dispatcher
void test_dispatcher()
{
RefCountedPtr<SysContext> ctx(new SysContext);
RefCountedPtr<iSysComponent> cpt( new StdLogger( StdLogger::LOGC_DEBUG) );
ctx->addComponent( cpt );
// create the interfaces
RefCountedPtr<RpcInterface> intf( new RpcInterface( NTEXT("interface"), ctx ));
RefCountedPtr<RpcInterface> intf1( new RpcInterface( NTEXT("interface"), ctx ));
RefCountedPtr<RpcInterface> intf2( new RpcInterface( NTEXT("interface"), ctx ));
// create the methods
RefCountedPtr<Object1Method1> method(
new Object1Method1(NTEXT("method"), NTEXT("default")) );
intf->addMethod( (RefCountedPtr<iRpcMethod>&)method );
RefCountedPtr<Object1Method1> method1(
new Object1Method1(NTEXT("method"), NTEXT("apache")) );
intf1->addMethod( (RefCountedPtr<iRpcMethod>&)method1 );
RefCountedPtr<Object1Method1> method2(
new Object1Method1(NTEXT("method"), NTEXT("cslib")) );
intf2->addMethod( (RefCountedPtr<iRpcMethod>&)method2 );
RpcDispatcher disp( NTEXT("test-dispatcher"), ctx );
disp.addInterface( intf );
disp.addInterface( intf1, APACHE_TENANT );
disp.addInterface( intf2, CSLIB_TENANT );
DOMDocument* requestDoc = DomUtils::getDocument( NTEXT("rpc_dispatcher.xml") );
if (requestDoc != NULL)
{
StreamFormatTarget targ(COUT);
DOMDocument* responseDoc = DomUtils::createDocument( NTEXT("default") );
if (responseDoc != NULL)
{
disp.dispatch( requestDoc, responseDoc );
disp.dispatch( requestDoc, responseDoc, APACHE_TENANT );
disp.dispatch( requestDoc, responseDoc, CSLIB_TENANT );
disp.dispatch( requestDoc, responseDoc, INVALID_TENANT );
DomUtils::print( responseDoc, NTEXT("UTF-8"), targ );
responseDoc->release();
}
requestDoc->release();
}
}
示例2: loadData
void ItemDataLoader::loadData(string filename)
{
XMLPlatformUtils::Initialize();
XmlHelper::initializeTranscoder();
XercesDOMParser* parser = new XercesDOMParser();
parser->setValidationScheme(XercesDOMParser::Val_Always); // optional.
parser->setDoNamespaces(true); // optional
XmlPtr res = XmlResourceManager::getSingleton().create(filename,
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
res->parseBy(parser);
DOMDocument* doc = parser->getDocument();
DOMElement* dataDocumentContent = XmlHelper::getChildNamed(
doc->getDocumentElement(), "Inhalt");
initializeWeapons(XmlHelper::getChildNamed(dataDocumentContent, "Waffen"));
initializeArmors(XmlHelper::getChildNamed(dataDocumentContent, "Rüstungen"));
initializeItems(XmlHelper::getChildNamed(dataDocumentContent, "Gegenstände"));
doc->release();
res.setNull();
XmlResourceManager::getSingleton().remove(filename);
XMLPlatformUtils::Terminate();
}
示例3: Write
/* Write the file. */
bool GQCFileData::Write(const std::string &fileName)
{
// Initialize the XML4C2 system.
try
{
XMLPlatformUtils::Initialize();
}
catch (const XMLException&)
{
return false;
}
// Create a DOM implementation object and create the document type for it.
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(ToXMLCh(L"LS"));
DOMDocument* doc = impl->createDocument();
//doc->setStandalone(true);
// Create the serializer.
DOMLSSerializer *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
DOMLSOutput *theOutputDesc = ((DOMImplementationLS*)impl)->createLSOutput();
//theSerializer->setEncoding(ToXMLCh(GENERIC_REPORT_FILE_ENCODING));
theOutputDesc->setEncoding(ToXMLCh(GENERIC_REPORT_FILE_ENCODING));
// Create the root element
DOMElement *rootElement = CreateGenericReportElement(doc);
// store the parameters
AddNameValuePairs(ANALYSIS_PARAMETERS, analysisParameters, doc, rootElement);
AddNameValuePairs(QC_RESULTS, qcResults, doc, rootElement);
AddNameValuePairs(SAMPLE_SIGNATURE, sampleSignature, doc, rootElement);
// Add an empty table (required by the DTD)
AddBlankReportTable(doc, rootElement);
// Store the element to the document.
doc->appendChild(rootElement);
// Write the file.
bool status = false;
XMLFormatTarget *myFormTarget = new LocalFileFormatTarget(fileName.c_str());
theOutputDesc->setByteStream(myFormTarget);
try
{
theSerializer->write(doc, theOutputDesc);
status = true;
}
catch (...)
{
status = false;
}
// Clean up
doc->release();
theOutputDesc->release();
theSerializer->release();
delete myFormTarget;
XMLPlatformUtils::Terminate();
return status;
}
示例4: main
int main()
{
XMLPlatformUtils::Initialize();
// Populate vector of items
vector<Item> items;
items.push_back(Item(Product("Toaster", 29.95), 3));
items.push_back(Item(Product("Hair dryer", 24.95), 1));
// Build the DOM document
DOMImplementation* implementation
= DOMImplementation::getImplementation();
DOMDocument* doc = implementation->createDocument();
doc->setStandalone(true);
DOMElement* root = create_item_list(doc, items);
doc->appendChild(root);
// Print the DOM document
DOMWriter* writer = implementation->createDOMWriter();
writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
XMLFormatTarget* out = new StdOutFormatTarget();
writer->writeNode(out, *doc);
writer->release();
doc->release();
return 0;
}
示例5: WriteEntity
void EntityXMLFileWriter::WriteEntity(World* world, EntityID entity)
{
using namespace xercesc;
DOMDocument* doc = m_DOMImplementation->createDocument(nullptr, X("Entity"), nullptr);
DOMElement* root = doc->getDocumentElement();
root->setAttribute(X("xmlns:xsi"), X("http://www.w3.org/2001/XMLSchema-instance"));
root->setAttribute(X("xsi:noNamespaceSchemaLocation"), X("../Types/Entity.xsd"));
root->setAttribute(X("xmlns:c"), X("components"));
const std::string& name = world->GetName(entity);
if (!name.empty()) {
root->setAttribute(X("name"), X(name));
}
DOMElement* componentsElement = doc->createElement(X("Components"));
root->appendChild(componentsElement);
appentEntityComponents(componentsElement, world, entity);
DOMElement* childrenElement = doc->createElement(X("Children"));
root->appendChild(childrenElement);
appendEntityChildren(childrenElement, world, entity);
try {
LocalFileFormatTarget* target = new LocalFileFormatTarget(X(m_FilePath.string()));
DOMLSOutput* output = static_cast<DOMImplementationLS*>(m_DOMImplementation)->createLSOutput();
output->setByteStream(target);
m_DOMLSSerializer->write(doc, output);
delete target;
} catch (const std::runtime_error& e) {
LOG_ERROR("Failed to save \"%s\": %s", m_FilePath.c_str(), e.what());
}
doc->release();
}
示例6: xiu
XERCES_CPP_NAMESPACE_BEGIN
DOMDocument *
XIncludeDOMDocumentProcessor::doXIncludeDOMProcess(const DOMDocument * const source, XMLErrorReporter *errorHandler, XMLEntityHandler* entityResolver /*=NULL*/){
XIncludeUtils xiu(errorHandler);
DOMImplementation* impl = source->getImplementation();
DOMDocument *xincludedDocument = impl->createDocument();
try
{
/* set up the declaration etc of the output document to match the source */
xincludedDocument->setDocumentURI( source->getDocumentURI());
xincludedDocument->setXmlStandalone( source->getXmlStandalone());
xincludedDocument->setXmlVersion( source->getXmlVersion());
/* copy entire source document into the xincluded document. Xincluded document can
then be modified in place */
DOMNode *child = source->getFirstChild();
for (; child != NULL; child = child->getNextSibling()){
if (child->getNodeType() == DOMNode::DOCUMENT_TYPE_NODE){
/* I am simply ignoring these at the moment */
continue;
}
DOMNode *newNode = xincludedDocument->importNode(child, true);
xincludedDocument->appendChild(newNode);
}
DOMNode *docNode = xincludedDocument->getDocumentElement();
/* parse and include the document node */
xiu.parseDOMNodeDoingXInclude(docNode, xincludedDocument, entityResolver);
xincludedDocument->normalizeDocument();
}
catch(const XMLErrs::Codes)
{
xincludedDocument->release();
return NULL;
}
catch(...)
{
xincludedDocument->release();
throw;
}
return xincludedDocument;
}
示例7: loadData
void DsaDataLoader::loadData(string filename)
{
XMLPlatformUtils::Initialize();
XmlHelper::initializeTranscoder();
DOMDocument* doc = loadDataFile(filename);
DOMElement* dataDocumentContent = XmlHelper::getChildNamed(doc->getDocumentElement(), "Inhalt");
initializeTalente(XmlHelper::getChildNamed(dataDocumentContent, "Talente"));
initializeKampftechniken(XmlHelper::getChildNamed(dataDocumentContent, "Kampftechniken"));
initializePersonen(XmlHelper::getChildNamed(dataDocumentContent, "Personen"));
doc->release();
XMLPlatformUtils::Terminate();
}
示例8: writeXMLFile
//-----------------------------------------------------------------------
void XercesWriter::writeXMLFile(const XMLNode* root, const Ogre::String& filename)
{
XERCES_CPP_NAMESPACE_USE;
DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(L"Core");
DOMDocumentType* docType = NULL;
DOMDocument* doc = impl->createDocument(NULL, transcode(root->getName()).c_str(), docType);
populateDOMElement(root, doc->getDocumentElement());
LocalFileFormatTarget destination(filename.c_str());
DOMWriter* writer = impl->createDOMWriter();
writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
writer->writeNode(&destination, *doc);
writer->release();
doc->release();
}
示例9: evaluate
//.........这里部分代码省略.........
formatTarget->writeChars(buf, read, NULL);
read = bis->readBytes(buf, 1023);
}
}
}
else {
XENCEncryptedData *xenc = NULL;
// Encrypting
if (kek != NULL && key == NULL) {
XSECPlatformUtils::g_cryptoProvider->getRandom(keyBuf, 24);
XSECCryptoSymmetricKey * k =
XSECPlatformUtils::g_cryptoProvider->keySymmetric(XSECCryptoSymmetricKey::KEY_3DES_192);
k->setKey(keyBuf, 24);
cipher->setKey(k);
keyAlg = ENCRYPT_3DES_CBC;
keyStr = keyBuf;
keyLen = 24;
}
if (encryptFileAsData) {
// Create a BinInputStream
#if defined(XSEC_XERCES_REQUIRES_MEMMGR)
BinFileInputStream * is = new BinFileInputStream(filename, XMLPlatformUtils::fgMemoryManager);
#else
BinFileInputStream * is = new BinFileInputStream(filename);
#endif
xenc = cipher->encryptBinInputStream(is, keyAlg);
// Replace the document element
DOMElement * elt = doc->getDocumentElement();
doc->replaceChild(xenc->getElement(), elt);
elt->release();
}
else {
// Document encryption
cipher->encryptElement(doc->getDocumentElement(), keyAlg);
}
// Do we encrypt a created key?
if (kek != NULL && xenc != NULL) {
XENCEncryptedKey *xkey = cipher->encryptKey(keyStr, keyLen, kekAlg);
// Add to the EncryptedData
xenc->appendEncryptedKey(xkey);
}
}
if (doXMLOutput) {
// Output the result
XMLCh core[] = {
XERCES_CPP_NAMESPACE_QUALIFIER chLatin_C,
XERCES_CPP_NAMESPACE_QUALIFIER chLatin_o,
XERCES_CPP_NAMESPACE_QUALIFIER chLatin_r,
XERCES_CPP_NAMESPACE_QUALIFIER chLatin_e,
XERCES_CPP_NAMESPACE_QUALIFIER chNull
};
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(core);
#if defined (XSEC_XERCES_DOMLSSERIALIZER)
// DOM L3 version as per Xerces 3.0 API
DOMLSSerializer *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
Janitor<DOMLSSerializer> j_theSerializer(theSerializer);
示例10: loadKeyMapping
void InputManager::loadKeyMapping(const Ogre::String& filename)
{
using namespace XERCES_CPP_NAMESPACE;
using XERCES_CPP_NAMESPACE::DOMDocument;
using std::make_pair;
XMLPlatformUtils::Initialize();
XmlHelper::initializeTranscoder();
XercesDOMParser* parser = new XercesDOMParser();
parser->setValidationScheme(XercesDOMParser::Val_Always); // optional.
parser->setDoNamespaces(true); // optional
/* ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
parser->setErrorHandler(errHandler);*/
XMLCh* ALT = XMLString::transcode("AltChar");
XMLCh* SHIFT = XMLString::transcode("ShiftChar");
XMLCh* NORMAL = XMLString::transcode("NormalChar");
XMLCh* DESCR = XMLString::transcode("KeyDescription");
XMLCh* CODE = XMLString::transcode("KeyCode");
XMLCh* KEY = XMLString::transcode("Key");
XmlPtr res =
XmlResourceManager::getSingleton().create(
filename,
ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
res->parseBy(parser);
DOMDocument* doc = parser->getDocument();
DOMElement* dataDocumentContent = doc->getDocumentElement();
DOMNodeList* keymaps = dataDocumentContent->getElementsByTagName(KEY);
for (unsigned int idx = 0; idx < keymaps->getLength(); idx++)
{
DOMElement* key = static_cast<DOMElement*>(keymaps->item(idx));
int keycode = XMLString::parseInt(key->getAttribute(CODE));
const XMLCh* xmlch;
xmlch = key->getAttribute(NORMAL);
if (xmlch != NULL && XMLString::stringLen(xmlch) > 0)
{
CeGuiString s(XmlHelper::transcodeToString(xmlch));
mKeyMapNormal.insert(make_pair(keycode, s[0]));
}
xmlch = key->getAttribute(ALT);
if (xmlch != NULL && XMLString::stringLen(xmlch) > 0)
{
CeGuiString s(XmlHelper::transcodeToString(xmlch));
mKeyMapAlt.insert(make_pair(keycode, s[0]));
}
xmlch = key->getAttribute(SHIFT);
if (xmlch != NULL && XMLString::stringLen(xmlch) > 0)
{
CeGuiString s(XmlHelper::transcodeToString(xmlch));
mKeyMapShift.insert(make_pair(keycode, s[0]));
}
xmlch = key->getAttribute(DESCR);
mKeyNames.insert(make_pair(keycode, XmlHelper::transcodeToString(xmlch)));
}
XMLString::release(&ALT);
XMLString::release(&SHIFT);
XMLString::release(&NORMAL);
XMLString::release(&CODE);
XMLString::release(&DESCR);
XMLString::release(&KEY);
doc->release();
XMLPlatformUtils::Terminate();
//XmlResourceManager::getSingleton().remove(filename);
//res.setNull();
}
示例11: main
int main(int argC, char*[])
{
// Initialize the XML4C2 system.
try
{
XMLPlatformUtils::Initialize();
}
catch(const XMLException& toCatch)
{
char *pMsg = XMLString::transcode(toCatch.getMessage());
XERCES_STD_QUALIFIER cerr << "Error during Xerces-c Initialization.\n"
<< " Exception message:"
<< pMsg;
XMLString::release(&pMsg);
return 1;
}
// Watch for special case help request
int errorCode = 0;
if (argC > 1)
{
XERCES_STD_QUALIFIER cout << "\nUsage:\n"
" CreateDOMDocument\n\n"
"This program creates a new DOM document from scratch in memory.\n"
"It then prints the count of elements in the tree.\n"
<< XERCES_STD_QUALIFIER endl;
errorCode = 1;
}
if(errorCode) {
XMLPlatformUtils::Terminate();
return errorCode;
}
{
// Nest entire test in an inner block.
// The tree we create below is the same that the XercesDOMParser would
// have created, except that no whitespace text nodes would be created.
// <company>
// <product>Xerces-C</product>
// <category idea='great'>XML Parsing Tools</category>
// <developedBy>Apache Software Foundation</developedBy>
// </company>
DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(X("Core"));
if (impl != NULL)
{
try
{
DOMDocument* doc = impl->createDocument(
0, // root element namespace URI.
X("company"), // root element name
0); // document type object (DTD).
DOMElement* rootElem = doc->getDocumentElement();
DOMElement* prodElem = doc->createElement(X("product"));
rootElem->appendChild(prodElem);
DOMText* prodDataVal = doc->createTextNode(X("Xerces-C"));
prodElem->appendChild(prodDataVal);
DOMElement* catElem = doc->createElement(X("category"));
rootElem->appendChild(catElem);
catElem->setAttribute(X("idea"), X("great"));
DOMText* catDataVal = doc->createTextNode(X("XML Parsing Tools"));
catElem->appendChild(catDataVal);
DOMElement* devByElem = doc->createElement(X("developedBy"));
rootElem->appendChild(devByElem);
DOMText* devByDataVal = doc->createTextNode(X("Apache Software Foundation"));
devByElem->appendChild(devByDataVal);
//
// Now count the number of elements in the above DOM tree.
//
const XMLSize_t elementCount = doc->getElementsByTagName(X("*"))->getLength();
XERCES_STD_QUALIFIER cout << "The tree just created contains: " << elementCount
<< " elements." << XERCES_STD_QUALIFIER endl;
doc->release();
}
catch (const OutOfMemoryException&)
{
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
errorCode = 5;
}
catch (const DOMException& e)
{
XERCES_STD_QUALIFIER cerr << "DOMException code is: " << e.code << XERCES_STD_QUALIFIER endl;
errorCode = 2;
}
catch (...)
{
//.........这里部分代码省略.........
示例12: file
Triggerconf::Triggerconf(string _filename, bool _autocreateitems, bool _mustexist, bool _savechanges)
: file( _filename ), autocreate( _autocreateitems ), savechanges( _savechanges ) {
rootnode = NULL;
goodstate = true;
lasterror = "";
try {
XMLPlatformUtils::Initialize();
//
// if the file does not exists we create it with the root node
// but only if the constructor parameter is fine with this
//
FileHandle filehandle = XMLPlatformUtils::openFile (file.c_str ());
if (filehandle == NULL && _mustexist == false) {
static const XMLCh gLS [] = {chLatin_L, chLatin_S, chNull};
DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(gLS);
XMLCh* xroot = XMLString::transcode( ROOT_NAME );
DOMDocument* doc = impl->createDocument( 0, xroot, 0 );
DOMElement* elemrt = doc->getDocumentElement();
DOMLSSerializer* writer = ((DOMImplementationLS*)impl)->createLSSerializer();
XMLString::release (&xroot);
if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true))
writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint, true);
if (writer->getDomConfig()->canSetParameter(XMLUni::fgDOMWRTBOM, true))
writer->getDomConfig()->setParameter(XMLUni::fgDOMWRTBOM, true);
XMLFormatTarget* target = new LocalFileFormatTarget (file.c_str ());
target->flush();
DOMLSOutput* output = ((DOMImplementationLS*)impl)->createLSOutput();
output->setByteStream( target );
writer->write( elemrt, output );
writer->release();
doc->release();
delete output;
delete target;
} else if (filehandle == NULL && _mustexist == true) {
setError ("file " + file + " does not exist");
return;
} else {
XMLPlatformUtils::closeFile (filehandle);
}
//
// parse the file
//
parser = new XercesDOMParser ();
errhandler = (ErrorHandler*) new HandlerBase ();
parser->setErrorHandler (errhandler);
parser->parse (file.c_str ());
rootnode = getChildOfType (parser->getDocument (), DOMNode::ELEMENT_NODE);
if (rootnode != NULL) {
char* xmlstring = XMLString::transcode (rootnode->getNodeName ());
if (((string) ROOT_NAME).compare (xmlstring) == 0)
resetError();
else
setError("invalid root item in file " + file);
XMLString::release (&xmlstring);
} else
setError("parsing xml file " + file + " failed");
} catch (const XMLException& toCatch) {
char* message = XMLString::transcode (toCatch.getMessage());
setError ("failed parsing file " + file + ": " + message);
XMLString::release(&message);
}
catch (const DOMException& toCatch) {
char* message = XMLString::transcode (toCatch.msg);
setError ("failed parsing file " + file + ": " + message);
XMLString::release(&message);
}
catch (...) {
setError( "failed parsing file " + file );
}
}
示例13: writeXML
//.........这里部分代码省略.........
for(int i = 0; i < this->_dimensions.size(); i ++)
{
Dimension *tempDimension = this->getDimension(this->_dimensions[i]->getName());
cubeElem->appendChild(tempDimension->recursiveXML(doc));
}
}
XSchema *tempschema = this->getSchema();
DOMElement* schemaElem = doc->getDocumentElement();//create root
if(DataSource *tempDS = tempschema->getDataSource())
{
schemaElem -> appendChild(tempDS->recursiveXML(doc));
}
schemaElem -> appendChild(cubeElem);
}
catch (const OutOfMemoryException &)
{
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
return false;
}
catch (const DOMException& e)
{
XERCES_STD_QUALIFIER cerr << "DOMException code is: " << e.code << XERCES_STD_QUALIFIER endl;
return false;
}
catch (...)
{
XERCES_STD_QUALIFIER cerr << "An error occurred creating the document" << XERCES_STD_QUALIFIER endl;
return false;
}
}
else
{return false;}
//use DOMwriter for export XML file
//Writer Ini
bool bRet = true;
XMLCh tempStr[100];
XMLString::transcode("LS", tempStr, 99);
DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
DOMWriter *m_pWriter = ((DOMImplementationLS*)impl)->createDOMWriter();
//set XML File in "UTF-8"
XMLCh *encoding = XMLString::transcode("UTF-8");
m_pWriter -> setEncoding(encoding);
// DOMDocument* m_pDoc;
const char * outfile = outputfile.c_str();
XMLFormatTarget* m_pFormatTarget = new LocalFileFormatTarget(outfile);
// construct the LocalFileFormatTarget
// m_pFormatTarget = new LocalFileFormatTarget(szPath);
// serialize a DOMNode to the local file "myXMLFile.xml"
//Write File in UTF-8
bRet = m_pWriter->writeNode(m_pFormatTarget, *doc);
if (bRet == false)
{
return false;
}
else
{
try
{
// optionally, you can flush the buffer to ensure all contents are written
m_pFormatTarget->flush();
delete m_pFormatTarget;
delete m_DOMXmlParser1;
delete m_pWriter;
doc->release();
XMLPlatformUtils::Terminate();
return true;
}
catch (const OutOfMemoryException&)
{
XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
return false;
}
catch (XMLException& e)
{
XERCES_STD_QUALIFIER cerr << "An error occurred during creation of output transcoder. Msg is:"
<< XERCES_STD_QUALIFIER endl
<< XMLString::transcode(e.getMessage()) << XERCES_STD_QUALIFIER endl;
return false;
}
}
}
示例14: main
/**
* Main routine that utilizes Xercesc module to create a DOM object in memory
* and prints out the resultant DOM structure
* @param argC number of command line args
* @param argV name of command line args
* @return 0 if no errors occurred
*/
int main(int argC, char*argv[]) {
// Initialize the XML4C2 system.
try {
XMLPlatformUtils::Initialize();
} catch (const XMLException& toCatch) {
char *pMsg = XMLString::transcode(toCatch.getMessage());
XERCES_STD_QUALIFIER cerr << "Error during Xerces-c Initialization.\n" << " Exception message:" << pMsg;
XMLString::release(&pMsg);
return 1;
}
// Watch for special case help request
int errorCode = 0;
if (argC > 1) {
XERCES_STD_QUALIFIER
cout << "\nUsage:\n"
" CreateDOMDocument\n\n"
"This program creates a new DOM document from scratch in memory.\n"
"It then prints the count of elements in the tree.\n" << XERCES_STD_QUALIFIER
endl;
errorCode = 1;
}
if (errorCode) {
XMLPlatformUtils::Terminate();
return errorCode;
}
DOMImplementation* impl = DOMImplementationRegistry::getDOMImplementation(X("Core"));
if (impl != NULL) {
try {
// create a DomDocument instance
DOMDocument* doc = impl->createDocument(
0, // root element namespace URI.
X("TheHood"), // root element name
0); // document type object (DTD).
// create root attribute nodes
DOMAttr* woop_atr = doc->createAttribute(X("WOOP"));
woop_atr->setValue(X("DANG"));
DOMAttr* fiyah_atr = doc->createAttribute(X("FIYAH"));
fiyah_atr->setValue(X("hot"));
DOMAttr* hungry_atr = doc->createAttribute(X("hungry"));
hungry_atr->setValue(X("starving"));
// create root element
DOMElement* rootElem = doc->getDocumentElement();
// set root attrs
rootElem->setAttributeNode(woop_atr);
rootElem->setAttributeNode(fiyah_atr);
rootElem->setAttributeNode(hungry_atr);
//create root child elements
DOMElement* gangElem = doc->createElement(X("gang"));
rootElem->appendChild(gangElem);
DOMText* gangDataVal = doc->createTextNode(X("YoungThugz"));
gangElem->appendChild(gangDataVal);
gangElem->setAttribute(X("hardness"), X("rock"));
//create gang attr nodes
DOMAttr* members_atr = doc->createAttribute(X("members"));
members_atr->setValue(X("500"));
DOMAttr* color_atr = doc->createAttribute(X("color"));
color_atr->setValue(X("magenta"));
// set gang attr
gangElem->setAttributeNode(members_atr);
gangElem->setAttributeNode(color_atr);
// create gang elem children
DOMElement* piruElem = doc->createElement(X("piru"));
piruElem->setNodeValue(X("w"));
DOMElement* cripElem = doc->createElement(X("crip"));
cripElem->setNodeValue(X("t"));
DOMElement* trgElem = doc->createElement(X("trg"));
trgElem->setNodeValue(X("o"));
// append gang elem children
gangElem->appendChild(piruElem);
gangElem->appendChild(cripElem);
gangElem->appendChild(trgElem);
DOMElement* turfElem = doc->createElement(X("turf"));
rootElem->appendChild(turfElem);
turfElem->setAttribute(X("idea"), X("great"));
DOMText* turfDataVal = doc->createTextNode(X("West Side Projects"));
turfElem->appendChild(turfDataVal);
DOMElement* cliqueElem = doc->createElement(X("clique"));
rootElem->appendChild(cliqueElem);
DOMText* cliqueDataVal = doc->createTextNode(X("Balla$"));
cliqueElem->appendChild(cliqueDataVal);
cliqueElem->setAttribute(X("Comradery"), X("tight"));
DOMElement* sideElem = doc->createElement(X("side"));
//.........这里部分代码省略.........
示例15: process_xml
bool XmlWorldParser::process_xml(const char* xmlFile) {
try {
XMLPlatformUtils::Initialize();
} catch (const XMLException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
cout << "Error during initialization! :\n" << message << "\n";
XMLString::release(&message);
return 1;
}
XercesDOMParser* parser = new XercesDOMParser();
parser->setValidationScheme(XercesDOMParser::Val_Always);
parser->setDoNamespaces(true); // optional
/**
* Configure parser error handling
*/
ErrorHandler* errHandler = (ErrorHandler*) new HandlerBase();
// ErrorHandler *errHandler =(ErrorHandler*) new DOMPrintErrorHandler();
parser->setErrorHandler(errHandler);
try {
parser->parse(xmlFile);
} catch (const XMLException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
cout << "Exception message is: \n" << message << "\n";
XMLString::release(&message);
return -1;
} catch (const DOMException& toCatch) {
char* message = XMLString::transcode(toCatch.msg);
cout << "Exception message is: \n" << message << "\n";
XMLString::release(&message);
return -1;
} catch (const SAXException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
cout << "Exception message is: " << message << "\n";
XMLString::release(&message);
return -1;
} catch (const exception& toCatch) {
cout << "Unexpected Exception \n" << toCatch.what() << endl;
return -1;
}
/**
* Walk through the document, adding bodies and joints in their relative frames
*/
DOMDocument* doc = parser->getDocument();
DOMTreeWalker* walker = doc->createTreeWalker(doc->getDocumentElement(),
DOMNodeFilter::SHOW_ELEMENT, new BodiesInWorld(), true);
/** Initial world frame */
double transform[3] = { 0, 0, 0 };
processNode(walker, transform);
//TODO Ensure that I am cleaning up everything I need to
/** Clean up no longer needed resources **/
doc->release();
delete errHandler;
return true;
}