本文整理汇总了C++中poco::xml::DOMParser类的典型用法代码示例。如果您正苦于以下问题:C++ DOMParser类的具体用法?C++ DOMParser怎么用?C++ DOMParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DOMParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: uri
Poco::AutoPtr<Poco::XML::Document> Twitter::invoke(const std::string& httpMethod, const std::string& twitterMethod, Poco::Net::HTMLForm& form)
{
// Create the request URI.
// We use the XML version of the Twitter API.
Poco::URI uri(_uri + twitterMethod + ".xml");
std::string path(uri.getPath());
Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());
Poco::Net::HTTPRequest req(httpMethod, path, Poco::Net::HTTPMessage::HTTP_1_1);
// Add username and password (HTTP basic authentication) to the request.
Poco::Net::HTTPBasicCredentials cred(_username, _password);
cred.authenticate(req);
// Send the request.
form.prepareSubmit(req);
std::ostream& ostr = session.sendRequest(req);
form.write(ostr);
// Receive the response.
Poco::Net::HTTPResponse res;
std::istream& rs = session.receiveResponse(res);
// Create a DOM document from the response.
Poco::XML::DOMParser parser;
parser.setFeature(Poco::XML::DOMParser::FEATURE_FILTER_WHITESPACE, true);
parser.setFeature(Poco::XML::XMLReader::FEATURE_NAMESPACES, false);
Poco::XML::InputSource source(rs);
Poco::AutoPtr<Poco::XML::Document> pDoc = parser.parse(&source);
// If everything went fine, return the XML document.
// Otherwise look for an error message in the XML document.
if (res.getStatus() == Poco::Net::HTTPResponse::HTTP_OK)
{
return pDoc;
}
else
{
std::string error(res.getReason());
Poco::AutoPtr<Poco::XML::NodeList> pList = pDoc->getElementsByTagName("error");
if (pList->length() > 0)
{
error += ": ";
error += pList->item(0)->innerText();
}
throw Poco::ApplicationException("Twitter Error", error);
}
}
示例2: LoadInputMappings
void Mapper::LoadInputMappings(const std::string &file)
{
if (boost::filesystem::exists(file) == false)
{
InputModuleOIS::LogInfo("Input mappings file not found, using default mappings.");
Export(file);
} else
{
InputModuleOIS::LogInfo("Loading input mappings from file " + file + "...");
try
{
Poco::XML::InputSource source(file);
Poco::XML::DOMParser parser;
Poco::XML::AutoPtr<Poco::XML::Document> document = parser.parse(&source);
if (!document.isNull())
{
Poco::XML::Node* node = document->firstChild();
if (node)
{
LoadInputMappings(node);
}
}
else
{
throw Exception("Failed to parse xml document.");
}
} catch (std::exception &e)
{
InputModuleOIS::LogInfo(e.what());
InputModuleOIS::LogInfo("Failed to parse input mappings file, using default mappings.");
}
}
}
示例3: in
XmlHandler::XmlHandler(std::string filename) {
std::ifstream in(filename);
Poco::XML::InputSource src(in);
Poco::XML::DOMParser parser;
pDoc = parser.parse(&src);
}
示例4: isValid
/* Validate all of the pipelines in the given config file.
* This method does some basic parsing of the config file to learn
* about the various pipelines that exist in the file.
*/
bool ValidatePipeline::isValid(const char *a_configPath) const
{
bool failed = false;
std::ifstream in(a_configPath);
if (!in) {
fprintf(stdout, "Error opening pipeline config file: %s\n", a_configPath);
} else {
try {
Poco::XML::InputSource src(in);
Poco::XML::DOMParser parser;
// basic parsing
Poco::AutoPtr<Poco::XML::Document> xmlDoc = parser.parse(&src);
// must have at least one pipeline element
Poco::AutoPtr<Poco::XML::NodeList> pipelines =
xmlDoc->getElementsByTagName(TskPipelineManager::PIPELINE_ELEMENT);
if (pipelines->length() == 0) {
fprintf(stdout, "No pipelines found in config file.\n");
} else {
// parse all pipelines in the config file
for (unsigned long i = 0; i < pipelines->length(); i++)
{
Poco::XML::Node * pNode = pipelines->item(i);
Poco::XML::Element* pElem = dynamic_cast<Poco::XML::Element*>(pNode);
Poco::XML::DOMWriter writer;
std::ostringstream pipelineXml;
writer.writeNode(pipelineXml, pNode);
std::string pipelineType = pElem->getAttribute(TskPipelineManager::PIPELINE_TYPE_ATTRIBUTE);
TskPipeline * pipeline = 0;
if (pipelineType == TskPipelineManager::FILE_ANALYSIS_PIPELINE_STR)
pipeline = new TskFileAnalysisPipeline();
else if (pipelineType == TskPipelineManager::REPORTING_PIPELINE_STR)
pipeline = new TskReportPipeline();
else {
fprintf(stdout, "Unsupported pipeline type: %s\n", pipelineType.c_str());
failed = true;
continue;
}
try {
pipeline->validate(pipelineXml.str());
} catch (...) {
fprintf(stdout, "Error parsing pipeline: %s\n", pElem->getAttribute(TskPipelineManager::PIPELINE_TYPE_ATTRIBUTE).c_str());
failed = true;
}
delete pipeline;
}
}
} catch (Poco::XML::SAXParseException& ex) {
fprintf(stderr, "Error parsing pipeline config file: %s (%s)\n", a_configPath, ex.what());
}
}
// If any of the pipelines failed validation we return false
return failed ? false : true;
}
示例5: convert
/**
Execution method to run the extraction.
@return implicit function if one could be found, or a NullImplicitFunction.
*/
Mantid::Geometry::MDImplicitFunction* vtkDataSetToImplicitFunction::execute()
{
using Mantid::Geometry::NullImplicitFunction;
using Mantid::Geometry::MDGeometryXMLDefinitions;
std::unique_ptr<Mantid::Geometry::MDImplicitFunction> function =
Mantid::Kernel::make_unique<NullImplicitFunction>();
FieldDataToMetadata convert;
std::string xmlString = convert(m_dataset->GetFieldData(), XMLDefinitions::metaDataId());
if (false == xmlString.empty())
{
Poco::XML::DOMParser pParser;
Poco::AutoPtr<Poco::XML::Document> pDoc = pParser.parseString(xmlString);
Poco::XML::Element* pRootElem = pDoc->documentElement();
Poco::XML::Element* functionElem = pRootElem->getChildElement(MDGeometryXMLDefinitions::functionElementName());
if(NULL != functionElem)
{
auto existingFunction =
std::unique_ptr<Mantid::Geometry::MDImplicitFunction>(
Mantid::API::ImplicitFunctionFactory::Instance()
.createUnwrapped(functionElem));
function.swap(existingFunction);
}
}
return function.release();
}
示例6: loadFromBuffer
//---------------------------------------------------------
bool ofXml::loadFromBuffer( const string& buffer )
{
Poco::XML::DOMParser parser;
// release and nullptr out if we already have a document
if(document) {
document->release();
}
try {
document = parser.parseString(buffer);
element = (Poco::XML::Element*) document->firstChild();
document->normalize();
return true;
} catch( const Poco::XML::SAXException & e ) {
ofLogError("ofXml") << "parse error: " << e.message();
document = new Poco::XML::Document;
element = document->documentElement();
return false;
} catch( const exception & e ) {
short msg = atoi(e.what());
ofLogError("ofXml") << "parse error: " << DOMErrorMessage(msg);
document = new Poco::XML::Document;
element = document->documentElement();
return false;
}
}
示例7: fromXMLString
/** Static method that sets the data inside this BoxController from an XML string
*
* @param xml :: string generated by BoxController::toXMLString()
*/
void BoxController::fromXMLString(const std::string & xml)
{
using namespace Poco::XML;
Poco::XML::DOMParser pParser;
Poco::AutoPtr<Poco::XML::Document> pDoc = pParser.parseString(xml);
Poco::XML::Element* pBoxElement = pDoc->documentElement();
std::string s;
s = pBoxElement->getChildElement("NumDims")->innerText();
Strings::convert(s, nd);
if (nd <= 0 || nd > 20) throw std::runtime_error("BoxController::fromXMLString(): Bad number of dimensions found.");
size_t ival;
Strings::convert(pBoxElement->getChildElement("MaxId")->innerText(), ival);
this->setMaxId(ival);
Strings::convert(pBoxElement->getChildElement("SplitThreshold")->innerText(), ival);
this->setSplitThreshold(ival);
Strings::convert(pBoxElement->getChildElement("MaxDepth")->innerText(), ival);
this->setMaxDepth(ival);
s = pBoxElement->getChildElement("SplitInto")->innerText();
this->m_splitInto = splitStringIntoVector<size_t>(s);
s = pBoxElement->getChildElement("NumMDBoxes")->innerText();
this->m_numMDBoxes = splitStringIntoVector<size_t>(s);
s = pBoxElement->getChildElement("NumMDGridBoxes")->innerText();
this->m_numMDGridBoxes = splitStringIntoVector<size_t>(s);
this->calcNumSplit();
}
示例8: parseRuninfo
/**
* Parse the runinfo file to find the names of the neutron event files.
*
* @param runinfo Runinfo file with full path.
* @param dataDir Directory where the runinfo file lives.
* @param eventFilenames vector of all possible event files. This is filled by
*the algorithm.
*/
void LoadPreNexus::parseRuninfo(const string &runinfo, string &dataDir,
vector<string> &eventFilenames) {
eventFilenames.clear();
// Create a Poco Path object for runinfo filename
Poco::Path runinfoPath(runinfo, Poco::Path::PATH_GUESS);
// Now lets get the directory
Poco::Path dirPath(runinfoPath.parent());
dataDir = dirPath.absolute().toString();
g_log.debug() << "Data directory \"" << dataDir << "\"\n";
std::ifstream in(runinfo.c_str());
Poco::XML::InputSource src(in);
Poco::XML::DOMParser parser;
Poco::AutoPtr<Poco::XML::Document> pDoc = parser.parse(&src);
Poco::XML::NodeIterator it(pDoc, Poco::XML::NodeFilter::SHOW_ELEMENT);
Poco::XML::Node *pNode = it.nextNode(); // root node
while (pNode) {
if (pNode->nodeName() == "RunInfo") // standard name for this type
{
pNode = pNode->firstChild();
while (pNode) {
if (pNode->nodeName() == "FileList") {
pNode = pNode->firstChild();
while (pNode) {
if (pNode->nodeName() == "DataList") {
pNode = pNode->firstChild();
while (pNode) {
if (pNode->nodeName() == "scattering") {
Poco::XML::Element *element =
static_cast<Poco::XML::Element *>(pNode);
eventFilenames.push_back(element->getAttribute("name"));
}
pNode = pNode->nextSibling();
}
} else // search for DataList
pNode = pNode->nextSibling();
}
} else // search for FileList
pNode = pNode->nextSibling();
}
} else // search for RunInfo
pNode = pNode->nextSibling();
}
// report the results to the log
if (eventFilenames.size() == 1) {
g_log.debug() << "Found 1 event file: \"" << eventFilenames[0] << "\"\n";
} else {
g_log.debug() << "Found " << eventFilenames.size() << " event files:";
for (auto &eventFilename : eventFilenames) {
g_log.debug() << "\"" << eventFilename << "\" ";
}
g_log.debug() << "\n";
}
}
示例9: load
void XMLConfiguration::load(Poco::XML::InputSource* pInputSource)
{
poco_check_ptr (pInputSource);
Poco::XML::DOMParser parser;
parser.setFeature(Poco::XML::XMLReader::FEATURE_NAMESPACES, false);
parser.setFeature(Poco::XML::DOMParser::FEATURE_FILTER_WHITESPACE, true);
Poco::XML::AutoPtr<Poco::XML::Document> pDoc = parser.parse(pInputSource);
load(pDoc);
}
开发者ID:babafall,项目名称:Sogeti-MasterThesis-CrossPlatformMobileDevelopment,代码行数:10,代码来源:XMLConfiguration.cpp
示例10: loadChannelList
void Configure::loadChannelList(void)
{
std::ifstream in(SystemInfo::instance().getExecutePath() + "\\config\\channelList.xml");
Poco::XML::InputSource src(in);
Poco::XML::DOMParser parser;
try
{
Poco::AutoPtr<Poco::XML::Document> pDoc = parser.parse(&src);
Poco::XML::NodeIterator it(pDoc, Poco::XML::NodeFilter::SHOW_ALL);
Poco::XML::Node* pNode = it.nextNode();
static int index = 0;
std::string channelInfo[3];
while (pNode)
{
if(pNode->nodeName() == "Row")
{
pNode = it.nextNode();
if(pNode->nodeName() != "#text")
{
continue; //No text node present
}
index = 0;
if(m_encodeChannel == channelInfo[1])
{
// 找到频道对照表
m_encodeChannelID = channelInfo[0];
m_encodeChannelPrefix = channelInfo[2];
LOG(INFO) << "get channel info : ID [" << m_encodeChannelID << "] Prefix[" << m_encodeChannelPrefix << "].";
return;
}
}
if(pNode->nodeName() == "Cell")
{
pNode = it.nextNode();
if(pNode->nodeName() != "#text")
{
pNode = it.nextNode();
continue; //No text node present
}
channelInfo[index++] = pNode->nodeValue();
}
pNode = it.nextNode();//指向下一个node
}
}
catch(std::exception& e)
{
LOG(ERROR) << "parse channelList xml file error." << e.what() ;
}
}
示例11: ParseXML
const bool BoardListXML::ParseXML(const std::string &xml)
{
bool parsed=false;
Poco::XML::DOMParser dp;
dp.setEntityResolver(0);
Initialize();
try
{
Poco::AutoPtr<Poco::XML::Document> doc=dp.parseString(FixCDATA(xml));
Poco::XML::Element *root=XMLGetFirstChild(doc,"BoardList");
Poco::XML::Element *boardel=NULL;
boardel=XMLGetFirstChild(root,"Board");
while(boardel)
{
std::string name="";
std::string description="";
Poco::XML::Element *txt=XMLGetFirstChild(boardel,"Name");
if(txt && txt->firstChild())
{
name=SanitizeSingleString(txt->firstChild()->getNodeValue());
StringFunctions::LowerCase(name,name);
}
txt=XMLGetFirstChild(boardel,"Description");
if(txt && txt->firstChild())
{
description=SanitizeSingleString(txt->firstChild()->getNodeValue());
}
if(name!="" && description!="")
{
m_boards.push_back(board(name,description));
}
boardel=XMLGetNextSibling(boardel,"Board");
}
parsed=true;
}
catch(...)
{
}
return parsed;
}
示例12: handleExtensions
void ExtensionPointService::handleExtensions(Bundle::ConstPtr pBundle, std::istream& istr, GenericHandler handler, Direction dir)
{
Poco::XML::DOMParser parser;
parser.setFeature(Poco::XML::XMLReader::FEATURE_NAMESPACES, false);
parser.setFeature(Poco::XML::DOMParser::FEATURE_FILTER_WHITESPACE, true);
Poco::XML::InputSource source(istr);
AutoPtr<Document> pDoc(parser.parse(&source));
Node* pRoot = pDoc->firstChild();
while (pRoot && pRoot->nodeName() != EXTENSIONS_ELEM)
{
pRoot = pRoot->nextSibling();
}
if (pRoot)
{
Node* pNode = (dir == DIR_FORWARD ? pRoot->firstChild() : pRoot->lastChild());
while (pNode)
{
if (pNode->nodeType() == Node::ELEMENT_NODE)
{
if (pNode->nodeName() == EXTENSION_ELEM)
{
Element* pElem = static_cast<Element*>(pNode);
const std::string& id = pElem->getAttribute(POINT_ATTR);
if (!id.empty())
{
(this->*handler)(pBundle, id, pElem);
}
else
{
_logger.error(std::string("No point attribute found in extension element of bundle ")
+ pBundle->symbolicName());
}
}
else
{
_logger.warning(std::string("Unsupported element '")
+ pNode->nodeName()
+ "' found in "
+ EXTENSIONS_XML
+ " of bundle "
+ pBundle->symbolicName());
}
}
pNode = (dir == DIR_FORWARD ? pNode->nextSibling() : pNode->previousSibling());
}
}
else throw Poco::NotFoundException("No extensions element found");
}
示例13: initializeXMLParser
/*
* Initalize Poco XML Parser
*/
void LoadGroupXMLFile::initializeXMLParser(const std::string &filename) {
const std::string xmlText = Kernel::Strings::loadFile(filename);
// Set up the DOM parser and parse xml file
Poco::XML::DOMParser pParser;
try {
m_pDoc = pParser.parseString(xmlText);
} catch (Poco::Exception &exc) {
throw Kernel::Exception::FileError(
exc.displayText() + ". Unable to parse File:", filename);
} catch (...) {
throw Kernel::Exception::FileError("Unable to parse File:", filename);
}
// Get pointer to root element
m_pRootElem = m_pDoc->documentElement();
if (!m_pRootElem->hasChildNodes()) {
throw Kernel::Exception::InstrumentDefinitionError(
"No root element in XML instrument file", filename);
}
}
示例14: ParseXML
const bool IdentityIntroductionXML::ParseXML(const std::string &xml)
{
FreenetSSKKey ssk;
bool parsed=false;
Poco::XML::DOMParser dp;
dp.setEntityResolver(0);
Initialize();
try
{
Poco::AutoPtr<Poco::XML::Document> doc=dp.parseString(FixCDATA(xml));
Poco::XML::Element *root=XMLGetFirstChild(doc,"IdentityIntroduction");
Poco::XML::Element *txt=NULL;
txt=XMLGetFirstChild(root,"Identity");
if(txt)
{
if(txt->firstChild())
{
m_identity=SanitizeSingleString(txt->firstChild()->getNodeValue());
if(ssk.TryParse(m_identity)==false)
{
return false;
}
m_identity=ssk.GetBaseKey();
}
}
parsed=true;
}
catch(...)
{
}
return parsed;
}
示例15: initialize
void TskPipeline::initialize(const std::string & pipelineConfig)
{
if (pipelineConfig.empty())
{
throw TskException("TskPipeline::initialize: Pipeline configuration string is empty.");
}
try
{
Poco::XML::DOMParser parser;
Poco::AutoPtr<Poco::XML::Document> xmlDoc = parser.parseString(pipelineConfig);
// Get all Module elements
Poco::AutoPtr<Poco::XML::NodeList> modules =
xmlDoc->getElementsByTagName(TskPipeline::MODULE_ELEMENT);
if (modules->length() == 0)
{
LOGWARN(L"TskPipeline::initialize - No modules found in config file.");
return;
}
// Size our list based on the number of modules
m_modules.resize(modules->length());
// Iterate through the module elements, make sure they are increasing order
// we now allow for gaps to make it easier to comment things out.
int prevOrder = -1;
for (unsigned int i = 0; i < modules->length(); i++)
{
Poco::XML::Node * pNode = modules->item(i);
Poco::XML::Element* pElem = dynamic_cast<Poco::XML::Element*>(pNode);
Poco::XML::XMLString orderStr = pElem->getAttribute(TskPipeline::MODULE_ORDER_ATTR);
if (orderStr == "") {
throw TskException("TskPipeline::initialize: Module order missing.");
}
int order;
try
{
order = Poco::NumberParser::parse(orderStr);
} catch (Poco::SyntaxException ex)
{
std::stringstream msg;
msg << "TskPipeline::initialize - Module order must a decimal number. Got " << orderStr.c_str();
throw TskException(msg.str());
}
if (order <= prevOrder)
{
std::stringstream msg;
msg << "TskPipeline::initialize - Expecting order bigger than " << prevOrder << ", got " << order;
throw TskException(msg.str());
}
prevOrder = order;
}
// Iterate through the module elements creating a new Module for each one
m_modules.clear();
for (unsigned int i = 0; i < modules->length(); i++)
{
Poco::XML::Node * pNode = modules->item(i);
Poco::XML::Element* pElem = dynamic_cast<Poco::XML::Element*>(pNode);
if (!pElem)
continue;
// Create a new module
TskModule * pModule = createModule(pElem);
if (pModule == NULL)
{
throw TskException("TskPipeline::initialize - Module creation failed.");
}
if (m_loadDll)
{
TskImgDB& imgDB = TskServices::Instance().getImgDB();
// Insert into Modules table
int moduleId = 0;
if (imgDB.addModule(pModule->getName(), pModule->getDescription(), moduleId))
{
std::stringstream errorMsg;
errorMsg << "TskPipeline::initialize - Failed to insert into Modules table. "
<< " module name=" << pModule->getName() ;
throw TskException(errorMsg.str());
}
else
{
pModule->setModuleId(moduleId);
m_moduleNames.insert(std::make_pair(moduleId, pModule->getName()));
m_moduleExecTimes.insert(std::make_pair(moduleId, Poco::Timespan()));
}
bool duplicate = false;
for (std::vector<TskModule*>::iterator it = m_modules.begin(); it != m_modules.end(); it++) {
if ((*it)->getModuleId() == pModule->getModuleId()) {
duplicate = true;
std::stringstream msg;
msg << "TskPipeline::initialize - " << pModule->getName() << " is a duplicate module. " <<
"The duplicate will not be added to the pipeline";
throw TskException(msg.str());
//.........这里部分代码省略.........