本文整理汇总了C++中XML类的典型用法代码示例。如果您正苦于以下问题:C++ XML类的具体用法?C++ XML怎么用?C++ XML使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XML类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: TEST
TEST(DOMParserTest, ParsesASimpleString) {
string input = "<html><head><title>Hello, World!</title></head><body>This is the body. </body></html>";
char *copy = strdup(input.c_str());
DOMNode *node = DOMNode::create();
XML h;
DOMNode *pNode = h.parse(copy, node);
ASSERT_TRUE(pNode != 0);
DOMNode *htmlNode = pNode->child();
ASSERT_STREQ(htmlNode->name(), "html");
ASSERT_STREQ(htmlNode->child()->name(), "head");
ASSERT_STREQ(htmlNode->last()->name(), "body");
DOMNode *headNode = htmlNode->child();
ASSERT_EQ(headNode->child(), headNode->last());
ASSERT_EQ(headNode->child()->type(), DOMNode::ELEMENT);
ASSERT_STREQ(headNode->child()->name(), "title");
ASSERT_STREQ(headNode->child()->child()->content(), "Hello, World!");
DOMNode *bodyNode = headNode->next();
ASSERT_STREQ(bodyNode->name(), "body");
ASSERT_EQ(bodyNode->child(), bodyNode->last());
ASSERT_EQ(bodyNode->child()->type(), DOMNode::TEXT);
ASSERT_STREQ(bodyNode->child()->content(), "This is the body. ");
free(copy);
}
开发者ID:jaju,项目名称:hypar2,代码行数:29,代码来源:domparsertest.cpp
示例2: folder
// Retrieves a list with available module ids
// static
StringList ModuleFactory::getModuleIDs()
{
StringList list;
boost::filesystem::path folder(dir::SHARE);
folder /= "modules";
// default construction yields past-the-end
boost::filesystem::directory_iterator end_itr;
for (boost::filesystem::directory_iterator itr(folder);
itr != end_itr; itr++)
{
if (!boost::filesystem::is_regular_file(itr->status()))
continue; // ignore directories
// process only files with .xml extension
boost::filesystem::path file(itr->path());
if (file.extension() != ".xml")
continue;
XML xml;
try
{
xml.parseFromFile(file.string());
}
catch(const std::exception& err)
{
klk_log(KLKLOG_ERROR, "Failed to get module info from '%s': %s",
file.string().c_str(), err.what());
continue;
}
const std::string id = xml.getValue("/klkdata/module/id");
list.push_back(id);
}
return list;
}
开发者ID:,项目名称:,代码行数:37,代码来源:
示例3: XML
void ProcessController::LoadXML()
{
string filename = m_Filename+".xml";
XML* xml = new XML(filename.c_str());
XMLElement* e = xml->GetRootElement();
LoadXML(e);
}
开发者ID:,项目名称:,代码行数:7,代码来源:
示例4: OleInitialize
void Level::parseXMLFile(const char *uri)
{
// Initialize COM library.
OleInitialize(0);
XML* xmlDoc = 0;
// Load from file or URL.
FILE* fp = fopen(uri, "rb");
if (fp) {
// Load from file.
fclose(fp);
xmlDoc = new XML(uri);
} else {
// Load from URL.
xmlDoc = new XML(uri, XML_LOAD_MODE_LOCAL_FILE);
}
// Check parse status and do integrity test. 0 OK , 1 Header warning (not fatal) , 2 Error in parse (fatal)
if (xmlDoc->ParseStatus() == 2 || !xmlDoc->IntegrityTest()) {
debug("Error: XML file %s is corrupt (or not a XML file).", uri);
delete xmlDoc;
return;
}
// Compress level XML in memory.
xmlDoc->CompressMemory();
XMLElement *rootNode = xmlDoc->GetRootElement();
this->parseElement(rootNode);
delete xmlDoc;
}
开发者ID:visusnet,项目名称:Blobby-Warriors,代码行数:34,代码来源:Level.cpp
示例5: read_token
void XML::read()
{
// read until EOF or end token
for (;;) {
std::string token;
token = read_token();
if (token == "(0)" || (!strncmp(token.c_str(), "</", 2))) {
return;
}
if (token.c_str()[0] == '<') {
#ifdef DEBUG_XML
std::cout << "Reading sub tag\n";
#endif
std::string name = get_token_name(token);
#ifdef DEBUG_XML
std::cout << "Token is " << name.c_str() << "\n";
#endif
XML* newdata = new XML(name, file);
newdata->read();
nodes.push_back(newdata);
}
else {
value += token.c_str();
}
}
}
开发者ID:LibreGames,项目名称:Nooskewl_Engine,代码行数:27,代码来源:xml.cpp
示例6: XML
//-------------------------------------------------------------------------------------
void Config::writeAccountName(const char* name)
{
if(!useLastAccountName_)
return;
TiXmlNode* rootNode = NULL;
XML* xml = new XML(Resmgr::getSingleton().matchRes(fileName_).c_str());
if(!xml->isGood())
{
ERROR_MSG(fmt::format("Config::writeAccountName: load {} is failed!\n",
fileName_.c_str()));
SAFE_RELEASE(xml);
return;
}
rootNode = xml->getRootNode("accountName");
if(rootNode != NULL)
{
rootNode->SetValue(name);
}
xml->getTxdoc()->SaveFile(fileName_.c_str());
SAFE_RELEASE(xml);
}
开发者ID:0jpq0,项目名称:kbengine,代码行数:27,代码来源:config.cpp
示例7: handle_numeric_tag
void XML_Helpers::handle_min_max_tag(XML *xml, int32_t &min, int32_t &max)
{
min = 0;
max = 0;
XML *min_xml = xml->find("min");
XML *max_xml = xml->find("max");
if (min_xml == 0 || max_xml == 0) {
return;
}
XML *x = min_xml->find("rand");
if (x == 0) {
min = handle_numeric_tag(min_xml);
}
else {
x = XML_Helpers::handle_rand_tag(x);
min = atoi(x->get_value().c_str());
}
x = max_xml->find("rand");
if (x == 0) {
max = handle_numeric_tag(max_xml);
}
else {
x = XML_Helpers::handle_rand_tag(x);
max = atoi(x->get_value().c_str());
}
}
开发者ID:LibreGames,项目名称:Nooskewl_Engine,代码行数:30,代码来源:xml.cpp
示例8: fd
void SBookWidget::menuImport(void)
{
QFileDialog fd(QString::null,0,this,"Import",true);
fd.setMode(QFileDialog::ExistingFile);
fd.setCaption("Import");
fd.setSelection(QDir::currentDirPath());
fd.setFilters((const char **)ifilters);
if(fd.exec()==QDialog::Accepted){
QString filter = fd.selectedFilter();
QString fn = fd.selectedFile();
if(access(fn.latin1(),04)){
if(QMessageBox::warning(0,"Cannot Read",
"The file "
+ fn
+ " cannot be opened for reading:"
+ sys_errlist[errno],
"OK",QString::null,QString::null)==1){
}
return; // aborted
}
int count=0;
if(filter.compare(ifilters[FILTER_XML])==0){
XML xml;
statusStack->raiseWidget(progressBar);
count = xml.readFile(fn,&data,0,progressBar);
statusStack->raiseWidget(statusBar);
if(count == -1){
QMessageBox::warning(0,"Cannot Read",
"The file " + fn + " appears to be corrupt. Sorry!",
"OK");
return;
}
}
if(filter.compare(ifilters[FILTER_SBOOK_ASCII])==0){
count = data.ImportSBookASCII(fn);
}
if(filter.compare(ifilters[FILTER_TAB])==0){
count = data.ImportDelimited(fn,TAB_DELIM);
}
if(filter.compare(ifilters[FILTER_CSV])==0){
count = data.ImportDelimited(fn,CSV_DELIM);
}
if(filter.compare(ifilters[FILTER_IG])==0){
count = data.ImportIG(fn);
}
redisplay();
char buf[1024];
sprintf(buf,"Imported %d %s",count,count==1 ? "entry" : "entries");
emit alert(buf);
}
}
开发者ID:dpp,项目名称:SBook5,代码行数:59,代码来源:main_menu.cpp
示例9: loadxml
static int loadxml(lua_State *state)
{
const char *path = luaL_checkstring(state, -1);
assert(path);
XML obj;
obj.Load(path);
return 0;
}
开发者ID:,项目名称:,代码行数:8,代码来源:
示例10: it
void PlayerDetails::fromXml(XML& xml){
mMesh = xml.getString("ship", "mesh");
mDll = xml.getString("ship", "dll");
mShield = xml.getFloat("ship", "shield");
mShieldRegen = xml.getFloat("ship", "shield_regen");
mArmour = xml.getFloat("ship", "armour");
mEnergy = xml.getFloat("ship", "energy");
mEnergyRegen = xml.getFloat("ship", "energy_regen");
mAmmo = xml.getInt("ship", "ammo");
mSpeed = xml.getFloat("ship", "speed");
mDeathFX = xml.getString("death_fx");
if (xml.getError() != XML_OK){
mDeathFX = "";
}
{
XMLIterator it(&xml);
it.setElemName("ship>weaponchain");
it.gotoZero();
while(it.gotoNext()==true){
WeaponChain wc(it.getElem());
mWeaponChain.push_back(wc);
}
}{
XMLIterator it(&xml);
it.setElemName("ship>reactor");
it.gotoZero();
while(it.gotoNext()==true){
mReactorNodes.push_back(it.getElem().getString("childName"));
}
}
/*
XMLIterator it(&xml);
it.setElemName("");
it.gotoZero();
it.gotoNext();
XML elem;
if (it.gotoNext() == false){
throw("Ship Definition File Missing 3 Weapon Chain");
}
elem = it.getElem();
if (it.gotoNext() == false){
throw("Ship Definition File Missing 2 Weapon Chain");
}
elem = it.getElem();
mSecondaryWeapon.fromXml(elem);
if (it.gotoNext() == false){
throw("Ship Definition File Missing 1 Weapon Chain");
}
elem = it.getElem();
mSuperWeapon.fromXml(elem);*/
int g=0;
}
开发者ID:christianboutin,项目名称:Shmoulette,代码行数:58,代码来源:level.cpp
示例11: RefinedNumericTrack
void Cell::createFromXml(XML* xml){
/*mOverlay = mOverlayManager.create(getId());
mOverlay->setZOrder(xml->getFloat("z"));
mOverlay->show();*/
//mZOrder = xml->getFloat("z");
//mTrack = new RefinedTrack(xml, false);
mX = new RefinedNumericTrack(xml, "posx");
mY = new RefinedNumericTrack(xml, "posy");
mAlpha = new RefinedNumericTrack(xml, "alpha");
mScaleX = new RefinedNumericTrack(xml, "sclx");
mScaleY = new RefinedNumericTrack(xml, "scly");
//mAngle = new RefinedNumericTrack(xml, "angle");
mPos.x = xml->getFloat("posx");
mPos.y = xml->getFloat("posy");
XMLIterator xmlIt(xml);
/*xmlIt.setElemName("cell");
xmlIt.gotoZero();
while(xmlIt.gotoNext()==true){
mElement.push_back(new Cell(&(xmlIt.getElem())));
}*/
xmlIt.setElemName("cell>image");
xmlIt.gotoZero();
while(xmlIt.gotoNext()==true){
Image* img = new Image();
img->init(&(xmlIt.getElem()));
mElement.push_back(img);
img->setDelta(Ogre::Vector2(-1, -1));
img->moveTimes(getTimeOn());
}
xmlIt.setElemName("cell>textzone");
xmlIt.gotoZero();
while(xmlIt.gotoNext()==true){
XML xml = xmlIt.getElem();
string txttype = xml.getString("type");
Text* txt;
if (txttype == "rolling"){
txt = new RollingText();
}else if (txttype == "static"){
txt = new StaticText();
}else{
txt = new StaticText();
}
txt->init(&(xmlIt.getElem()));
txt->setFontStyle(FontStyleManager::getSingleton()->requestFontStyle(xmlIt.getElem().getString("style")));
mElement.push_back(txt);
txt->setDelta(Ogre::Vector2(-1, -1));
txt->moveTimes(getTimeOn());
}
}
开发者ID:christianboutin,项目名称:Shmoulette,代码行数:57,代码来源:cell.cpp
示例12: createXMLTree1
static XML::XMLNode_SPtr createXMLTree1()
{
using XML::XMLNode;
using XML::XMLNode_SPtr;
XMLNode_SPtr root(new XMLNode("ROOT"));
root->children.push_back(XMLNode_SPtr(new XMLNode("CHILD1")));
root->children.push_back(XMLNode_SPtr(new XMLNode("CHILD2")));
return root;
}
开发者ID:JulianSchutsch,项目名称:dt,代码行数:9,代码来源:test_xml.cpp
示例13: load
void KeyboardManager::load (std::string s)
{
XML plik;
plik.load(s);
keys.clear();
for(auto& xml : plik.iter(""))
{
keys[xml->get<std::string>(":name")] = (xml->get<int>(":keycode"));
}
}
开发者ID:96jamteam,项目名称:96jam,代码行数:10,代码来源:keyboardManager.cpp
示例14: throw
WSAddNodePacket::WSAddNodePacket(std::string data) throw(InvalidXMLError) : WSPacket()
{
XML XMLParser;
xercesc::DOMDocument * doc = XMLParser.parseToDom(data);
char * temp;
xercesc::DOMElement * docElement = doc->getDocumentElement();
//if(docElement == NULL)
// throw InvalidXMLError();
xercesc::DOMElement * nextElement;
nextElement = docElement->getFirstElementChild();
XMLCh * installationIDString = xercesc::XMLString::transcode("installationID");
XMLCh * sensorGroupIDString = xercesc::XMLString::transcode("sensorGroupID");
XMLCh * zigbeeAddressString = xercesc::XMLString::transcode("zigbeeAddress");
while(nextElement != NULL)
{
if(xercesc::XMLString::compareIString(nextElement->getTagName(), installationIDString) == 0)
{
temp = xercesc::XMLString::transcode(nextElement->getTextContent());
installationID = boost::lexical_cast<int> (std::string(temp));
xercesc::XMLString::release(&temp);
}
else if(xercesc::XMLString::compareIString(nextElement->getTagName(), sensorGroupIDString) == 0)
{
temp = xercesc::XMLString::transcode(nextElement->getTextContent());
sensorGroupID = boost::lexical_cast<int> (std::string(temp));
xercesc::XMLString::release(&temp);
}
else if(xercesc::XMLString::compareIString(nextElement->getTagName(), zigbeeAddressString) == 0)
{
temp = xercesc::XMLString::transcode(nextElement->getTextContent());
zigbeeAddress64Bit = std::string(temp);
xercesc::XMLString::release(&temp);
}
else
{
std::cerr << "invalid XML: " << std::endl;
std::cerr << "textContent of invalid xml: " << std::string(xercesc::XMLString::transcode(nextElement->getTextContent())) << std::endl;
std::cerr << "tagname of invalid XML: " << std::string(xercesc::XMLString::transcode(nextElement->getTagName())) << std::endl;
throw InvalidWSXML();
}
nextElement = nextElement->getNextElementSibling();
}
xercesc::XMLString::release( &installationIDString );
xercesc::XMLString::release( &sensorGroupIDString );
xercesc::XMLString::release( &zigbeeAddressString );
}
开发者ID:macntouch,项目名称:Qt_ZigbeeWSN,代码行数:55,代码来源:wsaddnodepacket.cpp
示例15: SetProperty
void ListFunctionDef::SetDefaultValues()
{
SetProperty("Values","");
String xml( "<CryList />\
");
xml.Replace("\\\"","\"");// replace \" with "
XML x;
x.LoadFrom(xml);
x.SaveTo(*this);
}
开发者ID:iplayfast,项目名称:crylib,代码行数:11,代码来源:CryFunctionDef.cpp
示例16: snprintf
void XML::write(SDL_RWops *out, int tabs = 0)
{
char buf[1000];
if (value == "") {
for (int i = 0; i < tabs; i++) {
snprintf(buf, 200, "\t");
SDL_fputs(buf, out);
}
snprintf(buf, 200, "<%s>\n", name.c_str());
SDL_fputs(buf, out);
std::list<XML*>::iterator it = nodes.begin();
while (it != nodes.end()) {
XML* node = dynamic_cast<XML*>(*it);
node->write(out, tabs+1);
it++;
}
for (int i = 0; i < tabs; i++) {
snprintf(buf, 200, "\t");
SDL_fputs(buf, out);
}
snprintf(buf, 200, "</%s>\n", name.c_str());
SDL_fputs(buf, out);
}
else {
for (int i = 0; i < tabs; i++) {
snprintf(buf, 200, "\t");
SDL_fputs(buf, out);
}
snprintf(buf, 200, "<%s>", name.c_str());
SDL_fputs(buf, out);
snprintf(buf, 200, "%s", value.c_str());
SDL_fputs(buf, out);
std::list<XML*>::iterator it = nodes.begin();
while (it != nodes.end()) {
XML* node = dynamic_cast<XML*>(*it);
node->write(out, tabs+1);
it++;
}
snprintf(buf, 200, "</%s>\n", name.c_str());
SDL_fputs(buf, out);
}
}
开发者ID:LibreGames,项目名称:Nooskewl_Engine,代码行数:53,代码来源:xml.cpp
示例17: loadXML
Handle<Value> loadXML(const v8::Arguments& args) {
if(!args.IsConstructCall()) {
return v8::ThrowException(String::New("Cannot call constructor as a function"));
}
/* if (args.Length() != 1) {
return v8::ThrowException(v8::String::New("Bad parameters"));
} */
HandleScope scope;
Shell *shell = Shell::Instance();
Context::Scope context_scope(shell->globalContext);
XML *newXML = new XML();
return(scope.Close(newXML->registerObject()));
}
开发者ID:pcontezini,项目名称:pieroshell,代码行数:14,代码来源:GlobalFunctions.cpp
示例18: getLocation
string ConfigurationManager::getLocation(){
XML xml;
char* pPath;
pPath = getenv ("HOME");
QString path(pPath);
if (pPath!=NULL){
path = path +QString(xml.getValue(xml.N_USRDESTDIR).c_str());
QDir dir(path);
if (!dir.exists()) {
dir.mkpath(".");
}
}
return path.toStdString();
}
开发者ID:seger22,项目名称:CloudSync,代码行数:14,代码来源:configurationmanager.cpp
示例19: return
WeaponDBE* WeaponDB::get(string id){
for (list<WeaponDBE*>::iterator it = mEntry.begin();it!=mEntry.end();it++){
if ((*it)->getId() == id){
return (*it);
};
}
File f(id+".xml", "media\\weapons\\weapons");
XML* xml;
if (f.error() != FILE_OK){
throw("Error accessing file : "+id+" in context weapons\\weapons");
xml = NULL;
}else{
xml = new XML(f.getStrContent());
}
string type = xml->getString("weapon","type");
if (xml->getError() != XML_OK){
throw("Error : Weapon requires type");
}
WeaponDBE* rv;
if (type == "dll"){
rv = new DLLWeaponDBE(id, *xml);
}else if (type == "internal"){
string subtype = xml->getString("weapon","subtype");
if (xml->getError() != XML_OK){
throw("Error : Weapon requires subtype");
}
if (subtype == "ammo"){
rv = new AmmoWeaponDBE(id, *xml);
}else if (subtype == "beam"){
rv = new BeamWeaponDBE(id, *xml);
}else{
throw("Subtype : "+subtype+" not recognized");
}
}else{
throw("Type : "+type+" not recognized");
}
//rv->setMount(launcher, mMount);
delete xml;
mEntry.push_back(rv);
return rv;
}
开发者ID:christianboutin,项目名称:Shmoulette,代码行数:43,代码来源:weapondb.cpp
示例20: XML
bool XMLfile::save(Object* pObj,const char *file) //saves the XML file created with the object
{
// Create the XML FILE or if it already exists, it will be overwritten
XML* xml = new XML(file);
XMLElement* root = xml->GetRootElement();
string className = pObj->getClassName();
XMLElement* obj_xml=new XMLElement (root,className.c_str());
pObj->writeToXML(obj_xml);//execute the writing process XML
pElem.push_back(obj_xml);//save every XMLElements_Objects in pElem
root->AddElement(obj_xml);
xml->Save();
return true;
}
开发者ID:drodri,项目名称:MRCore,代码行数:19,代码来源:xmlfile.cpp
注:本文中的XML类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论