本文整理汇总了C++中poco::xml::DOMParser::parseString方法的典型用法代码示例。如果您正苦于以下问题:C++ DOMParser::parseString方法的具体用法?C++ DOMParser::parseString怎么用?C++ DOMParser::parseString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类poco::xml::DOMParser
的用法示例。
在下文中一共展示了DOMParser::parseString方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: 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;
}
}
示例4: 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;
}
示例5: 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);
}
}
示例6: 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;
}
示例7: svgtiny_parse
svgtiny_code svgtiny_parse(struct svgtiny_diagram *diagram,
const char *buffer, size_t size, const char *url,
int viewport_width, int viewport_height)
{
Poco::XML::Document *document;
//Poco::XML::Element *svg;
Poco::XML::Element *svg;
struct svgtiny_parse_state state;
float x, y, width, height;
svgtiny_code code;
assert(diagram);
assert(buffer);
assert(url);
std::string str(buffer);
Poco::XML::DOMParser parser;
document = parser.parseString(str);
svg = document->documentElement();
//std::cout << svg->localName() << std::endl;
if (!svg)
return svgtiny_NOT_SVG;
if (svg->localName().compare("svg") != 0)
return svgtiny_NOT_SVG;
/* get graphic dimensions */
state.diagram = diagram;
state.document = document;
state.viewport_width = viewport_width;
state.viewport_height = viewport_height;
svgtiny_parse_position_attributes(svg, state, &x, &y, &width, &height);
diagram->width = width;
diagram->height = height;
/* set up parsing state */
state.viewport_width = width;
state.viewport_height = height;
state.ctm.a = 1; /*(float) viewport_width / (float) width;*/
state.ctm.b = 0;
state.ctm.c = 0;
state.ctm.d = 1; /*(float) viewport_height / (float) height;*/
state.ctm.e = 0; /*x;*/
state.ctm.f = 0; /*y;*/
/*state.style = css_base_style;
state.style.font_size.value.length.value = option_font_size * 0.1;*/
state.fill = 0x000000;
state.stroke = svgtiny_TRANSPARENT;
state.stroke_width = 1;
state.linear_gradient_stop_count = 0;
/* parse tree */
code = svgtiny_parse_svg(svg, state, diagram);
/* free XML tree */
//xmlFreeDoc(document);
return code;
}
示例8: ParseXML
const bool MessageXML::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,"Message");
Poco::XML::Element *txt=NULL;
txt=XMLGetFirstChild(root,"Date");
if(txt)
{
if(txt->firstChild())
{
m_date=SanitizeSingleString(txt->firstChild()->getNodeValue());
}
}
txt=XMLGetFirstChild(root,"Time");
if(txt)
{
if(txt->firstChild())
{
m_time=SanitizeSingleString(txt->firstChild()->getNodeValue());
}
}
txt=XMLGetFirstChild(root,"Subject");
if(txt)
{
if(txt->firstChild())
{
m_subject=SanitizeSingleString(txt->firstChild()->getNodeValue());
}
}
txt=XMLGetFirstChild(root,"MessageID");
if(txt)
{
if(txt->firstChild())
{
m_messageid=SanitizeSingleString(txt->firstChild()->getNodeValue());
}
}
txt=XMLGetFirstChild(root,"ReplyBoard");
if(txt)
{
if(txt->firstChild())
{
m_replyboard=SanitizeSingleString(txt->firstChild()->getNodeValue());
// strip off everything after , in board name
if(m_replyboard.find(',')!=std::string::npos)
{
m_replyboard.erase(m_replyboard.find(','));
}
m_replyboard=Board::FixBoardName(m_replyboard);
}
}
txt=XMLGetFirstChild(root,"Body");
if(txt)
{
if(txt->firstChild())
{
m_body=txt->firstChild()->getNodeValue();
}
}
Poco::XML::Element *boards=XMLGetFirstChild(root,"Boards");
if(boards)
{
Poco::XML::Element *board=XMLGetFirstChild(boards,"Board");
while(board)
{
if(board->firstChild())
{
std::string boardname=SanitizeSingleString(board->firstChild()->getNodeValue());
// strip off everything after , in board name
if(boardname.find(',')!=std::string::npos)
{
boardname.erase(boardname.find(','));
}
boardname=Board::FixBoardName(boardname);
m_boards.push_back(boardname);
}
board=XMLGetNextSibling(board,"Board");
}
}
Poco::XML::Element *inreplyto=XMLGetFirstChild(root,"InReplyTo");
if(inreplyto)
{
Poco::XML::Element *message=XMLGetFirstChild(inreplyto,"Message");
while(message)
{
Poco::XML::Element *orderel=XMLGetFirstChild(message,"Order");
Poco::XML::Element *messageidel=XMLGetFirstChild(message,"MessageID");
if(orderel && orderel->firstChild() && messageidel && messageidel->firstChild())
{
int order=-1;
//.........这里部分代码省略.........
示例9: svgtiny_parse
svgtiny_code svgtiny_parse(svgInfo &info,struct svgtiny_diagram *diagram, const char *buffer,int viewport_width, int viewport_height){
Poco::XML::Document *document;
Poco::XML::Element *svg;
struct svgtiny_parse_state state;
float x, y, width, height;
svgtiny_code code;
assert(diagram);
assert(buffer);
string rawXMLstring(buffer);
//info.rawXML = rawXMLstring;
//parser is statically allocated
Poco::XML::DOMParser parser;
/*
Why does this upset the internal SVG parser?
*/
//parser.setFeature(Poco::XML::XMLReader::FEATURE_NAMESPACES, false);
document = parser.parseString(rawXMLstring);
svg = document->documentElement();
//std::cout << svg->localName() << std::endl;
if (!svg){
code = svgtiny_NOT_SVG;
return code;
}else if(svg->localName().compare("svg") != 0){
code= svgtiny_NOT_SVG;
return code;
}else{
/* get graphic dimensions */
state.diagram = diagram;
state.document = document;
state.viewport_width = viewport_width;
state.viewport_height = viewport_height;
svgtiny_parse_position_attributes(svg, state, &x, &y, &width, &height);
diagram->width = width;
diagram->height = height;
/* set up parsing state */
state.viewport_width = width;
state.viewport_height = height;
state.ctm.a = 1; /*(float) viewport_width / (float) width;*/
state.ctm.b = 0;
state.ctm.c = 0;
state.ctm.d = 1; /*(float) viewport_height / (float) height;*/
state.ctm.e = 0; /*x;*/
state.ctm.f = 0; /*y;*/
/*state.style = css_base_style;
state.style.font_size.value.length.value = option_font_size * 0.1;*/
state.fill = 0x000000;
state.stroke = svgtiny_TRANSPARENT;
state.stroke_width = 1;
state.linear_gradient_stop_count = 0;
//borg
state.info = &info;
/* parse tree */
ofPtr<svgNode> rootnode(new svgNode());
rootnode->type = SVG_TAG_TYPE_DOCUMENT;
info.rootnode = rootnode;
//store root svg info
info.width = ofToString(svg->getAttribute("width").c_str());
info.height = ofToString(svg->getAttribute("height").c_str());
info.x = ofToString(svg->getAttribute("x").c_str());
info.y = ofToString(svg->getAttribute("y").c_str());
info.viewbox = ofToString(svg->getAttribute("viewBox").c_str());
info.id = ofToString(svg->getAttribute("id").c_str());
info.xmlns = ofToString(svg->getAttribute("xmlns").c_str());
info.version = ofToString(svg->getAttribute("version").c_str());
info.preserveAspectRatio = ofToString(svg->getAttribute("preserveAspectRatio").c_str());
code = svgtiny_parse_svg(info,svg, state,rootnode);
}
//.........这里部分代码省略.........
示例10: ParseXML
const bool SoneXML::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,"sone");
Poco::XML::Element *posts=NULL;
Poco::XML::Element *replies=NULL;
Poco::XML::Element *txt=NULL;
Poco::XML::Element *profile=NULL;
Poco::XML::Element *albums=NULL;
if(root)
{
posts=XMLGetFirstChild(root,"posts");
replies=XMLGetFirstChild(root,"replies");
profile=XMLGetFirstChild(root,"profile");
albums=XMLGetFirstChild(root,"albums");
}
if(posts)
{
txt=XMLGetFirstChild(posts,"post");
while(txt)
{
std::string id("");
std::string timestr("");
Poco::Timestamp::TimeVal timeval;
Poco::DateTime messagetime;
std::string messagetext("");
Poco::XML::Element *el;
el=XMLGetFirstChild(txt,"id");
if(el && el->firstChild())
{
id=el->firstChild()->getNodeValue();
}
el=XMLGetFirstChild(txt,"time");
if(el && el->firstChild())
{
timestr=el->firstChild()->getNodeValue();
StringFunctions::Convert(timestr,timeval);
messagetime=Poco::Timestamp(timeval*static_cast<Poco::Timestamp::TimeVal>(1000));
}
el=XMLGetFirstChild(txt,"text");
if(el && el->firstChild())
{
messagetext=el->firstChild()->getNodeValue();
}
if(id!="" && messagetext!="")
{
m_messages.push_back(message(messagetime,id,std::string(""),messagetext));
}
txt=XMLGetNextSibling(txt,"post");
}
}
if(replies)
{
txt=XMLGetFirstChild(replies,"reply");
while(txt)
{
std::string id("");
std::string replyto("");
std::string timestr("");
Poco::Timestamp::TimeVal timeval;
Poco::DateTime messagetime;
std::string messagetext("");
Poco::XML::Element *el;
el=XMLGetFirstChild(txt,"id");
if(el && el->firstChild())
{
id=el->firstChild()->getNodeValue();
}
el=XMLGetFirstChild(txt,"post-id");
if(el && el->firstChild())
{
replyto=el->firstChild()->getNodeValue();
}
el=XMLGetFirstChild(txt,"time");
if(el && el->firstChild())
{
timestr=el->firstChild()->getNodeValue();
StringFunctions::Convert(timestr,timeval);
//.........这里部分代码省略.........
示例11: 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());
//.........这里部分代码省略.........
示例12: execute
/**
Peforms the processing associated with these transformations.
*/
void MDGeometryXMLParser::execute() {
Poco::XML::DOMParser pParser;
Poco::AutoPtr<Poco::XML::Document> pDoc = pParser.parseString(m_xmlToProcess);
Poco::XML::Element *pRootElem = pDoc->documentElement();
// Apply root node checking if supplied.
Poco::XML::Element *geometryXMLElement = nullptr;
if (!m_rootNodeName.empty()) {
Poco::XML::Element *temp = pRootElem->getChildElement(m_rootNodeName);
geometryXMLElement = temp;
if (geometryXMLElement == nullptr) {
std::string message =
"Root node was not found to be the expected value of " +
m_rootNodeName;
throw std::runtime_error(message);
}
} else {
// The default is to take the root node to be the geometry xml element.
geometryXMLElement = pRootElem;
}
Poco::AutoPtr<Poco::XML::NodeList> dimensionsXML =
geometryXMLElement->getElementsByTagName(
MDGeometryXMLDefinitions::workspaceDimensionElementName());
size_t nDimensions = dimensionsXML->length();
VecIMDDimension_sptr vecAllDims(nDimensions);
////Extract dimensions
for (size_t i = 0; i < nDimensions; i++) {
Poco::XML::Element *dimensionXML = static_cast<Poco::XML::Element *>(
dimensionsXML->item(static_cast<unsigned long>(i)));
vecAllDims[i] = createDimension(*dimensionXML);
}
VecIMDDimension_sptr vecNonMappedDims = vecAllDims;
Poco::XML::Element *xDimensionElement = geometryXMLElement->getChildElement(
MDGeometryXMLDefinitions::workspaceXDimensionElementName());
std::string xDimId =
xDimensionElement
->getChildElement(
MDGeometryXMLDefinitions::workspaceRefDimensionElementName())
->innerText();
if (!xDimId.empty()) {
auto xDimensionIt =
find_if(vecAllDims.begin(), vecAllDims.end(), findID(xDimId));
if (xDimensionIt == vecAllDims.end()) {
throw std::invalid_argument("Cannot determine x-dimension mapping.");
}
m_xDimension = *xDimensionIt;
vecNonMappedDims.erase(std::remove_if(vecNonMappedDims.begin(),
vecNonMappedDims.end(),
findID(xDimId)),
vecNonMappedDims.end());
}
Poco::XML::Element *yDimensionElement = geometryXMLElement->getChildElement(
MDGeometryXMLDefinitions::workspaceYDimensionElementName());
std::string yDimId =
yDimensionElement
->getChildElement(
MDGeometryXMLDefinitions::workspaceRefDimensionElementName())
->innerText();
if (!yDimId.empty()) {
auto yDimensionIt =
find_if(vecAllDims.begin(), vecAllDims.end(), findID(yDimId));
if (yDimensionIt == vecAllDims.end()) {
throw std::invalid_argument("Cannot determine y-dimension mapping.");
}
m_yDimension = *yDimensionIt;
vecNonMappedDims.erase(std::remove_if(vecNonMappedDims.begin(),
vecNonMappedDims.end(),
findID(yDimId)),
vecNonMappedDims.end());
}
Poco::XML::Element *zDimensionElement = geometryXMLElement->getChildElement(
MDGeometryXMLDefinitions::workspaceZDimensionElementName());
std::string zDimId =
zDimensionElement
->getChildElement(
MDGeometryXMLDefinitions::workspaceRefDimensionElementName())
->innerText();
if (!zDimId.empty()) {
auto zDimensionIt =
find_if(vecAllDims.begin(), vecAllDims.end(), findID(zDimId));
if (zDimensionIt == vecAllDims.end()) {
throw std::invalid_argument("Cannot determine z-dimension mapping.");
}
m_zDimension = *zDimensionIt;
vecNonMappedDims.erase(std::remove_if(vecNonMappedDims.begin(),
vecNonMappedDims.end(),
findID(zDimId)),
vecNonMappedDims.end());
}
Poco::XML::Element *tDimensionElement = geometryXMLElement->getChildElement(
MDGeometryXMLDefinitions::workspaceTDimensionElementName());
//.........这里部分代码省略.........