32                 const char * xml_type = xml_matrix->Attribute(
"type");
    33                 if (strcmp(
"CV_32F", xml_type) == 0) type = CV_32F;
    34                 else if (strcmp(
"CV_64F", xml_type) == 0) type = CV_64F;
    37                 if (xml_matrix->QueryIntAttribute(
"rows", &rows) != TIXML_SUCCESS) 
return false;
    38                 if (xml_matrix->QueryIntAttribute(
"cols", &cols) != TIXML_SUCCESS) 
return false;
    44                 if (!xml_matrix) 
return NULL;
    49                 return cvCreateMat(rows, cols, type);
    53                 if (!xml_matrix || !matrix) 
return false;
    58                 if (type != cvGetElemType(matrix)) 
return false;
    59                 if (rows != matrix->rows) 
return false;
    60                 if (cols != matrix->cols) 
return false;
    62                 const TiXmlElement *xml_data = xml_matrix->FirstChildElement(
"data");
    63                 for (
int r = 0; 
r < matrix->rows; ++
r) {
    64                         for (
int c = 0; c < matrix->cols; ++c) {
    65                                 if (!xml_data) 
return false;
    66                                 double value = atof(xml_data->GetText());
    67                                 cvSetReal2D(matrix, 
r, c, value);
    68                                 xml_data = (
const TiXmlElement *) xml_data->NextSibling(
"data");
    76                 if (!matrix) 
return NULL;
    78                 TiXmlElement* xml_matrix = 
new TiXmlElement(element_name);
    80                 if (cvGetElemType(matrix) == CV_32F) {
    81                         xml_matrix->SetAttribute(
"type", 
"CV_32F");
    82                         precision = std::numeric_limits<float>::digits10 + 2;
    84                 else if (cvGetElemType(matrix) == CV_64F) {
    85                         xml_matrix->SetAttribute(
"type", 
"CV_64F");
    86                         precision = std::numeric_limits<double>::digits10 + 2;
    93                 xml_matrix->SetAttribute(
"rows", matrix->rows);
    94                 xml_matrix->SetAttribute(
"cols", matrix->cols);
    96                 for (
int r = 0; 
r < matrix->rows; ++
r) {
    97                         for (
int c = 0; c < matrix->cols; ++c) {
    98                                 TiXmlElement *xml_data = 
new TiXmlElement(
"data");
    99                                 xml_matrix->LinkEndChild(xml_data);
   100                                 std::stringstream ss;
   101                                 ss.precision(precision);
   102                                 ss<<cvGetReal2D(matrix, 
r, c);
   103                                 xml_data->LinkEndChild(
new TiXmlText(ss.str().c_str()));