我有一个 xml 文件,我想从中提取一些特定字段
样本测试文件
<ScheduleTask ID="ZmwnBtczlnYOBLyK" Code="000-000.0.0.0" Name="SETTLEMENT.BRIDGE" ParentSummaryTaskID="">
<Quantities>
<STQuantity MethodID="416" RecipeID=""/>
</Quantities>
<Timings>
<Timing LocationID="$$$$$>C1>NB" CompletionRate="1">
<Planned Begin="2012-03-08T07:14:57" End="2012-03-28T07:14:57"/>
<Actual Begin="2012-03-31T06:00:00" End="2012-05-01T14:00:00"/>
</Timing>
<Timing LocationID="$$$$$>C1>SB" CompletionRate="0">
<Planned Begin="2012-12-04T06:07:29" End="2012-12-24T06:07:29"/>
<Forecast Begin="2013-04-18T09:16:37" End="2013-06-04T12:06:02"/>
</Timing>
</Timings>
</ScheduleTask>
所以,我有这个函数用 /ScheduleTask 寻找一行(包括 <)
//xml file into ontology
list<stack<string> > addWordsFromFile(string filename, int changeLevel)
{
ifstream ontology;
ontology.open(filename.c_str());
string ontTemp, line;
list<stack<string> > control_list;
while (true) {
getline(ontology, line); //read line
if (ontology.fail()) break; //boilerplate check for error
line.erase(remove(line.begin(), line.end(), '\t'), line.end()); //remove tabs
if(line == "</ScheduleTasks>") break; //check for end of document
if(line == "</ScheduleTask>") {
ontTemp.clear(); //clear memory
}
//look for activity
if(line.substr(1, 15) == "ScheduleTask ID") {
int i = 41;
while (line[++i] != '"') {ontTemp += line[i]; }
}
if (ontTemp != "" ) {//ready to add
stack<string> tempMem;
tempMem.push(ontTemp);
control_list.push_back(tempMem);
}
}
ontology.close();
return control_list;
}
在 Windows 中,这个函数可以正常工作并且/ScheduleTask
被找到 - 在 Linux 中它没有找到,尽管其他字段被发现就好了if(line.substr(1, 15) == "ScheduleTask ID")
使用 VisualStudio 2008 和 g++ 编译
我的问题:1)为什么这在 Linux 中不起作用和 2)它是如何工作的?