本文整理汇总了C++中poco::xml::Element类的典型用法代码示例。如果您正苦于以下问题:C++ Element类的具体用法?C++ Element怎么用?C++ Element使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Element类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例2: 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;
}
示例3: removeRaw
void XMLConfiguration::removeRaw(const std::string& key)
{
Poco::XML::Node* pNode = findNode(key);
if (pNode)
{
if (pNode->nodeType() == Poco::XML::Node::ELEMENT_NODE)
{
Poco::XML::Node* pParent = pNode->parentNode();
if (pParent)
{
pParent->removeChild(pNode);
}
}
else if (pNode->nodeType() == Poco::XML::Node::ATTRIBUTE_NODE)
{
Poco::XML::Attr* pAttr = dynamic_cast<Poco::XML::Attr*>(pNode);
Poco::XML::Element* pOwner = pAttr->ownerElement();
if (pOwner)
{
pOwner->removeAttributeNode(pAttr);
}
}
}
}
开发者ID:babafall,项目名称:Sogeti-MasterThesis-CrossPlatformMobileDevelopment,代码行数:25,代码来源:XMLConfiguration.cpp
示例4: removeAttributes
bool ofXml::removeAttributes(const string& path)
{
Poco::XML::Element *e;
if(element) {
if(path.find("[@") == string::npos) {
// we need to create a proper path
string attributePath = "[@" + path + "]";
e = (Poco::XML::Element*) element->getNodeByPath(attributePath);
} else {
e = (Poco::XML::Element*) element->getNodeByPath(path);
}
} else {
ofLogWarning("ofXml") << "clearAttributes(): no element set yet";
return false;
}
if(e) {
Poco::XML::NamedNodeMap *map = e->attributes();
for(unsigned long i = 0; i < map->length(); i++) {
e->removeAttribute(map->item(i)->nodeName());
}
map->release();
return true;
}
return false;
}
示例5: setToSibling
bool ofXml::setToSibling()
{
Poco::XML::Element *node;
if(element) {
node = (Poco::XML::Element*) element->nextSibling();
} else {
ofLogWarning("ofXml") << "setToSibling() << no element set yet";
return false;
}
/* If we get NULL for node, then we do not have a sibling.
We can only savely check the type on a non-Null node (thus
avoiding NULL-pointer dereferences). Empty space is treated
as a text node and we do not want that. We are also not
interessted in comments. If we find a non-TEXT_NODE or
non-COMMENT_NODE, we do not look further for a sibling. */
while(NULL != node){
if((node->nodeType() == Poco::XML::Node::TEXT_NODE)
|| (node->nodeType() == Poco::XML::Node::COMMENT_NODE)) {
node = (Poco::XML::Element*) node->nextSibling();
} else {
break;
}
}
// make sure we actually got a sibling
if(NULL == node) {
return false;
}
// we're cool now
element = node;
return true;
}
示例6: fillLiveData
/// Called from constructor to fill live listener name
void InstrumentInfo::fillLiveData(const Poco::XML::Element* elem)
{
// Get the first livedata element (will be NULL if there's none)
Poco::XML::Element * live = elem->getChildElement("livedata");
if ( live )
{
// Get the name of the listener - empty string will be returned if missing
m_liveListener = live->getAttribute("listener");
// Get the host+port. Would have liked to put straight into a Poco::Net::SocketAddress
// but that tries to contact the given address on construction, which won't always be possible (or scalable)
m_liveDataAddress = live->getAttribute("address");
// Warn rather than throw if there are problems with the address
if ( m_liveDataAddress.empty() )
{
g_log.warning() << "No connection details specified for live data listener of " << m_name << "\n";
}
// Check for a colon, which would suggest that a host & port are present
else if ( m_liveDataAddress.find(":") == std::string::npos )
{
g_log.warning() << "Live data address for " << m_name << " appears not to have both host and port specified.\n";
}
}
// Apply the facility default listener if none specified for this instrument
if ( m_liveListener.empty() )
{
m_liveListener = m_facility->liveListener();
}
}
示例7: 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";
}
}
示例8: fillComputeResources
/// Called from constructor to fill compute resources map
void FacilityInfo::fillComputeResources(const Poco::XML::Element* elem)
{
Poco::AutoPtr<Poco::XML::NodeList> pNL_compute = elem->getElementsByTagName("computeResource");
unsigned long n = pNL_compute->length();
for (unsigned long i = 0; i < n; i++)
{
Poco::XML::Element* elem = dynamic_cast<Poco::XML::Element*>(pNL_compute->item(i));
std::string name = elem->getAttribute("name");
m_computeResources.insert( std::make_pair(name, boost::shared_ptr<RemoteJobManager>(new RemoteJobManager(elem))));
}
}
示例9: 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();
}
示例10: removeAttribute
bool ofXml::removeAttribute(const string& path)
{
string attributeName, pathToAttribute;
Poco::XML::Element *e;
if(element) {
bool hasPath = false;
// you can pass either /node[@attr] or just attr
if(path.find("[@") != string::npos)
{
int attrBegin = path.find("[@");
int start = attrBegin + 2;
int end = path.find("]", start);
attributeName = path.substr( start, end - start );
pathToAttribute = path.substr(0, attrBegin);
hasPath = true;
}
else
{
attributeName = path;
}
if(hasPath) {
e = (Poco::XML::Element*) element->getNodeByPath(pathToAttribute);
} else {
e = element;
}
} else {
ofLogWarning("ofXml") << "clearAttributes(): no element set yet";
return false;
}
if(e) {
Poco::XML::NamedNodeMap *map = e->attributes();
for(unsigned long i = 0; i < map->length(); i++) {
if(map->item(i)->nodeName() == attributeName) {
e->removeAttribute(map->item(i)->nodeName());
}
}
map->release();
return true;
}
return false;
}
示例11: SaveState
void DebugBreakpointManager::SaveState(const Poco::Path& path) const
{
Poco::XML::Document* doc = new Poco::XML::Document();
Poco::XML::Element* breakpoints = doc->createElement(BREAKPOINTS_TAG);
doc->appendChild(breakpoints)->release();
for (std::set<unsigned long>::const_iterator i = m_ObjectBreakpoints.begin(); i
!= m_ObjectBreakpoints.end(); ++i)
{
Poco::XML::Element* objectBreakpoint = doc->createElement(OBJECT_TAG);
breakpoints->appendChild(objectBreakpoint)->release();
std::stringstream ss;
ss << *i;
objectBreakpoint->setAttribute(ID_ATTR, ss.str());
const Object* obj = DebugUtil::GetObject(*i);
if (obj)
{
objectBreakpoint->setAttribute(CLASSNAME_ATTR, obj->GetClassName());
}
}
for (Poco::HashMap<int, const Object*>::ConstIterator i =
m_SmartPointerBreakpoints.begin(); i != m_SmartPointerBreakpoints.end(); ++i)
{
Poco::XML::Element* spBreakpoint = doc->createElement(SMARTPOINTER_TAG);
breakpoints->appendChild(spBreakpoint)->release();
std::stringstream ss;
ss << i->first;
spBreakpoint->setAttribute(ID_ATTR, ss.str());
const Object* obj = i->second;
if (i->second)
{
spBreakpoint->setAttribute(CLASSNAME_ATTR, obj->GetClassName());
ss.clear();
ss << obj->GetTraceId();
spBreakpoint->setAttribute(OBJECTID_ATTR, ss.str());
}
}
Poco::FileOutputStream writer(path.toString());
Poco::XML::DOMWriter out;
out.setOptions(3); //write declaration and pretty print
out.writeNode(writer, doc);
doc->release();
}
示例12: pResult
Poco::XML::Node* XMLConfiguration::findAttribute(const std::string& name, Poco::XML::Node* pNode, bool create)
{
Poco::XML::Node* pResult(0);
Poco::XML::Element* pElem = dynamic_cast<Poco::XML::Element*>(pNode);
if (pElem)
{
pResult = pElem->getAttributeNode(name);
if (!pResult && create)
{
Poco::AutoPtr<Poco::XML::Attr> pAttr = pNode->ownerDocument()->createAttribute(name);
pElem->setAttributeNode(pAttr);
return pAttr;
}
}
return pResult;
}
开发者ID:babafall,项目名称:Sogeti-MasterThesis-CrossPlatformMobileDevelopment,代码行数:16,代码来源:XMLConfiguration.cpp
示例13: runtime_error
ImplicitFunctionParser *
ImplicitFunctionParserFactoryImpl::createImplicitFunctionParserFromXML(
Poco::XML::Element *functionElement) const {
const std::string &name = functionElement->localName();
if (name != "Function") {
throw std::runtime_error(
"Root node must be a Funtion element. Unable to determine parsers.");
}
Poco::XML::Element *typeElement = functionElement->getChildElement("Type");
std::string functionParserName = typeElement->innerText() + "Parser";
ImplicitFunctionParser *functionParser =
this->createUnwrapped(functionParserName);
Poco::XML::Element *parametersElement =
functionElement->getChildElement("ParameterList");
// Get the parameter parser for the current function parser and append that to
// the function parser.
ImplicitFunctionParameterParser *paramParser =
Mantid::API::ImplicitFunctionParameterParserFactory::Instance()
.createImplicitFunctionParameterParserFromXML(parametersElement);
functionParser->setParameterParser(paramParser);
Poco::AutoPtr<Poco::XML::NodeList> childFunctions =
functionElement->getElementsByTagName("Function");
ImplicitFunctionParser *childParser = nullptr;
for (unsigned long i = 0; i < childFunctions->length(); i++) {
// Recursive call to handle nested parameters.
ImplicitFunctionParser *tempParser = createImplicitFunctionParserFromXML(
dynamic_cast<Poco::XML::Element *>(childFunctions->item(i)));
if (i == 0) {
childParser = tempParser;
// Add the first child function parser to the parent (composite) directly.
functionParser->setSuccessorParser(childParser);
} else {
// Add all other function parsers are added as successors to those before
// them in the loop.
childParser->setSuccessorParser(tempParser);
childParser = tempParser;
}
}
return functionParser;
}
示例14: addChild
bool ofXml::addChild( const string& path )
{
vector<string> tokens;
if(path.find('/') != string::npos) {
tokens = tokenize(path, "/");
}
// is this a tokenized tag?
if(tokens.size() > 1)
{
// don't 'push' down into the new nodes
Poco::XML::Element *el = element;
vector<Poco::XML::Element*> toBeReleased;
for(std::size_t i = 0; i < tokens.size(); i++)
{
Poco::XML::Element *pe = getPocoDocument()->createElement(tokens.at(i));
el->appendChild(pe);
toBeReleased.push_back(pe);
el = pe;
}
if(element) {
element->appendChild(el);
} else {
element = el;
}
return true;
} else {
Poco::XML::Element* pe = getPocoDocument()->createElement(path);
if(element) {
element->appendChild(pe);
} else {
document->appendChild(pe);
element = document->documentElement();
}
}
return true;
}
示例15: fillArchiveNames
/// Called from constructor to fill archive interface names
void FacilityInfo::fillArchiveNames(const Poco::XML::Element *elem) {
Poco::AutoPtr<Poco::XML::NodeList> pNL_archives =
elem->getElementsByTagName("archive");
if (pNL_archives->length() > 1) {
g_log.error("Facility must have only one archive tag");
throw std::runtime_error("Facility must have only one archive tag");
} else if (pNL_archives->length() == 1) {
Poco::AutoPtr<Poco::XML::NodeList> pNL_interfaces =
elem->getElementsByTagName("archiveSearch");
for (unsigned int i = 0; i < pNL_interfaces->length(); ++i) {
Poco::XML::Element *elem =
dynamic_cast<Poco::XML::Element *>(pNL_interfaces->item(i));
std::string plugin = elem->getAttribute("plugin");
if (!plugin.empty()) {
m_archiveSearch.push_back(plugin);
}
}
}
}