00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "XMLElement.h"
00014
00015 XMLElement::XMLElement()
00016 {
00017 initialize(false, true);
00018 }
00019
00020
00021 XMLElement::XMLElement(map<string,string> * entities)
00022 {
00023 initialize(entities, false, true);
00024 }
00025
00026
00027 XMLElement::XMLElement(bool skipLeadingWhitespace)
00028 {
00029 initialize(skipLeadingWhitespace, true);
00030 }
00031
00032
00033 XMLElement::XMLElement(map<string,string> * entities,
00034 bool skipLeadingWhitespace)
00035 {
00036 initialize(entities, skipLeadingWhitespace, true);
00037 }
00038
00039
00040 XMLElement::XMLElement(map<string,string> * entities,
00041 bool skipLeadingWhitespace,
00042 bool fillBasicConversionTable)
00043 {
00044 initialize(entities, skipLeadingWhitespace, fillBasicConversionTable);
00045 }
00046
00047
00048 void XMLElement::initialize(bool skipLeadingWhitespace,
00049 bool fillBasicConversionTable)
00050 {
00051 initialize(&entitiesInstance, skipLeadingWhitespace,
00052 fillBasicConversionTable);
00053 }
00054
00055 void XMLElement::initialize(map<string,string> * entities,
00056 bool skipLeadingWhitespace,
00057 bool fillBasicConversionTable)
00058 {
00059 this->ignoreWhitespace = skipLeadingWhitespace;
00060 this->contents = "";
00061 this->entities = entities;
00062 this->lineNr = 0;
00063
00064 if (fillBasicConversionTable)
00065 {
00066 string key = "amp";
00067 string val = "&";
00068 (*this->entities)[key] = val;
00069
00070 key = "quot";
00071 val = '"';
00072 (*this->entities)[key] = val;
00073
00074 key = "apos";
00075 val = '\'';
00076 (*this->entities)[key] = val;
00077
00078 key = "lt";
00079 val = '<';
00080 (*this->entities)[key] = val;
00081
00082 key = "gt";
00083 val = '>';
00084 (*this->entities)[key] = val;
00085 }
00086 }
00087
00088 int XMLElement::countChildren()
00089 {
00090 return (int)this->children.size();
00091 }
00092
00093 void XMLElement::addChild(XMLElement & child)
00094 {
00095 this->children.push_back(child);
00096 }
00097
00098
00099 void XMLElement::setAttribute(string & name, string & value)
00100 {
00101 this->attributes[name] = value;
00102 }
00103
00104
00105 void XMLElement::setAttribute(string & name, int value)
00106 {
00107 this->attributes[name] = StringManipulation::intToString(value);
00108 }
00109
00110
00111 void XMLElement::setAttribute(string & name, double value)
00112 {
00113 this->attributes[name] = StringManipulation::doubleToString(value);
00114 }
00115
00116 void XMLElement::parse(string & file)
00117 {
00118 ifstream reader(file.c_str());
00119 this->parse(reader);
00120 reader.close();
00121 }
00122
00123
00124 void XMLElement::parse(istream & reader)
00125 {
00126 this->parse(reader, 1);
00127 }
00128
00129 void XMLElement::parse(istream & reader, int startingLineNr)
00130 {
00131 this->charReadTooMuch = '\0';
00132 this->reader = &reader;
00133 this->parserLineNr = startingLineNr;
00134
00135 for (;;)
00136 {
00137 unsigned char ch = this->scanWhitespace();
00138
00139 if (ch != '<')
00140 {
00141 throw this->expectedInput("<");
00142 }
00143
00144 ch = this->readChar();
00145
00146 if ((ch == '!') || (ch == '?'))
00147 {
00148 this->skipSpecialTag(0);
00149 }
00150 else
00151 {
00152 this->unreadChar(ch);
00153 this->scanElement(*this);
00154 return;
00155 }
00156 }
00157 }
00158
00159 void XMLElement::removeChild(XMLElement & child)
00160 {
00161 for(list<XMLElement>::iterator it=this->children.begin();
00162 it != this->children.end(); it++)
00163 {
00164 if( *it == child )
00165 {
00166 it = this->children.erase(it);
00167 }
00168 }
00169 }
00170
00171
00172 void XMLElement::removeAttribute(string & name)
00173 {
00174 this->attributes.erase(name);
00175 }
00176
00177 void XMLElement::setContent(string & content)
00178 {
00179 this->contents = content;
00180 }
00181
00182 string XMLElement::getContent()
00183 {
00184 return this->contents;
00185 }
00186
00187 string XMLElement::getName()
00188 {
00189 return this->name;
00190 }
00191
00192 void XMLElement::setName(string & name)
00193 {
00194 this->name = name;
00195 }
00196
00197 int XMLElement::getLineNr()
00198 {
00199 return this->lineNr;
00200 }
00201
00202 list<XMLElement> * XMLElement::getChildren()
00203 {
00204 return &children;
00205 }
00206
00207
00208
00209 string XMLElement::getStringAttribute(string & name)
00210 {
00211 string noValue = "";
00212 return this->getStringAttribute(name, noValue);
00213 }
00214
00215
00216 string XMLElement::getStringAttribute(string & name,
00217 string & defaultValue)
00218 {
00219 string value = this->attributes[name];
00220
00221 if (value.empty())
00222 {
00223 value = defaultValue;
00224 }
00225
00226 return value;
00227 }
00228
00229
00230 int XMLElement::getIntAttribute(string & name)
00231 {
00232 return this->getIntAttribute(name, 0);
00233 }
00234
00235
00236 int XMLElement::getIntAttribute(string & name,
00237 int defaultValue)
00238 {
00239 string value = this->attributes[name];
00240
00241 if (value.empty())
00242 {
00243 return defaultValue;
00244 }
00245 else
00246 {
00247 return StringManipulation::stringToInt(value);
00248 }
00249 }
00250
00251
00252 double XMLElement::getDoubleAttribute(string & name)
00253 {
00254 return this->getDoubleAttribute(name, 0.);
00255 }
00256
00257
00258 double XMLElement::getDoubleAttribute(string & name,
00259 double defaultValue)
00260 {
00261 string value = this->attributes[name];
00262
00263 if (value.empty())
00264 {
00265 return defaultValue;
00266 }
00267 else
00268 {
00269 return StringManipulation::stringToDouble(value);
00270 }
00271 }
00272
00273
00274 bool XMLElement::getBooleanAttribute(string & name,
00275 string & trueValue,
00276 string & falseValue,
00277 bool defaultValue)
00278 {
00279 string value = this->attributes[name];
00280
00281 if (value.empty())
00282 {
00283 return defaultValue;
00284 }
00285 else if (value == trueValue)
00286 {
00287 return true;
00288 }
00289 else if (value == falseValue)
00290 {
00291 return false;
00292 }
00293 else
00294 {
00295 throw this->invalidValue(name, (string) value);
00296 }
00297 }
00298
00299
00300
00301 void XMLElement::scanIdentifier(string & result)
00302 {
00303 for (;;)
00304 {
00305 unsigned char ch = this->readChar();
00306
00307 if (((ch < 'A') || (ch > 'Z')) && ((ch < 'a') || (ch > 'z'))
00308 && ((ch < '0') || (ch > '9')) && (ch != '_') && (ch != '.')
00309 && (ch != ':') && (ch != '-'))
00310 {
00311 this->unreadChar(ch);
00312 return;
00313 }
00314 result += ch;
00315 }
00316 }
00317
00318
00319 unsigned char XMLElement::scanWhitespace()
00320 {
00321 for (;;)
00322 {
00323 unsigned char ch = this->readChar();
00324
00325 switch (ch)
00326 {
00327 case ' ':
00328 case '\t':
00329 case '\n':
00330 case '\r':
00331 break;
00332 default:
00333 return ch;
00334 }
00335 }
00336 }
00337
00338
00339 unsigned char XMLElement::scanWhitespace(string & result)
00340 {
00341 for (;;)
00342 {
00343 unsigned char ch = this->readChar();
00344
00345 switch (ch)
00346 {
00347 case ' ':
00348 case '\t':
00349 case '\n':
00350 result += ch;
00351 case '\r':
00352 break;
00353 default:
00354 return ch;
00355 }
00356 }
00357 }
00358
00359
00360 void XMLElement::scanString(string & str)
00361 {
00362 unsigned char delimiter = this->readChar();
00363
00364 if ((delimiter != '\'') && (delimiter != '"'))
00365 {
00366 throw this->expectedInput("' or \"");
00367 }
00368
00369 for (;;)
00370 {
00371 unsigned char ch = this->readChar();
00372
00373 if (ch == delimiter)
00374 {
00375 return;
00376 }
00377 else if (ch == '&')
00378 {
00379 this->resolveEntity(str);
00380 }
00381 else
00382 {
00383 str += ch;
00384 }
00385 }
00386 }
00387
00388
00389 void XMLElement::scanPCData(string & data)
00390 {
00391 for (;;)
00392 {
00393 unsigned char ch = this->readChar();
00394
00395 if (ch == '<')
00396 {
00397 ch = this->readChar();
00398
00399 if (ch == '!')
00400 {
00401 this->checkCDATA(data);
00402 }
00403 else
00404 {
00405 this->unreadChar(ch);
00406 return;
00407 }
00408 }
00409 else if (ch == '&')
00410 {
00411 this->resolveEntity(data);
00412 }
00413 else
00414 {
00415 data += ch;
00416 }
00417 }
00418 }
00419
00420
00421 bool XMLElement::checkCDATA(string & buf)
00422 {
00423 unsigned char ch = this->readChar();
00424
00425 if (ch != '[')
00426 {
00427 this->unreadChar(ch);
00428 this->skipSpecialTag(0);
00429 return false;
00430 }
00431 else if (! this->checkLiteral("CDATA["))
00432 {
00433 this->skipSpecialTag(1);
00434 return false;
00435 }
00436 else
00437 {
00438 int delimiterCharsSkipped = 0;
00439
00440 while (delimiterCharsSkipped < 3)
00441 {
00442 ch = this->readChar();
00443
00444 switch (ch)
00445 {
00446 case ']':
00447 if (delimiterCharsSkipped < 2)
00448 {
00449 delimiterCharsSkipped += 1;
00450 }
00451 else
00452 {
00453 buf += ']';
00454 buf += ']';
00455 delimiterCharsSkipped = 0;
00456 }
00457 break;
00458 case '>':
00459 if (delimiterCharsSkipped < 2)
00460 {
00461 for (int i = 0; i < delimiterCharsSkipped; i++)
00462 {
00463 buf += ']';
00464 }
00465
00466 delimiterCharsSkipped = 0;
00467 buf += '>';
00468 }
00469 else
00470 {
00471 delimiterCharsSkipped = 3;
00472 }
00473
00474 break;
00475 default:
00476 for (int i = 0; i < delimiterCharsSkipped; i += 1)
00477 {
00478 buf += ']';
00479 }
00480
00481 buf += ch;
00482 delimiterCharsSkipped = 0;
00483 }
00484 }
00485 return true;
00486 }
00487 }
00488
00489
00490 void XMLElement::scanElement(XMLElement & elt)
00491 {
00492 string name;
00493 this->scanIdentifier(name);
00494 elt.setName(name);
00495 unsigned char ch = this->scanWhitespace();
00496
00497 while ((ch != '>') && (ch != '/'))
00498 {
00499 string key;
00500 this->unreadChar(ch);
00501 this->scanIdentifier(key);
00502 ch = this->scanWhitespace();
00503
00504 if (ch != '=')
00505 {
00506 throw this->expectedInput("=");
00507 }
00508
00509 this->unreadChar(this->scanWhitespace());
00510 string value;
00511 this->scanString(value);
00512 elt.setAttribute(key, value);
00513 ch = this->scanWhitespace();
00514 }
00515
00516 if (ch == '/')
00517 {
00518 ch = this->readChar();
00519 if (ch != '>')
00520 {
00521 throw this->expectedInput(">");
00522 }
00523 return;
00524 }
00525
00526 string buf;
00527 ch = this->scanWhitespace(buf);
00528
00529 if (ch != '<')
00530 {
00531 this->unreadChar(ch);
00532 this->scanPCData(buf);
00533 }
00534 else
00535 {
00536 for (;;)
00537 {
00538 ch = this->readChar();
00539 if (ch == '!')
00540 {
00541 if (this->checkCDATA(buf))
00542 {
00543 this->scanPCData(buf);
00544 break;
00545 }
00546 else
00547 {
00548 ch = this->scanWhitespace(buf);
00549 if (ch != '<')
00550 {
00551 this->unreadChar(ch);
00552 this->scanPCData(buf);
00553 break;
00554 }
00555 }
00556 }
00557 else
00558 {
00559 buf.resize(0);
00560 break;
00561 }
00562 }
00563 }
00564
00565 if (buf.length() == 0)
00566 {
00567 while (ch != '/')
00568 {
00569 if (ch == '!')
00570 {
00571 ch = this->readChar();
00572
00573 if (ch != '-')
00574 {
00575 throw this->expectedInput("Comment or Element");
00576 }
00577
00578 ch = this->readChar();
00579
00580 if (ch != '-')
00581 {
00582 throw this->expectedInput("Comment or Element");
00583 }
00584
00585 this->skipComment();
00586 }
00587 else
00588 {
00589 this->unreadChar(ch);
00590 XMLElement child = this->createAnotherElement();
00591 this->scanElement(child);
00592 elt.addChild(child);
00593 }
00594
00595 ch = this->scanWhitespace();
00596
00597 if (ch != '<')
00598 {
00599 throw this->expectedInput("<");
00600 }
00601
00602 ch = this->readChar();
00603 }
00604 this->unreadChar(ch);
00605 }
00606 else
00607 {
00608
00609
00610
00611
00612
00613
00614 elt.setContent(buf);
00615
00616 }
00617
00618 ch = this->readChar();
00619
00620 if (ch != '/')
00621 {
00622 throw this->expectedInput("/");
00623 }
00624
00625 this->unreadChar(this->scanWhitespace());
00626
00627 if (! this->checkLiteral(name))
00628 {
00629 throw this->expectedInput(name);
00630 }
00631
00632 if (this->scanWhitespace() != '>')
00633 {
00634 throw this->expectedInput(">");
00635 }
00636 }
00637
00638
00639
00640 void XMLElement::skipComment()
00641 {
00642 int dashesToRead = 2;
00643
00644 while (dashesToRead > 0)
00645 {
00646 unsigned char ch = this->readChar();
00647
00648 if (ch == '-')
00649 {
00650 dashesToRead -= 1;
00651 }
00652 else
00653 {
00654 dashesToRead = 2;
00655 }
00656 }
00657
00658 if (this->readChar() != '>')
00659 {
00660 throw this->expectedInput(">");
00661 }
00662 }
00663
00664
00665
00666 void XMLElement::skipSpecialTag(int bracketLevel)
00667 {
00668 int tagLevel = 1;
00669 unsigned char stringDelimiter = '\0';
00670
00671 if (bracketLevel == 0)
00672 {
00673 unsigned char ch = this->readChar();
00674
00675 if (ch == '[')
00676 {
00677 bracketLevel += 1;
00678 }
00679 else
00680 {
00681 if (ch == '-')
00682 {
00683 ch = this->readChar();
00684
00685 if (ch == '[')
00686 {
00687 bracketLevel += 1;
00688 }
00689 else if (ch == ']')
00690 {
00691 bracketLevel -= 1;
00692 }
00693 else if (ch == '-')
00694 {
00695 this->skipComment();
00696 return;
00697 }
00698 }
00699 }
00700 }
00701
00702 while (tagLevel > 0)
00703 {
00704 unsigned char ch = this->readChar();
00705
00706 if (stringDelimiter == '\0')
00707 {
00708 if ((ch == '"') || (ch == '\''))
00709 {
00710 stringDelimiter = ch;
00711 }
00712 else if (bracketLevel <= 0)
00713 {
00714 if (ch == '<')
00715 {
00716 tagLevel += 1;
00717 }
00718 else if (ch == '>')
00719 {
00720 tagLevel -= 1;
00721 }
00722 }
00723
00724 if (ch == '[')
00725 {
00726 bracketLevel += 1;
00727 }
00728 else if (ch == ']')
00729 {
00730 bracketLevel -= 1;
00731 }
00732 }
00733 else
00734 {
00735 if (ch == stringDelimiter)
00736 {
00737 stringDelimiter = '\0';
00738 }
00739 }
00740 }
00741 }
00742
00743
00744
00745 bool XMLElement::checkLiteral(string literal)
00746 {
00747 int length = (int)literal.length();
00748
00749 for (int i = 0; i < length; i += 1)
00750 {
00751 if (this->readChar() != literal.at(i))
00752 {
00753 return false;
00754 }
00755 }
00756 return true;
00757 }
00758
00759
00760 void XMLElement::resolveEntity(string & buf)
00761 {
00762 unsigned char ch = '\0';
00763 string key;
00764
00765 for (;;)
00766 {
00767 ch = this->readChar();
00768
00769 if (ch == ';')
00770 {
00771 break;
00772 }
00773
00774 key += ch;
00775 }
00776
00777 if (key.at(0) == '#')
00778 {
00779 if (key.at(1) == 'x')
00780 {
00781 string numberStr = key.substr(2);
00782 int intRep = StringManipulation::hexstringToInt(numberStr);
00783
00784 if(intRep < 0 || intRep > 256)
00785 {
00786 throw unicodeError(intRep);
00787 }
00788
00789 ch = (unsigned char) intRep;
00790 }
00791 else
00792 {
00793 string numberStr = key.substr(1);
00794 int intRep = StringManipulation::stringToInt(numberStr);
00795
00796 if(intRep < 0 || intRep > 256)
00797 {
00798 throw unicodeError(intRep);
00799 }
00800
00801 ch = (unsigned char) intRep;
00802 }
00803
00804 buf += ch;
00805 }
00806 else
00807 {
00808 string value = (*this->entities)[key];
00809 if (value.empty())
00810 {
00811 throw this->unknownEntity(key);
00812 }
00813 buf.append(value);
00814 }
00815 }
00816
00817
00818 unsigned char XMLElement::readChar()
00819 {
00820 if (this->charReadTooMuch != '\0')
00821 {
00822 unsigned char ch = this->charReadTooMuch;
00823 this->charReadTooMuch = '\0';
00824 return ch;
00825 }
00826 else
00827 {
00828 int i = (*this->reader).get();
00829 if (i < 0)
00830 {
00831 throw this->unexpectedEndOfData();
00832 }
00833 else if (i == 10)
00834 {
00835 this->parserLineNr += 1;
00836 return '\n';
00837 }
00838 else
00839 {
00840 return (unsigned char) i;
00841 }
00842 }
00843 }
00844
00845
00846 void XMLElement::unreadChar(unsigned char ch)
00847 {
00848 this->charReadTooMuch = ch;
00849 }
00850
00851
00852 XMLElement XMLElement::createAnotherElement()
00853 {
00854 return XMLElement(this->entities, this->ignoreWhitespace, false);
00855 }
00856
00857
00858 void XMLElement::singleLineWriter(ostream& writer)
00859 {
00860 if (this->name.empty())
00861 {
00862 this->writeEncoded(writer, this->contents);
00863 return;
00864 }
00865
00866 writer << '<';
00867 writer << this->name;
00868
00869 if (! this->attributes.empty())
00870 {
00871 for(map<string,string>::iterator it=attributes.begin();
00872 it != attributes.end(); ++it)
00873 {
00874 writer << ' ';
00875 string key = it->first;
00876 string value = it->second;
00877 writer << key << '=' << '"';
00878 this->writeEncoded(writer,value);
00879 writer << '"';
00880 }
00881 }
00882
00883 if (!this->contents.empty())
00884 {
00885 writer << '>';
00886 this->writeEncoded(writer, this->contents);
00887 writer << '<';
00888 writer << '/';
00889 writer << this->name;
00890 writer << '>';
00891 }
00892 else if (this->children.empty())
00893 {
00894 writer << '/';
00895 writer << '>';
00896 }
00897 else
00898 {
00899 writer << '>';
00900
00901 for(list<XMLElement>::iterator it=children.begin();
00902 it != children.end(); ++it)
00903 {
00904 it->singleLineWriter(writer);
00905 }
00906
00907 writer << '<';
00908 writer << '/';
00909 writer << this->name;
00910 writer << '>';
00911 }
00912 }
00913
00914 void XMLElement::indent(ostream & writer, int depth)
00915 {
00916 for(int i=0; i<depth; i++)
00917 {
00918 writer << " ";
00919 }
00920 }
00921
00922 void XMLElement::write(string & file)
00923 {
00924 ofstream writer(file.c_str());
00925 this->prettyWriter(writer);
00926 writer.close();
00927 }
00928
00929 void XMLElement::prettyWriter(ostream& writer)
00930 {
00931 this->prettyWriter(writer, /*depth*/ 0);
00932 }
00933
00934 void XMLElement::prettyWriter(ostream& writer,int depth)
00935 {
00936 if (this->name.empty())
00937 {
00938 this->writeEncoded(writer, this->contents);
00939 return;
00940 }
00941
00942 this->indent(writer,depth);
00943 writer << '<';
00944 writer << this->name;
00945
00946 if (! this->attributes.empty())
00947 {
00948 for(map<string,string>::iterator it=attributes.begin();
00949 it != attributes.end(); ++it)
00950 {
00951 writer << ' ';
00952 string key = it->first;
00953 string value = it->second;
00954 writer << key << '=' << '"';
00955 this->writeEncoded(writer,value);
00956 writer << '"';
00957 }
00958 }
00959
00960 if (!this->contents.empty())
00961 {
00962 writer << '>';
00963 this->writeEncoded(writer, this->contents);
00964 writer << '<';
00965 writer << '/';
00966 writer << this->name;
00967 writer << '>';
00968 writer << '\n';
00969 }
00970 else if (this->children.empty())
00971 {
00972 writer << '/';
00973 writer << '>';
00974 writer << '\n';
00975 }
00976 else
00977 {
00978 writer << '>';
00979 writer << '\n';
00980
00981 for(list<XMLElement>::iterator it=children.begin();
00982 it != children.end(); ++it)
00983 {
00984 it->prettyWriter(writer,depth+1);
00985 }
00986
00987 this->indent(writer,depth);
00988 writer << '<';
00989 writer << '/';
00990 writer << this->name;
00991 writer << '>';
00992 writer << '\n';
00993 }
00994 }
00995
00996 void XMLElement::writeEncoded(ostream & writer,
00997 string & str)
00998 {
00999 for (unsigned int i = 0; i < str.length(); i += 1)
01000 {
01001 unsigned char ch = str.at(i);
01002
01003 switch (ch)
01004 {
01005 case '<':
01006 writer << "<";
01007 break;
01008 case '>':
01009 writer << ">";
01010 break;
01011 case '&':
01012 writer << "&";
01013 break;
01014 case '"':
01015 writer << """;
01016 break;
01017 case '\'':
01018 writer << "'";
01019 break;
01020 default:
01021 int unicode = (int) ch;
01022
01023 if ((unicode < 32) || (unicode > 126))
01024 {
01025 writer << "&#x" << StringManipulation::intToHexString(unicode);
01026 writer << ";";
01027 }
01028 else
01029 {
01030 writer << ch;
01031 }
01032 }
01033 }
01034 }
01035
01036
01037 void XMLElement::operator=(XMLElement & rhs)
01038 {
01039 this->entities = rhs.entities;
01040 this->lineNr = rhs.lineNr;
01041 this->ignoreWhitespace = rhs.ignoreWhitespace;
01042 this->name = rhs.name;
01043 this->contents = rhs.contents;
01044
01045 this->attributes.clear();
01046
01047 for(map<string,string>::iterator it=rhs.attributes.begin();
01048 it != rhs.attributes.end(); ++it)
01049 {
01050 this->attributes[it->first] = it->second;
01051 }
01052
01053 this->children.clear();
01054
01055 for(list<XMLElement>::iterator it=rhs.children.begin();
01056 it != rhs.children.end(); ++it)
01057 {
01058 XMLElement child = *it;
01059 this->children.push_back(child);
01060 }
01061 }
01062
01063 bool XMLElement::operator==(XMLElement & rhs)
01064 {
01065 // Check the easy fields
01066 if( this->name != rhs.name ) return false;
01067 if( this->contents != rhs.contents ) return false;
01068
01069 // Check for equal attributes
01070 if( this->attributes.size() != rhs.attributes.size() ) return false;
01071
01072 for(map<string,string>::iterator it=rhs.attributes.begin();
01073 it != rhs.attributes.end(); ++it)
01074 {
01075 if( this->attributes[it->first] != it->second ) return false;
01076 }
01077
01078 // Check for equal children
01079 if( this->children.size() != rhs.children.size() ) return false;
01080
01081 for(list<XMLElement>::iterator it1=rhs.children.begin();
01082 it1 != rhs.children.end(); ++it1)
01083 {
01084 bool childFound = false;
01085
01086 for(list<XMLElement>::iterator it2=this->children.begin();
01087 it2 != this->children.end(); ++it2)
01088 {
01089 if( *it1 == *it2 ) childFound = true;
01090 }
01091
01092 if( !childFound ) return false;
01093 }
01094
01095
01096 return true;
01097 }
01098
01099 XMLParseException XMLElement::invalidValueSet(string name)
01100 {
01101 string msg = "Invalid value set (entity name = \"" + name + "\")";
01102 return XMLParseException(this->getName(), this->parserLineNr, msg);
01103 }
01104
01105
01106 XMLParseException XMLElement::invalidValue(string name,
01107 string value)
01108 {
01109 string msg = "Attribute \"" + name + "\" does not contain a valid "
01110 + "value (\"" + value + "\")";
01111 return XMLParseException(this->getName(), this->parserLineNr, msg);
01112 }
01113
01114
01115 XMLParseException XMLElement::unexpectedEndOfData()
01116 {
01117 string msg = "Unexpected end of data reached";
01118 return XMLParseException(this->getName(), this->parserLineNr, msg);
01119 }
01120
01121
01122 XMLParseException XMLElement::syntaxError(string context)
01123 {
01124 string msg = "Syntax error while parsing " + context;
01125 return XMLParseException(this->getName(), this->parserLineNr, msg);
01126 }
01127
01128 XMLParseException XMLElement::unicodeError(int value)
01129 {
01130 string decUni = "#&" + StringManipulation::intToString(value) + ";";
01131 string hexUni = "#&x" + StringManipulation::intToHexString(value) + ";";
01132
01133 string msg = "Unicode error while parsing " + decUni + " or " + hexUni
01134 + ". Only ASCII values (� to Ā or � to Ā) are "
01135 + "currently supported.";
01136
01137 return XMLParseException(this->getName(), this->parserLineNr, msg);
01138 }
01139
01140 XMLParseException XMLElement::expectedInput(string charSet)
01141 {
01142 string msg = "Expected: " + charSet;
01143 return XMLParseException(this->getName(), this->parserLineNr, msg);
01144 }
01145
01146
01147 XMLParseException XMLElement::unknownEntity(string name)
01148 {
01149 string msg = "Unknown or invalid entity: &" + name + ";";
01150 return XMLParseException(this->getName(), this->parserLineNr, msg);
01151 }
01152
01153
01154