本文整理汇总了C++中DOMParser类的典型用法代码示例。如果您正苦于以下问题:C++ DOMParser类的具体用法?C++ DOMParser怎么用?C++ DOMParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DOMParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: confidence
/**checks the file by opening it and reading few lines
* @param filePath :: name of the file inluding its path
* @return an integer value how much this algorithm can load the file
*/
int LoadSpice2D::fileCheck(const std::string& filePath)
{
// Set up the DOM parser and parse xml file
DOMParser pParser;
Document* pDoc;
try
{
pDoc = pParser.parse(filePath);
} catch (...)
{
throw Kernel::Exception::FileError("Unable to parse File:", filePath);
}
int confidence(0);
// Get pointer to root element
Element* pRootElem = pDoc->documentElement();
if(pRootElem)
{
if(pRootElem->tagName().compare("SPICErack") == 0)
{
confidence = 80;
}
}
pDoc->release();
return confidence;
}
示例2: httpRequest
void SINQHMListener::loadDimensions() {
std::istream &istr = httpRequest("/sinqhm.xml");
std::stringstream oss;
Poco::StreamCopier::copyStream(istr, oss);
DOMParser xmlParser;
Poco::AutoPtr<Document> doc;
try {
doc = xmlParser.parseString(oss.str());
} catch (...) {
throw std::runtime_error("Unable to parse sinqhm.xml");
}
Element *root = doc->documentElement();
Poco::AutoPtr<NodeList> bankList = root->getElementsByTagName("bank");
/**
* TODO: There may be multiple banks but I only
* look at the first
*/
Element *bank = dynamic_cast<Element *>(bankList->item(0));
std::string rankt = bank->getAttribute("rank");
rank = std::stoi(rankt);
Poco::AutoPtr<NodeList> axisList = bank->getElementsByTagName("axis");
for (unsigned int i = 0; i < axisList->length(); i++) {
Element *axis = dynamic_cast<Element *>(axisList->item(i));
std::string sdim = axis->getAttribute("length");
dim[i] = std::stoi(sdim);
}
doSpecialDim();
}
示例3: confidence
/**
* Return the confidence with with this algorithm can load the file
* @param descriptor A descriptor for the file
* @returns An integer specifying the confidence level. 0 indicates it will not
* be used
*/
int LoadSpice2D::confidence(Kernel::FileDescriptor &descriptor) const {
if (descriptor.extension() != ".xml")
return 0;
std::istream &is = descriptor.data();
int confidence(0);
{ // start of inner scope
Poco::XML::InputSource src(is);
// Set up the DOM parser and parse xml file
DOMParser pParser;
Poco::AutoPtr<Document> pDoc;
try {
pDoc = pParser.parse(&src);
} catch (Poco::Exception &e) {
throw Kernel::Exception::FileError("Unable to parse File (" +
descriptor.filename() + ")",
e.displayText());
} catch (...) {
throw Kernel::Exception::FileError("Unable to parse File:",
descriptor.filename());
}
// Get pointer to root element
Element *pRootElem = pDoc->documentElement();
if (pRootElem) {
if (pRootElem->tagName() == "SPICErack") {
confidence = 80;
}
}
} // end of inner scope
return confidence;
}
示例4: createImplicitFunctionParserFromXML
ImplicitFunctionParser* ImplicitFunctionParserFactoryImpl::createImplicitFunctionParserFromXML(const std::string& functionXML) const
{
using namespace Poco::XML;
DOMParser pParser;
AutoPtr<Document> pDoc = pParser.parseString(functionXML);
Element* pRootElem = pDoc->documentElement();
return createImplicitFunctionParserFromXML(pRootElem);
}
示例5: execManually
void LoadParameterFile::execManually(bool useString, std::string filename, std::string parameterXML, Mantid::API::ExperimentInfo_sptr localWorkspace)
{
// TODO: Refactor to remove the need for the const cast (ticket #8521)
Instrument_sptr instrument = boost::const_pointer_cast<Instrument>(localWorkspace->getInstrument()->baseInstrument());
// Set up the DOM parser and parse xml file
DOMParser pParser;
AutoPtr<Document> pDoc;
if(useString){
try
{
pDoc = pParser.parseString(parameterXML);
}
catch(Poco::Exception& exc)
{
throw Kernel::Exception::FileError (exc.displayText() + ". Unable to parse parameter XML string","ParameterXML");
}
catch(...)
{
throw Kernel::Exception::FileError("Unable to parse parameter XML string","ParameterXML");
}
}
else
{
try
{
pDoc = pParser.parse(filename);
}
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
Element* pRootElem = pDoc->documentElement();
if ( !pRootElem->hasChildNodes() )
{
throw Kernel::Exception::InstrumentDefinitionError("No root element in XML Parameter file", filename);
}
//
InstrumentDefinitionParser loadInstr;
loadInstr.setComponentLinks(instrument, pRootElem);
// populate parameter map of workspace
localWorkspace->populateInstrumentParameters();
}
示例6: funcParser
Mantid::Geometry::MDImplicitFunction* ImplicitFunctionFactoryImpl::createUnwrapped(const std::string& processXML) const
{
using namespace Poco::XML;
DOMParser pParser;
Poco::AutoPtr<Document> pDoc = pParser.parseString(processXML);
Element* pInstructionsXML = pDoc->documentElement();
boost::scoped_ptr<ImplicitFunctionParser> funcParser(ImplicitFunctionParserFactory::Instance().createImplicitFunctionParserFromXML(processXML));
boost::scoped_ptr<ImplicitFunctionBuilder> functionBuilder(funcParser->createFunctionBuilder(pInstructionsXML));
return functionBuilder->create();
}
示例7: jsDOMParserPrototypeFunctionParseFromString
JSValue* jsDOMParserPrototypeFunctionParseFromString(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)
{
if (!thisValue->isObject(&JSDOMParser::s_info))
return throwError(exec, TypeError);
JSDOMParser* castedThisObj = static_cast<JSDOMParser*>(thisValue);
DOMParser* imp = static_cast<DOMParser*>(castedThisObj->impl());
const UString& str = args[0]->toString(exec);
const UString& contentType = args[1]->toString(exec);
KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->parseFromString(str, contentType)));
return result;
}
示例8: loadSkin
int SkinElementsMgr::loadSkin(const char *name) {
if ( m_doc ) {
}
DOMParser p;
m_skinName = name;
String skinPath = m_skinsPath;
skinPath += m_skinName;
skinPath += DIRCHARSTR;
m_skinPath = skinPath;
skinPath += "skin.xml";
m_doc = p.parseFile(skinPath,1);
if(m_doc && m_doc->getDocumentElement()) m_skinIterator++;
return m_skinIterator;
}
示例9: jsDOMParserPrototypeFunctionParseFromString
EncodedJSValue JSC_HOST_CALL jsDOMParserPrototypeFunctionParseFromString(ExecState* exec)
{
JSValue thisValue = exec->hostThisValue();
if (!thisValue.inherits(&JSDOMParser::s_info))
return throwVMTypeError(exec);
JSDOMParser* castedThis = static_cast<JSDOMParser*>(asObject(thisValue));
DOMParser* imp = static_cast<DOMParser*>(castedThis->impl());
const String& str(ustringToString(exec->argument(0).toString(exec)));
if (exec->hadException())
return JSValue::encode(jsUndefined());
const String& contentType(ustringToString(exec->argument(1).toString(exec)));
if (exec->hadException())
return JSValue::encode(jsUndefined());
JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->parseFromString(str, contentType)));
return JSValue::encode(result);
}
示例10: src
/**
* Takes a stream that is assumed to contain a single complete material
* definition,
* reads the definition and produces a new Material object. If many definitions
* are present then the first one is read
* @param istr A reference to a stream
* @return A new Material object
*/
Material MaterialXMLParser::parse(std::istream &istr) const {
using namespace Poco::XML;
typedef AutoPtr<Document> DocumentPtr;
InputSource src(istr);
DOMParser parser;
// Do not use auto here or anywhereas the Poco API returns raw pointers
// but in some circumstances requires AutoPtrs to manage the memory
DocumentPtr doc;
try {
doc = parser.parse(&src);
} catch (SAXParseException &exc) {
std::ostringstream os;
os << "MaterialXMLReader::read() - Error parsing stream as XML: "
<< exc.what();
throw std::invalid_argument(os.str());
}
Element *rootElement = doc->documentElement();
// Iterating is apparently much faster than getElementsByTagName
NodeIterator nodeIter(rootElement, NodeFilter::SHOW_ELEMENT);
Node *node = nodeIter.nextNode();
Material matr;
bool found(false);
while (node) {
if (node->nodeName() == MATERIAL_TAG) {
matr = parse(static_cast<Element *>(node));
found = true;
break;
}
node = nodeIter.nextNode();
}
if (!found) {
throw std::invalid_argument(
"MaterialXMLReader::read() - No material tags found.");
}
return matr;
}
示例11: initializeXMLParser
/** Initalize Poco XML Parser
* @param filename -- name of the xml file to process.
*/
void LoadMask::initializeXMLParser(const std::string &filename) {
// const std::string instName
std::cout << "Load File " << filename << '\n';
const std::string xmlText = Kernel::Strings::loadFile(filename);
std::cout << "Successfully Load XML File \n";
// Set up the DOM parser and parse xml file
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()) {
g_log.error("XML file: " + filename + "contains no root element.");
throw Kernel::Exception::InstrumentDefinitionError(
"No root element in XML instrument file", filename);
}
}
示例12: DOMParser
/**
* Parse incomming message (from server).
* @param str Incomming server message
* @return Message in Command structure
*/
Command XMLTool::parseXML(string str) {
Command cmd;
try {
DOMParser parser = DOMParser(0);
AutoPtr<Document> pDoc = parser.parseString(str);
NodeIterator it(pDoc, NodeFilter::SHOW_ELEMENT);
Node* pNode = it.nextNode();
NamedNodeMap* attributes = NULL;
Node* attribute = NULL;
while (pNode) {
if (pNode->nodeName().compare("server_adapter") == 0) {
if (pNode->hasAttributes()) {
attributes = pNode->attributes();
for(unsigned int i = 0; i < attributes->length(); i++) {
attribute = attributes->item(i);
if (attribute->nodeName().compare("protocol_version") == 0) {
cmd.protocol_version = attribute->nodeValue();
}
else if (attribute->nodeName().compare("state") == 0) {
cmd.state = attribute->nodeValue();
}
// FIXME - id attribute is here only for backward compatibility, it should be removed in Q1/2016
else if (attribute->nodeName().compare("euid") == 0 || attribute->nodeName().compare("id") == 0) {
cmd.euid = stoull(attribute->nodeValue(), nullptr, 0);
}
else if (attribute->nodeName().compare("device_id") == 0) {
cmd.device_id = atoll(attribute->nodeValue().c_str());
}
else if (attribute->nodeName().compare("time") == 0) {
cmd.time = atoll(attribute->nodeValue().c_str());
}
else {
log.error("Unknow attribute for SERVER_ADAPTER : " + fromXMLString(attribute->nodeName()));
}
}
attributes->release();
}
}
else if (pNode->nodeName().compare("value") == 0) {
if(cmd.state == "getparameters" || cmd.state == "parameters"){
string inner = pNode->innerText();
string device_id = "";
if (pNode->hasAttributes()) {
attributes = pNode->attributes();
string device_id = "";
for(unsigned int i = 0; i < attributes->length(); i++) {
attribute = attributes->item(i);
if (attribute->nodeName().compare("device_id") == 0) {
device_id = toNumFromString(attribute->nodeValue());
}
}
attributes->release();
}
cmd.params.value.push_back({inner, device_id});
}
else {
float val = atof(pNode->innerText().c_str());
if (pNode->hasAttributes()) {
int module_id = 0;
attributes = pNode->attributes();
for(unsigned int i = 0; i < attributes->length(); i++) {
attribute = attributes->item(i);
if (attribute->nodeName().compare("module_id") == 0) {
module_id = toNumFromString(attribute->nodeValue());
}
}
cmd.values.push_back({module_id, val}); //TODO Hex number is processed wrongly
attributes->release();
}
}
}
else if (pNode->nodeName().compare("parameter") == 0) {
if (pNode->hasAttributes()) {
attributes = pNode->attributes();
for(unsigned int i = 0; i < attributes->length(); i++) {
attribute = attributes->item(i);
if (attribute->nodeName().compare("param_id") == 0 || attribute->nodeName().compare("id") == 0) {
cmd.params.param_id = toNumFromString(attribute->nodeValue());
}
else if (attribute->nodeName().compare("euid") == 0) {
cmd.params.euid = toNumFromString(attribute->nodeValue());
}
}
attributes->release();
}
}
//.........这里部分代码省略.........
示例13: Open
/*****************************************************************************
* Open:
*****************************************************************************/
static int Open(vlc_object_t *p_obj)
{
demux_t *p_demux = (demux_t*) p_obj;
if(!p_demux->s->psz_url)
return VLC_EGENERIC;
std::string mimeType;
char *psz_mime = stream_ContentType(p_demux->s);
if(psz_mime)
{
mimeType = std::string(psz_mime);
free(psz_mime);
}
PlaylistManager *p_manager = NULL;
char *psz_logic = var_InheritString(p_obj, "adaptive-logic");
AbstractAdaptationLogic::LogicType logic = AbstractAdaptationLogic::Default;
if( psz_logic )
{
for(size_t i=0;i<ARRAY_SIZE(pi_logics); i++)
{
if(!strcmp(psz_logic, ppsz_logics_values[i]))
{
logic = pi_logics[i];
break;
}
}
free( psz_logic );
}
std::string playlisturl(p_demux->s->psz_url);
bool dashmime = DASHManager::mimeMatched(mimeType);
bool smoothmime = SmoothManager::mimeMatched(mimeType);
if(!dashmime && !smoothmime && HLSManager::isHTTPLiveStreaming(p_demux->s))
{
M3U8Parser parser;
M3U8 *p_playlist = parser.parse(VLC_OBJECT(p_demux),p_demux->s, playlisturl);
if(!p_playlist)
{
msg_Err( p_demux, "Could not parse playlist" );
return VLC_EGENERIC;
}
p_manager = new (std::nothrow) HLSManager(p_demux, p_playlist,
new (std::nothrow) HLSStreamFactory, logic);
}
else
{
/* Handle XML Based ones */
DOMParser xmlParser; /* Share that xml reader */
if(dashmime)
{
p_manager = HandleDash(p_demux, xmlParser, playlisturl, logic);
}
else if(smoothmime)
{
p_manager = HandleSmooth(p_demux, xmlParser, playlisturl, logic);
}
else
{
/* We need to probe content */
const uint8_t *p_peek;
const ssize_t i_peek = vlc_stream_Peek(p_demux->s, &p_peek, 2048);
if(i_peek > 0)
{
stream_t *peekstream = vlc_stream_MemoryNew(p_demux, const_cast<uint8_t *>(p_peek), (size_t)i_peek, true);
if(peekstream)
{
if(xmlParser.reset(peekstream) && xmlParser.parse(false))
{
if(DASHManager::isDASH(xmlParser.getRootNode()))
{
p_manager = HandleDash(p_demux, xmlParser, playlisturl, logic);
}
else if(SmoothManager::isSmoothStreaming(xmlParser.getRootNode()))
{
p_manager = HandleSmooth(p_demux, xmlParser, playlisturl, logic);
}
}
vlc_stream_Delete(peekstream);
}
}
}
}
if(!p_manager || !p_manager->start())
{
delete p_manager;
return VLC_EGENERIC;
}
p_demux->p_sys = reinterpret_cast<demux_sys_t *>(p_manager);
//.........这里部分代码省略.........
示例14: main
int main(int argc, char **argv)
{
bool verbose = false;
#if 0
DOMParser::ValSchemes gValScheme = DOMParser::Val_Auto;
bool gDoNamespaces = true;
bool gDoSchema = true;
bool gSchemaFullChecking = false;
bool gDoCreate = false;
#endif
MFileOperations f;
char path[1024];
f.expandPath(path, "MESA_TARGET", "runtime");
::strcat(path, "/IHE-syslog-audit-message-4.xsd");
char* schemaDef = path;
int detailLevel = 1;
MString tmp;
while (--argc > 0 && (*++argv)[0] == '-') {
switch (*(argv[0] + 1)) {
case 'l':
argc--; argv++;
if (argc < 1)
usage();
tmp = *argv;
detailLevel = tmp.intData();
break;
case 's':
argc--; argv++;
if (argc < 1)
usage();
schemaDef = *argv;
break;
case 'v':
verbose = true;
break;
default:
break;
}
}
if (argc < 1)
usage();
// Initialize the XML4C2 system
try {
XMLPlatformUtils::Initialize();
}
catch (const XMLException& e) {
cout << "Unable to initialize Xerces-c software"
<< DOMString(e.getMessage()) << endl;
return 1;
}
DOMParser *parser = new DOMParser;
parser->setValidationScheme(DOMParser::Val_Auto);
parser->setDoNamespaces(true);
parser->setDoSchema(true);
parser->setValidationSchemaFullChecking(true);
if (schemaDef != "") {
parser->setExternalNoNamespaceSchemaLocation(schemaDef);
}
DOMTreeErrorReporter *errReporter = new DOMTreeErrorReporter();
parser->setErrorHandler(errReporter);
parser->setCreateEntityReferenceNodes(false);
parser->setToCreateXMLDeclTypeNode(true);
bool errorFlag = false;
try {
parser->parse(*argv);
int count = parser->getErrorCount();
if (count > 0) {
errorFlag = true;
return 1;
}
}
catch (const XMLException& e) {
cout << "Parsing error: " << DOMString(e.getMessage()) << endl;
return 1;
}
catch (const DOM_DOMException& e) {
cout << "DOM Error: " << e.code << endl;
return 1;
}
catch (...) {
cout << "Unspecified error" << endl;
return 1;
}
DOM_Document doc = parser->getDocument();
unsigned int elementCount = doc.getElementsByTagName("*").getLength();
//.........这里部分代码省略.........
示例15: settingsFile
//**********************************************************************************************************************
bool cSettings::LoadFromFile (const string& fileName)
{
ifstream settingsFile(fileName.c_str());
msAlertCode = acOk;
if (!settingsFile.is_open())
{
cout << "Cannot open \"" << fileName << "\" for reading." << endl;
return false;
}
InputSource settingsSrc(settingsFile);
// attempt to parse the settings file
try
{
mSettingsDoc = mSettingsParser.parse(&settingsSrc);
mSettingsRoot = mSettingsDoc->documentElement();
// check that the settings root element's name is "settings"
if (mSettingsRoot->nodeName() != "settings")
{
cout << fileName << " must contain a <settings> element as its root element." << endl;
return false;
}
Element* el = mSettingsRoot->getChildElement("logfile");
if ((!el) || (!el->hasAttribute("location")))
{
cout << "WARNING: No log file location specified in settings file. Using \"./qrap.log\"." << endl;
msLogFileName = "./qrap.log";
} else
{
msLogFileName = el->getAttribute("location");
}
QRAP_INFO("-----------Begin debug logging-----------");
// check the database element
el = mSettingsRoot->getChildElement("database");
if ((!el) || (!el->hasAttribute("host")) || (!el->hasAttribute("name")))
{
QRAP_FATAL_CODE(fileName+" must contain a <database> element with connection parameters.", acInternalError);
return false;
}
#ifndef QRAP_SERVER_EDITION
// check that the synchronisation server details are in
el = mSettingsRoot->getChildElement("syncserver");
if ((!el) || (!el->hasAttribute("host")) || (!el->hasAttribute("port")))
{
QRAP_FATAL_CODE(fileName+" must contain a <syncserver> element with connection parameters.", acInternalError);
return false;
}
#endif
// check the structure element
el = mSettingsRoot->getChildElement("structure");
if ((!el) || (!el->hasAttribute("location")))
{
QRAP_FATAL_CODE(fileName+" must contain a reference to a structure XML file.", acInternalError);
return false;
}
// open up the structure file
string structFileName = el->getAttribute("location");
ifstream structFile(structFileName.c_str());
// check that the file's open
if (!structFile.is_open())
{
QRAP_FATAL_CODE("Cannot open \""+structFileName+"\" for reading.", acFileOpenRead);
return false;
}
// create an input source
InputSource structSrc(structFile);
DOMParser structParser;
AutoPtr<Document> structDoc = structParser.parse(&structSrc);
Element* structRoot = structDoc->documentElement();
// check that the structure file contains a <structure> element
if ((!structRoot) || (structRoot->nodeName() != "structure"))
{
QRAP_FATAL_CODE(structFileName+" must contain a <structure> root element.", acParse);
return false;
}
// get the "table" children
ElementsByTagNameList* tables = dynamic_cast<ElementsByTagNameList*>(structRoot->getElementsByTagName("table"));
ElementsByTagNameList* fields, *views;
int i, tableCount, j, k, fieldCount, viewCount;
unsigned refPos;
Element* curTable, *curField, *curView;
string tableName, fieldName, temp, viewName, viewAs;
tableCount = tables->length();
if (!tableCount)
//.........这里部分代码省略.........