本文整理汇总了C++中DOMDocument::getDocumentElement方法的典型用法代码示例。如果您正苦于以下问题:C++ DOMDocument::getDocumentElement方法的具体用法?C++ DOMDocument::getDocumentElement怎么用?C++ DOMDocument::getDocumentElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMDocument
的用法示例。
在下文中一共展示了DOMDocument::getDocumentElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parser
VGAuthError
SAMLVerifyAssertion(const char *xmlText,
SAMLTokenData &token,
vector<string> &certs)
{
XercesDOMParser parser(NULL, XMLPlatformUtils::fgMemoryManager, pool);
SAMLErrorHandler errorHandler;
SecurityManager sm;
parser.setErrorHandler(&errorHandler);
// prevent the billion laughs attack -- put a limit on entity expansions
sm.setEntityExpansionLimit(100);
parser.setSecurityManager(&sm);
DOMDocument *doc = SAMLValidateSchemaAndParse(parser, xmlText);
if (NULL == doc) {
return VGAUTH_E_AUTHENTICATION_DENIED;
}
const DOMElement *s = SAMLFindChildByName(doc->getDocumentElement(),
SAML_TOKEN_PREFIX"Subject");
if (NULL == s) {
Debug("Couldn't find " SAML_TOKEN_PREFIX " in token\n");
s = SAMLFindChildByName(doc->getDocumentElement(),
SAML_TOKEN_SSO_PREFIX"Subject");
if (NULL == s) {
Debug("Couldn't find " SAML_TOKEN_SSO_PREFIX " in token\n");
Warning("No recognized tags in token; punting\n");
return VGAUTH_E_AUTHENTICATION_DENIED;
} else {
Debug("Found " SAML_TOKEN_SSO_PREFIX " in token\n");
token.isSSOToken = true;
token.ns = SAML_TOKEN_SSO_PREFIX;
}
} else {
Debug("Found " SAML_TOKEN_PREFIX " in token\n");
token.isSSOToken = false;
token.ns = SAML_TOKEN_PREFIX;
}
if (!SAMLCheckSubject(doc, token)) {
return VGAUTH_E_AUTHENTICATION_DENIED;
}
if (!SAMLCheckConditions(doc, token)) {
return VGAUTH_E_AUTHENTICATION_DENIED;
}
if (!SAMLCheckSignature(doc, certs)) {
return VGAUTH_E_AUTHENTICATION_DENIED;
}
return VGAUTH_E_OK;
}
示例2: getDocumentRoot
DOMElement* ReadXml::getDocumentRoot(const char* xmlConfigFile)
{
DOMElement* root = NULL;
if (m_DOMXmlParser != NULL)
{
try
{
m_DOMXmlParser->parse(xmlConfigFile) ;
DOMDocument* xmlDoc = m_DOMXmlParser->getDocument();
root = xmlDoc->getDocumentElement(); // 取得根结点
if (root == NULL)
{
printf("empty XML document error\n");
}
}
catch(XMLException& excp)
{
string msg;
CXmlConfig::charArrayToString(excp.getMessage(), msg);
printf("parsing file error : %s\n", msg.c_str());
}
}
return root;
}
示例3: HandlerBase
map<string, DatasetSpecification> Specifications::readDatasetIndex(string str){
map<string, DatasetSpecification> result;
XERCES_CPP_NAMESPACE_USE
XMLPlatformUtils::Initialize();
XercesDOMParser parser;
parser.setValidationScheme(XercesDOMParser::Val_Always);
HandlerBase errHandler;// = (ErrorHandler*) new HandlerBase();
parser.setErrorHandler(&errHandler);
parser.parse(str.c_str());
DOMDocument * doc = parser.getDocument();
DOMElement* elementRoot = doc->getDocumentElement();
DOMNodeList *entries =
elementRoot->getElementsByTagName(XMLString::transcode("dataset"));
cout << "Databases in index:\n";
for(size_t i = 0; i < entries->getLength(); ++i){
DOMNode *current = entries->item(i);
DatasetSpecification dss;
dss.name = XMLString::transcode(current->getAttributes()->
getNamedItem(XMLString::transcode("name"))->
getNodeValue());
dss.root = XMLString::transcode(current->getAttributes()->
getNamedItem(XMLString::transcode("root"))->
getNodeValue());
cout << " name: " << dss.name << " root: " << dss.root << endl;
DOMNodeList *categories = current->getChildNodes();
for(size_t j = 0; j < categories->getLength(); ++j)
if((string) XMLString::transcode(categories->item(j)->getNodeName()) ==
"category")
dss.categories.push_back(XMLString::transcode(categories->item(j)->getTextContent()));
result[dss.name] = dss;
}
return result;
}
示例4: getWholeText
const XMLCh* DOMTextImpl::getWholeText() const
{
DOMDocument *doc = getOwnerDocument();
if (!doc) {
throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0, GetDOMNodeMemoryManager);
return 0;
}
DOMNode* root=doc->getDocumentElement();
DOMTreeWalker* pWalker=doc->createTreeWalker(root!=NULL?root:(DOMNode*)this, DOMNodeFilter::SHOW_ALL, NULL, true);
pWalker->setCurrentNode((DOMNode*)this);
// Logically-adjacent text nodes are Text or CDATASection nodes that can be visited sequentially in document order or in
// reversed document order without entering, exiting, or passing over Element, Comment, or ProcessingInstruction nodes.
DOMNode* prevNode;
while((prevNode=pWalker->previousNode())!=NULL)
{
if(prevNode->getNodeType()==ELEMENT_NODE || prevNode->getNodeType()==COMMENT_NODE || prevNode->getNodeType()==PROCESSING_INSTRUCTION_NODE)
break;
}
XMLBuffer buff(1023, GetDOMNodeMemoryManager);
DOMNode* nextNode;
while((nextNode=pWalker->nextNode())!=NULL)
{
if(nextNode->getNodeType()==ELEMENT_NODE || nextNode->getNodeType()==COMMENT_NODE || nextNode->getNodeType()==PROCESSING_INSTRUCTION_NODE)
break;
if(nextNode->getNodeType()==TEXT_NODE || nextNode->getNodeType()==CDATA_SECTION_NODE)
buff.append(nextNode->getNodeValue());
}
pWalker->release();
XMLCh* wholeString = (XMLCh*)((DOMDocumentImpl*)doc)->allocate((buff.getLen()+1) * sizeof(XMLCh));
XMLString::copyString(wholeString, buff.getRawBuffer());
return wholeString;
}
示例5: readFile
void Parameters::readFile(string str){
file = str;
XMLPlatformUtils::Initialize();
XercesDOMParser parser;
parser.setValidationScheme(XercesDOMParser::Val_Always);
HandlerBase errHandler;// = (ErrorHandler*) new HandlerBase();
parser.setErrorHandler(&errHandler);
parser.parse(str.c_str());
DOMDocument * doc = parser.getDocument();
DOMElement* elementRoot = doc->getDocumentElement();
// Extract floats
DOMElement* floatRoot = (DOMElement *)
elementRoot->getElementsByTagName(XMLString::transcode("real"))->item(0);
DOMElement* child = floatRoot->getFirstElementChild();
do{
saveReal(XMLString::transcode(child->getNodeName()),
atof(XMLString::transcode(child->getTextContent())));
child = child->getNextElementSibling();
}while(child != NULL);
// Extract integers
DOMElement* intRoot = (DOMElement *)
elementRoot->getElementsByTagName(XMLString::transcode("integer"))->item(0);
child = intRoot->getFirstElementChild();
do{
saveInteger(
XMLString::transcode(child->getNodeName()),
atoi(XMLString::transcode(child->getTextContent())));
child = child->getNextElementSibling();
}while(child != NULL);
}
示例6: 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();
}
示例7:
void XMLparser::parseConfigFile(std::string& configFile)
{
DOMElement *currentElement;
DOMElement *elementRoot;
DOMNode *currentNode;
DOMNodeList *children;
XMLSize_t nodeCount;
DOMDocument *xmlDoc;
this->ConfigFileParser_->parse(configFile.c_str());
xmlDoc = this->ConfigFileParser_->getDocument();
elementRoot = xmlDoc->getDocumentElement();
if (!elementRoot)
std::cerr << "empty XML document" << std::endl;
children = elementRoot->getChildNodes();
nodeCount = children->getLength();
for(XMLSize_t xx = 0; xx < nodeCount; ++xx)
{
currentNode = children->item(xx);
if(currentNode->getNodeType() &&
currentNode->getNodeType() == DOMNode::ELEMENT_NODE)
{
currentElement = dynamic_cast< xercesc::DOMElement* >(currentNode);
this->getAttributes(currentElement);
}
}
if (conf["port"].mValue.empty() || conf["thread-number"].mValue.empty() || conf["root-dir"].mValue.empty())
{
this->putDefaultValues();
}
}
示例8: test_serializable
void test_serializable()
{
StXmlOpener opener;
RefCountedPtr<SysContext> ctx(new SysContext);
DOMDocument* doc = DomUtils::getDocument( NTEXT("sertest.xml") );
if ( doc != NULL )
{
// construct the system counter manager
SerSerializationMgr theMgr;
// load the xml counter document
DOMElement* root = doc->getDocumentElement();
int res = theMgr.init( root, ctx );
res = theMgr.postInit( root, ctx );
if ( res == 0 )
{
// allocate the source data
MasterStructContainer sourceContainer;
createData( sourceContainer );
COUT << NTEXT("---------------- doFileBased reference data --------------") << std::endl;
print( sourceContainer );
COUT << NTEXT("---------------- doFileBased reference data --------------") << std::endl;
do_filebased( theMgr, sourceContainer );
do_membased( theMgr, sourceContainer );
// finally, test the copy function
MasterStructContainer theCopyContainer;
time_t startt, endt;
startt = ::time(NULL);
if ( theMgr.copy( sourceContainer, theCopyContainer ) == 0 )
{
endt = ::time(NULL);
COUT <<
NTEXT("Copied a serializable world in: ") <<
endt-startt << NTEXT(" seconds") << std::endl;
print( theCopyContainer );
}
else
{
CERR << NTEXT("problem copying the object world") << std::endl;
}
delete doc;
}
else
{
CERR << NTEXT("problem initializing the SerSerializationMgr object") << std::endl;
}
}
else
{
CERR << NTEXT("Could not parse: 'sertest.xml'") << std::endl;
}
}
示例9: readGenerations
void Generation::readGenerations(const string &file,
vector<GenerationPtr> &generations) {
XMLPlatformUtils::Initialize();
XercesDOMParser parser;
GenerationErrorHandler handler;
parser.setErrorHandler(&handler);
parser.setEntityResolver(&handler);
parser.parse(file.c_str());
DOMDocument *doc = parser.getDocument();
DOMElement *root = doc->getDocumentElement();
XMLCh tempStr[12];
XMLString::transcode("generation", tempStr, 11);
DOMNodeList *list = root->getElementsByTagName(tempStr);
int length = list->getLength();
for (int i = 0; i < length; ++i) {
DOMElement *item = (DOMElement *)list->item(i);
GenerationPtr generation(new Generation());
generation->m_impl->m_owner = generation.get();
generation->m_impl->getGeneration(item);
generation->m_impl->m_idx = i;
generations.push_back(generation);
}
}
示例10: xmlParser
xercesc::DOMElement* DWXML::xmlParser(const std::string & xmlFile) throw( std::runtime_error )
{
//获取文件信息状态
//配置DOMParser
m_DOMXmlParser->setValidationScheme( XercesDOMParser::Val_Auto );
m_DOMXmlParser->setDoNamespaces( false );
m_DOMXmlParser->setDoSchema( false );
m_DOMXmlParser->setLoadExternalDTD( false );
try
{
//调用 Xerces C++ 类库提供的解析接口
m_DOMXmlParser->parse(xmlFile.c_str()) ;
//获得DOM树
DOMDocument* xmlDoc = m_DOMXmlParser->getDocument();
DOMElement* pRoot = xmlDoc->getDocumentElement();
if (!pRoot )
{
throw(std::runtime_error( "empty XML document" ));
}
return pRoot;
}
catch( xercesc::XMLException& excp )
{
char* msg = xercesc::XMLString::transcode( excp.getMessage() );
ostringstream errBuf;
errBuf << "Error parsing file: " << msg << flush;
XMLString::release( &msg );
}
return NULL;
}
示例11: 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();
}
示例12: setConfig
void ReadXml::setConfig(const char* xmlConfigFile, IXmlConfigBase& configVal)
{
configVal.__isSetConfigValueSuccess__ = false;
if (m_DOMXmlParser == NULL) return;
if (xmlConfigFile == NULL || *xmlConfigFile == '\0')
{
printf("XML file name is null\n");
return;
}
struct stat fInfo;
if (stat(xmlConfigFile, &fInfo) != 0)
{
printf("check XML file error, name = %s, error code = %d\n", xmlConfigFile, errno);
return;
}
try
{
m_DOMXmlParser->parse(xmlConfigFile) ;
DOMDocument* xmlDoc = m_DOMXmlParser->getDocument();
if (xmlDoc == NULL)
{
printf("parse XML document error, file name = %s\n", xmlConfigFile);
return;
}
DOMElement* root = xmlDoc->getDocumentElement(); // 取得根结点
if (root == NULL)
{
printf("empty XML document error, file name = %s\n", xmlConfigFile);
return;
}
DomNodeArray parentNode;
CXmlConfig::getNode((DOMNode*)root, MainType, MainValue, parentNode);
if (parentNode.size() < 1)
{
printf("can not find main config value error, file name = %s\n", xmlConfigFile);
return;
}
configVal.set(parentNode[0]);
configVal.__isSetConfigValueSuccess__ = true;
}
catch(XMLException& excp)
{
string msg;
CXmlConfig::charArrayToString(excp.getMessage(), msg);
printf("parsing xml file error, name = %s, msg = %s\n", xmlConfigFile, msg.c_str());
}
}
示例13: LoadException
/**
* TODO: JavaDocs
*
* @throws LoadException
*/
ConnectionTemplate *XMLConnectionTemplateLoader::loadConnectionTemplate(
istream &inStream) const {
DOMDocument *document;
try {
document = Utils::DOM::parseDocumentFromStream(inStream);
document->normalizeDocument();
removeWhitespaceTextNodes(document->getDocumentElement());
} catch (const DOMParseException &ex) {
throw LoadException("XMLException, see above");
}
try {
XMLConnectionTemplate *result = new XMLConnectionTemplate();
result->fromXML(document->getDocumentElement());
return result;
} catch (const XMLReadable::XMLSerializationException &ex) {
Log::error(LOG_LOCATION("XMLConnectionTemplateLoader",
"loadConnectionTemplate"),
"Got XMLSerializationException while creating "
"template...");
throw LoadException(ex.what());
}
}
示例14: 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;
}
示例15: 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();
}