43 #define XS_NO_COMMENT // no #pragma comment(lib, ...) statements in .lib files to enable static linking 92 const char*
end =
s +
l;
160 const char*
p =
expr.c_str();
167 const char* at =
strchr(
p,
'@');
188 for(XMLNode::Children::const_iterator it=
node->_children.begin(); it!=
node->_children.end(); ++it)
199 for(XMLNode::Children::const_iterator it=
node->_children.begin(); it!=
node->_children.end(); ++it)
255 for(XPath::const_iterator it=xpath.begin(); it!=xpath.end(); ++it) {
269 for(XPath::const_iterator it=xpath.begin(); it!=xpath.end(); ++it) {
283 for(XPath::const_iterator it=xpath.begin(); it!=xpath.end(); ++it) {
290 if (!it->_attr_name.empty())
291 (*
this)[it->_attr_name] = it->_attr_value;
307 for(XMLNode::Children::const_iterator it=
_children.begin(); it!=
_children.end(); ++it)
308 if (
elem.matches(**it,
n)) {
311 cnt += (*it)->count(
from, to);
346 for(XMLNode::Children::const_iterator it=
_children.begin(); it!=
_children.end(); ++it)
347 if (
elem.matches(**it,
n)) {
383 #ifdef XS_STRING_UTF8 399 *o++ =
'&'; *o++ =
'a'; *o++ =
'm'; *o++ =
'p'; *o++ =
';';
403 *o++ =
'&'; *o++ =
'l'; *o++ =
't'; *o++ =
';';
407 *o++ =
'&'; *o++ =
'g'; *o++ =
't'; *o++ =
';';
411 *o++ =
'&'; *o++ =
'q'; *o++ =
'u'; *o++ =
'o'; *o++ =
't'; *o++ =
';';
415 *o++ =
'&'; *o++ =
'a'; *o++ =
'p'; *o++ =
'o'; *o++ =
's'; *o++ =
';';
419 if ((
unsigned)*
p<0x20 && *
p!=
'\t' && *
p!=
'\r' && *
p!=
'\n') {
422 for(
const char*
q=
b; *
q; )
428 #ifdef XS_STRING_UTF8 463 if ((
unsigned)*
p<0x20 && *
p!=
'\t' && *
p!=
'\r' && *
p!=
'\n')
469 #ifdef XS_STRING_UTF8 472 return get_utf8(
out.str());
480 #ifdef XS_STRING_UTF8 484 assign_utf8(str_utf8,
str.c_str(),
str.length());
539 out << CDATA_START << _content << CDATA_END; 543 for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it) 544 (*it)->original_write_worker(out); 546 out << _end_leading << "</" << EncodeXMLString(*this) << '>
'; 555 void XMLNode::plain_write_worker(std::ostream& out) const 557 out << '<
' << EncodeXMLString(*this); 559 for(AttributeMap::const_iterator it=_attributes.begin(); it!=_attributes.end(); ++it) 560 out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\""; 562 // strip leading white space from content 563 const char* content = _content.c_str(); 564 while(isspace((unsigned char)*content)) ++content; 566 if (!_children.empty() || *content) { 567 out << ">" << content; 569 for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it) 570 (*it)->plain_write_worker(out); 572 out << "</" << EncodeXMLString(*this) << ">"; 579 void XMLNode::pretty_write_worker(std::ostream& out, const XMLFormat& format, int indent) const 581 for(int i=indent; i--; ) 582 out << XML_INDENT_SPACE; 584 out << '<
' << EncodeXMLString(*this); 586 for(AttributeMap::const_iterator it=_attributes.begin(); it!=_attributes.end(); ++it) 587 out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\""; 589 // strip leading white space from content 590 const char* content = _content.c_str(); 591 while(isspace((unsigned char)*content)) ++content; 593 if (!_children.empty() || *content) { 594 out << '>
' << content; 596 if (!_children.empty()) 599 for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it) 600 (*it)->pretty_write_worker(out, format, indent+1); 602 for(int i=indent; i--; ) 603 out << XML_INDENT_SPACE; 605 out << "</" << EncodeXMLString(*this) << '>
' << format._endl; 607 out << "/>" << format._endl; 612 void XMLNode::smart_write_worker(std::ostream& out, const XMLFormat& format, int indent) const 614 // strip the first line feed from _leading 615 const char* leading = _leading.c_str(); 616 if (*leading == '\n') ++leading; 619 for(int i=indent; i--; ) 620 out << XML_INDENT_SPACE; 624 out << '<
' << EncodeXMLString(*this); 626 for(AttributeMap::const_iterator it=_attributes.begin(); it!=_attributes.end(); ++it) 627 out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\""; 629 // strip leading white space from content 630 const char* content = _content.c_str(); 631 while(isspace((unsigned char)*content)) ++content; 633 if (_children.empty() && !*content) 639 out << CDATA_START << _content << CDATA_END; 645 Children::const_iterator it = _children.begin(); 647 if (it != _children.end()) { 648 for(; it!=_children.end(); ++it) 649 (*it)->smart_write_worker(out, format, indent+1); 651 // strip the first line feed from _end_leading 652 const char* end_leading = _end_leading.c_str(); 653 if (*end_leading == '\n') ++end_leading; 656 for(int i=indent; i--; ) 657 out << XML_INDENT_SPACE; 663 out << "</" << EncodeXMLString(*this) << '>
'; 666 if (_trailing.empty()) 673 std::ostream& operator<<(std::ostream& out, const XMLError& err) 675 out << err._systemId << "(" << err._line << ") [column " << err._column << "] : " 682 const char* get_xmlsym_end_utf8(const char* p) 687 // NameChar ::= Letter | Digit | '.
' | '-
' | '_' | ':
' | CombiningChar | Extender 688 if (c == '\xC3
') // UTF-8 escape character 689 ++p; //TODO only continue on umlaut characters 690 else if (!isalnum(c) && c!='.
' && c!='-
' && c!='_' && c!=':
') 698 void DocType::parse(const char* p) 700 while(isspace((unsigned char)*p)) ++p; 702 const char* start = p; 703 p = get_xmlsym_end_utf8(p); 704 _name.assign(start, p-start); 706 while(isspace((unsigned char)*p)) ++p; 709 p = get_xmlsym_end_utf8(p); 710 std::string keyword(p, p-start); // "PUBLIC" or "SYSTEM" 712 while(isspace((unsigned char)*p)) ++p; 714 if (*p=='"' || *p=='\'') { 718 while(*p && *p!=delim) ++p; 721 _public.assign(start, p++-start); 725 while(isspace((unsigned char)*p)) ++p; 727 if (*p=='"' || *p=='\
'') {
731 while(*
p && *
p!=delim) ++
p;
742 out <<
"<?xml version=\"" << _version <<
"\" encoding=\"" << _encoding <<
"\"";
744 if (_standalone != -1)
745 out <<
" standalone=\"yes\"";
752 if (!_doctype.empty()) {
753 out <<
"<!DOCTYPE " << _doctype._name;
755 if (!_doctype._public.empty()) {
756 out <<
" PUBLIC \"" << _doctype._public <<
'"';
761 out <<
" \"" << _doctype._system <<
'"';
762 }
else if (!_doctype._system.empty())
763 out <<
" SYSTEM \"" << _doctype._system <<
'"';
771 for(StyleSheetList::const_iterator it=_stylesheets.begin(); it!=_stylesheets.end(); ++it) {
788 out <<
"<?xml-stylesheet" 789 " href=\"" << _href <<
"\"" 790 " type=\"" << _type <<
"\"";
793 out <<
" title=\"" << _title <<
"\"";
796 out <<
" media=\"" << _media <<
"\"";
798 if (!_charset.empty())
799 out <<
" charset=\"" << _charset <<
"\"";
802 out <<
" alternate=\"yes\"";
824 for(const_iterator it=
begin(); it!=
end(); ++it)
833 if (_pos->_children.empty())
836 _pos->_children.back()->_trailing.append(
_content);
851 _format._standalone = standalone;
868 if (_pos->_children.empty()) {
869 if (_last_tag == TAG_START)
870 _pos->_content.append(
s,
p-
s);
871 else if (_last_tag == TAG_END)
872 _pos->_trailing.append(
s,
p-
s);
876 _pos->_children.back()->_trailing.append(
s,
p-
s);
882 leading.assign(
p,
e-
p);
888 #ifdef XMLNODE_LOCATION 892 node->_attributes = attributes;
894 _last_tag = TAG_START;
909 _pos->_cdata_content =
true;
916 _pos->_cdata_content =
false;
920 if (_pos->_children.empty())
921 _pos->_content.append(
s,
p-
s);
922 else if (_last_tag == TAG_START)
923 _pos->_content.append(
s,
p-
s);
925 _pos->_children.back()->_trailing.append(
s,
p-
s);
929 _pos->_end_leading.assign(
p,
e-
p);
937 #if defined(XS_USE_XERCES) || defined(XS_USE_EXPAT) 941 #if defined(XML_UNICODE) || defined(XS_USE_XERCES) 954 if (!_stack.empty()) {
957 if (
last._state < PRE_CLOSED) {
958 write_attributes(
last);
974 if (!_stack.empty()) {
975 write_post(_stack.top());
987 entry._state = PRE_CLOSED; 990 void XMLWriter::write_pre(StackEntry& entry) 992 if (_format._pretty >= PRETTY_LINEFEED) 993 _out << _format._endl; 995 if (_format._pretty == PRETTY_INDENT) { 996 for(size_t i=_stack.size(); --i>0; ) 997 _out << XML_INDENT_SPACE; 1000 _out << '<
' << EncodeXMLString(entry._node_name); 1001 //entry._state = PRE; 1004 void XMLWriter::write_attributes(StackEntry& entry) 1006 for(AttrMap::const_iterator it=entry._attributes.begin(); it!=entry._attributes.end(); ++it) 1007 _out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\""; 1009 entry._state = ATTRIBUTES; 1012 void XMLWriter::write_post(StackEntry& entry) 1014 if (entry._state < ATTRIBUTES) 1015 write_attributes(entry); 1017 if (entry._children || !entry._content.empty()) { 1018 if (entry._state < PRE_CLOSED) 1021 _out << entry._content; 1022 //entry._state = CONTENT; 1024 if (_format._pretty>=PRETTY_LINEFEED && entry._content.empty()) 1025 _out << _format._endl; 1027 if (_format._pretty==PRETTY_INDENT && entry._content.empty()) { 1028 for(size_t i=_stack.size(); --i>0; ) 1029 _out << XML_INDENT_SPACE; 1032 _out << "</" << EncodeXMLString(entry._node_name) << ">"; 1037 entry._state = POST; 1041 } // namespace XMLStorage XMLNode(const XS_String &name)
const XMLNode * find_relative(const XPath &xpath) const
XPath find function (const)
basic_ostream< char, char_traits< char > > ostream
XMLNode * find(XMLNode *node) const
basic_ostringstream< char, char_traits< char >, allocator< char > > ostringstream
ACPI_SIZE strlen(const char *String)
const XS_String XS_PROPERTY
GLsizei const GLchar ** path
static std::string unescape(const char *s, char b, char e)
remove escape characters from zero terminated string
void create(const XS_String &name)
create node and move to it
std::ostringstream fast_ostringstream
virtual void StartElementHandler(const XS_String &name, const XMLNode::AttributeMap &attributes)
notifications about XML start tag
bool back()
go back to previous position
#define sprintf(buf, format,...)
container for XMLWriter state information
basic_ostream< _CharT, _Traits > &_STLP_CALL endl(basic_ostream< _CharT, _Traits > &__os)
int count(const XPath &xpath) const
count the nodes matching the given relative XPath expression
map of XML node attributes
void go_to(const XMLNode *child)
go to specified node
virtual void XmlDeclHandler(const char *version, const char *encoding, int standalone)
store XML version and encoding into XML reader
static const WCHAR version[]
std::string str() const
return formated error message
XS_String DecodeXMLString(const std::string &str)
decode XML string literals
GLboolean GLboolean GLboolean b
bool matches(const XMLNode &node, int &n) const
in memory representation of an XML node
void go_to(XMLNode *child)
go to specified node
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
GLdouble GLdouble GLdouble GLdouble q
static HRESULT get_location(HTMLInnerWindow *This, HTMLLocation **ret)
void assign(const XS_String &s)
const XMLNode * const_find(const XMLNode *node) const
#define memcpy(s1, s2, n)
const char * parse(const char *path)
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
virtual void EndElementHandler()
notifications about XML end tag
std::string EncodeXMLString(const XS_String &str, bool cdata)
encode XML string literals
char * strchr(const char *String, int ch)
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
bool filter(const XPath &xpath, XMLNode &target) const
copy matching tree nodes using the given XPath filter expression
void init(const char *path)
bool go(const XPath &xpath)
move to the position defined by xpath in XML tree
bool go(const XPath &xpath)
move to the position defined by xpath in XML tree
void print(std::ostream &out) const
XMLNode * create_relative(const XPath &xpath)
relative XPath create function
void close_pre(StackEntry &entry)
virtual void DefaultHandler(const std::string &s)
store content, white space and comments
void original_write_worker(std::ostream &out) const
write node with children tree to output stream using original white space
string class for TCHAR strings
static unsigned(__cdecl *hash_bstr)(bstr_t s)
XS_String str() const
return merged error strings
static XS_String s_empty_attr
GLuint const GLchar * name