我有一个 xml 文件这个文件由 Blocks、Lines、words、characters 组成:
<block id="48" left="2532" top="108" right="2896" bottom="137">
<line id="49" left="2532" top="108" right="2896" bottom="137">
<word id="50" left="2532" top="108" right="2616" bottom="137" value='Date"d'' confidence="69" font="MP" type="-1">
<char id="51" left="2532" top="115" right="2550" bottom="137" value="D" confidence="92" />
<char id="52" left="2551" top="120" right="2565" bottom="137" value="a" confidence="51" />
<char id="53" left="2566" top="116" right="2574" bottom="137" value="t" confidence="33" />
<char id="54" left="2574" top="120" right="2589" bottom="136" value="e" confidence="100" />
<char id="55" left="2589" top="108" right="2592" bottom="112" value='"' confidence="39" />
<char id="56" left="2597" top="115" right="2611" bottom="136" value="d" confidence="76" />
<char id="57" left="2612" top="115" right="2616" bottom="123" value="'" confidence="100" />
</word>
- 每个 Block 由 1,...,n 行组成
- 每行由 1,...,k 个单词组成
- 每个单词由 1,...,l 个字符组成
我正在尝试按如下方式创建对象:
Block(int top, int left, int bottom, int right, vector<Lines>)
Line(int top, int left, int bottom, int right, vector<words>)
Word(int top, int left, int bottom, int right, vector<characters>)
我在 C++ 上使用 TinyXML,但我无法将它们链接在一起,我的代码一次可以使用一个对象(块、行、单词、字符)。
void Keywords::checkChild(TiXmlElement *child)
{
if(child)
{
if((string)child->Value() == "block")
{
cout << child->Value()<<endl;
double x1 = atoi(child->Attribute("left"));
double y1 = atoi(child->Attribute("top"));
double x2 = atoi(child->Attribute("right"));
double y2= atoi(child->Attribute("bottom"));
int bid = atoi(child->Attribute("id"));
double xcenter = (x1 + x2)/2.0;
double ycenter = (y1 + y2)/2.0;
double hauteur = y2-y1;
double largeur = x2-x1;
//LineList is a vector, and I can't find a way to fill the vector
// blockList.push_back(new Block(y1,x1,y2,x2,xcenter,ycenter,largeur,hauteur,xmlFile,lineList));
}
checkChild(child->FirstChildElement());
checkChild(child->NextSiblingElement());
}///end if child
}