ReactOS 0.4.15-dev-7961-gdcf9eb0
XMLStorage::XMLNode Struct Reference

in memory representation of an XML node More...

#include <xmlstorage.h>

Inheritance diagram for XMLStorage::XMLNode:
Collaboration diagram for XMLStorage::XMLNode:

Classes

struct  AttributeMap
 map of XML node attributes More...
 
struct  Children
 internal children node list More...
 

Public Types

enum  COPY_FLAGS { COPY_NOCHILDREN }
 
- Public Types inherited from XMLStorage::XS_String
typedef std::string super
 

Public Member Functions

 XMLNode (const XS_String &name)
 
 XMLNode (const XS_String &name, const std::string &leading)
 
 XMLNode (const XMLNode &other)
 
 XMLNode (const XMLNode &other, COPY_FLAGS copy_no_children)
 
virtual ~XMLNode ()
 
void clear ()
 
XMLNodeoperator= (const XMLNode &other)
 
void add_child (XMLNode *child)
 add a new child node
 
void remove_children (const XS_String &name)
 remove all children named 'name'
 
void put (const XS_String &attr_name, const XS_String &value)
 write access to an attribute
 
XS_Stringoperator[] (const XS_String &attr_name)
 index operator write access to an attribute
 
template<typename T >
XS_String get (const T &attr_name, LPCXSSTR def=XS_EMPTY_STR) const
 read only access to an attribute
 
void erase (const XS_String &attr_name)
 remove the attribute 'attr_name'
 
XS_String subvalue (const XS_String &child_name, const XS_String &attr_name, int n=0) const
 convenient value access in children node
 
XS_Stringsubvalue (const XS_String &child_name, const XS_String &attr_name, int n=0)
 convenient storage of distinct values in children node
 
const Childrenget_children () const
 
Childrenget_children ()
 
const AttributeMapget_attributes () const
 
AttributeMapget_attributes ()
 
XS_String get_content () const
 read element node content
 
XS_String get_sub_content (const XPath &xpath) const
 read content of a subnode specified by an XPath expression
 
void set_content (const XS_String &s, bool cdata=false)
 set element node content
 
bool set_sub_content (const XPath &xpath, const XS_String &s, bool cdata=false)
 set content of a subnode specified by an XPath expression
 
bool write (std::ostream &out, const XMLFormat &format, WRITE_MODE mode=FORMAT_SMART, int indent=0) const
 write node with children tree to output stream
 
int count (const XPath &xpath) const
 count the nodes matching the given relative XPath expression
 
int count (XPath::const_iterator from, const XPath::const_iterator &to) const
 count the nodes matching the given relative XPath expression
 
bool filter (const XPath &xpath, XMLNode &target) const
 copy matching tree nodes using the given XPath filter expression
 
const XMLNodefind_relative (const XPath &xpath) const
 XPath find function (const)
 
XMLNodefind_relative (const XPath &xpath)
 XPath find function.
 
XMLNodeget_first_child () const
 
- Public Member Functions inherited from XMLStorage::XS_String
 XS_String ()
 
 XS_String (LPCXSSTR s)
 
 XS_String (LPCXSSTR s, size_t l)
 
 XS_String (const super &other)
 
 XS_String (const XS_String &other)
 
void assign (const XS_String &s)
 
XS_Stringoperator= (LPCXSSTR s)
 
XS_Stringoperator= (const super &s)
 
void assign (LPCXSSTR s)
 
void assign (LPCXSSTR s, size_t l)
 
 operator LPCXSSTR () const
 
XS_Stringprintf (LPCXSSTR fmt,...)
 
XS_Stringvprintf (LPCXSSTR fmt, va_list l)
 
XS_Stringappendf (LPCXSSTR fmt,...)
 
XS_Stringvappendf (LPCXSSTR fmt, va_list l)
 

Protected Member Functions

XMLNodecreate_relative (const XPath &xpath)
 relative XPath create function
 
XMLNodefilter (XPath::const_iterator from, const XPath::const_iterator &to) const
 create a new node tree using the given XPath filter expression
 
void original_write_worker (std::ostream &out) const
 write node with children tree to output stream using original white space
 
void plain_write_worker (std::ostream &out) const
 print node without any white space
 
void pretty_write_worker (std::ostream &out, const XMLFormat &format, int indent) const
 pretty print node with children tree to output stream
 
void smart_write_worker (std::ostream &out, const XMLFormat &format, int indent) const
 write node with children tree to output stream using smart formating
 

Protected Attributes

Children _children
 
AttributeMap _attributes
 
std::string _leading
 
std::string _content
 
std::string _end_leading
 
std::string _trailing
 
bool _cdata_content
 

Friends

struct XMLPos
 
struct const_XMLPos
 
struct XMLReaderBase
 
struct XPathElement
 

Detailed Description

in memory representation of an XML node

Definition at line 854 of file xmlstorage.h.

Member Enumeration Documentation

◆ COPY_FLAGS

Enumerator
COPY_NOCHILDREN 

Definition at line 1013 of file xmlstorage.h.

Constructor & Destructor Documentation

◆ XMLNode() [1/4]

XMLStorage::XMLNode::XMLNode ( const XS_String name)
inline

Definition at line 984 of file xmlstorage.h.

985 : XS_String(name),
986 _cdata_content(false)
987 {
988 }
Definition: name.c:39

◆ XMLNode() [2/4]

XMLStorage::XMLNode::XMLNode ( const XS_String name,
const std::string &  leading 
)
inline

Definition at line 990 of file xmlstorage.h.

991 : XS_String(name),
992 _leading(leading),
993 _cdata_content(false)
994 {
995 }
std::string _leading
Definition: xmlstorage.h:1273

◆ XMLNode() [3/4]

XMLStorage::XMLNode::XMLNode ( const XMLNode other)
inline

Definition at line 997 of file xmlstorage.h.

998 : XS_String(other),
999 _attributes(other._attributes),
1000 _leading(other._leading),
1001 _content(other._content),
1002 _end_leading(other._end_leading),
1003 _trailing(other._trailing),
1004#ifdef XMLNODE_LOCATION
1005 _location(other._location),
1006#endif
1007 _cdata_content(false)
1008 {
1009 for(Children::const_iterator it=other._children.begin(); it!=other._children.end(); ++it)
1010 _children.push_back(new XMLNode(**it));
1011 }
int other
Definition: msacm.c:1376
AttributeMap _attributes
Definition: xmlstorage.h:1271
std::string _content
Definition: xmlstorage.h:1274
std::string _end_leading
Definition: xmlstorage.h:1275
std::string _trailing
Definition: xmlstorage.h:1276
XMLNode(const XS_String &name)
Definition: xmlstorage.h:984

◆ XMLNode() [4/4]

XMLStorage::XMLNode::XMLNode ( const XMLNode other,
COPY_FLAGS  copy_no_children 
)
inline

Definition at line 1015 of file xmlstorage.h.

1016 : XS_String(other),
1017 _attributes(other._attributes),
1018 _leading(other._leading),
1019 _content(other._content),
1020 _end_leading(other._end_leading),
1021 _trailing(other._trailing),
1022#ifdef XMLNODE_LOCATION
1023 _location(other._location),
1024#endif
1025 _cdata_content(false)
1026 {
1027// assert(copy_no_children==COPY_NOCHILDREN);
1028 }

◆ ~XMLNode()

virtual XMLStorage::XMLNode::~XMLNode ( )
inlinevirtual

Definition at line 1030 of file xmlstorage.h.

1031 {
1032 while(!_children.empty()) {
1033 delete _children.back();
1034 _children.pop_back();
1035 }
1036 }

Member Function Documentation

◆ add_child()

void XMLStorage::XMLNode::add_child ( XMLNode child)
inline

add a new child node

Definition at line 1067 of file xmlstorage.h.

1068 {
1069 _children.push_back(child);
1070 }
static HWND child
Definition: cursoricon.c:298

Referenced by XMLStorage::XMLPos::add_down(), XMLStorage::XMLPos::create_node_content(), and subvalue().

◆ clear()

void XMLStorage::XMLNode::clear ( )
inline

Definition at line 1038 of file xmlstorage.h.

1039 {
1040 _leading.erase();
1041 _content.erase();
1042 _end_leading.erase();
1043 _trailing.erase();
1044
1045 _attributes.clear();
1046 _children.clear();
1047
1048 XS_String::erase();
1049 }

◆ count() [1/2]

int XMLStorage::XMLNode::count ( const XPath xpath) const
inline

count the nodes matching the given relative XPath expression

Definition at line 1244 of file xmlstorage.h.

1245 {
1246 return count(xpath.begin(), xpath.end());
1247 }
GLuint GLuint GLsizei count
Definition: gl.h:1545

Referenced by XMLStorage::XMLPos::count().

◆ count() [2/2]

int XMLStorage::XMLNode::count ( XPath::const_iterator  from,
const XPath::const_iterator &  to 
) const

count the nodes matching the given relative XPath expression

Definition at line 301 of file xmlstorage.cpp.

302{
303 const XPathElement& elem = *from++;
304 int cnt = 0;
305 int n = 0;
306
307 for(XMLNode::Children::const_iterator it=_children.begin(); it!=_children.end(); ++it)
308 if (elem.matches(**it, n)) {
309 if (from != to)
310 // iterate deeper
311 cnt += (*it)->count(from, to);
312 else
313 // increment match counter
314 ++cnt;
315 }
316
317 return cnt;
318}
GLdouble n
Definition: glext.h:7729
static size_t elem
Definition: string.c:68
CardRegion * from
Definition: spigame.cpp:19
friend struct XPathElement
Definition: xmlstorage.h:982

◆ create_relative()

XMLNode * XMLStorage::XMLNode::create_relative ( const XPath xpath)
protected

relative XPath create function

Definition at line 279 of file xmlstorage.cpp.

280{
281 XMLNode* node = this;
282
283 for(XPath::const_iterator it=xpath.begin(); it!=xpath.end(); ++it) {
284 XMLNode* child = it->find(node);
285
286 if (!child) {
287 child = new XMLNode(it->_child_name);
288 node->add_child(child);
289
290 if (!it->_attr_name.empty())
291 (*this)[it->_attr_name] = it->_attr_value;
292 }
293
294 node = child;
295 }
296
297 return node;
298}
Definition: dlist.c:348

Referenced by XMLStorage::XMLPos::create_relative(), and set_sub_content().

◆ erase()

void XMLStorage::XMLNode::erase ( const XS_String attr_name)
inline

remove the attribute 'attr_name'

Definition at line 1106 of file xmlstorage.h.

1107 {
1108 _attributes.erase(attr_name);
1109 }

Referenced by XMLStorage::XMLPos::erase(), and XMLStorage::XMLNode::Children::remove().

◆ filter() [1/2]

bool XMLStorage::XMLNode::filter ( const XPath xpath,
XMLNode target 
) const

copy matching tree nodes using the given XPath filter expression

Definition at line 321 of file xmlstorage.cpp.

322{
323 XMLNode* ret = filter(xpath.begin(), xpath.end());
324
325 if (ret) {
326 // move returned nodes to target node
327 target._children.move(ret->_children);
328 target._attributes = ret->_attributes;
329
330 delete ret;
331
332 return true;
333 } else
334 return false;
335}
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
GLenum target
Definition: glext.h:7315
int ret

Referenced by XMLStorage::XMLPos::filter().

◆ filter() [2/2]

XMLNode * XMLStorage::XMLNode::filter ( XPath::const_iterator  from,
const XPath::const_iterator &  to 
) const
protected

create a new node tree using the given XPath filter expression

Definition at line 338 of file xmlstorage.cpp.

339{
340 XMLNode* copy = NULL;
341
342 const XPathElement& elem = *from++;
343 int cnt = 0;
344 int n = 0;
345
346 for(XMLNode::Children::const_iterator it=_children.begin(); it!=_children.end(); ++it)
347 if (elem.matches(**it, n)) {
348 if (!copy)
350
351 if (from != to) {
352 XMLNode* ret = (*it)->filter(from, to);
353
354 if (ret) {
355 copy->add_child(ret);
356 ++cnt;
357 }
358 } else {
359 copy->add_child(new XMLNode(**it, XMLNode::COPY_NOCHILDREN));
360 ++cnt;
361 }
362 }
363
364 if (cnt > 0) {
365 return copy;
366 } else {
367 delete copy;
368 return NULL;
369 }
370}
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
#define NULL
Definition: types.h:112

◆ find_relative() [1/2]

XMLNode * XMLStorage::XMLNode::find_relative ( const XPath xpath)

XPath find function.

Definition at line 265 of file xmlstorage.cpp.

266{
267 XMLNode* node = this;
268
269 for(XPath::const_iterator it=xpath.begin(); it!=xpath.end(); ++it) {
270 node = it->find(node);
271
272 if (!node)
273 return NULL;
274 }
275
276 return node;
277}

◆ find_relative() [2/2]

const XMLNode * XMLStorage::XMLNode::find_relative ( const XPath xpath) const

XPath find function (const)

Definition at line 251 of file xmlstorage.cpp.

252{
253 const XMLNode* node = this;
254
255 for(XPath::const_iterator it=xpath.begin(); it!=xpath.end(); ++it) {
256 node = it->const_find(node);
257
258 if (!node)
259 return NULL;
260 }
261
262 return node;
263}

Referenced by get_sub_content().

◆ get()

template<typename T >
XS_String XMLStorage::XMLNode::get ( const T attr_name,
LPCXSSTR  def = XS_EMPTY_STR 
) const
inline

read only access to an attribute

Definition at line 1095 of file xmlstorage.h.

1096 {
1097 AttributeMap::const_iterator found = _attributes.find(attr_name);
1098
1099 if (found != _attributes.end())
1100 return found->second;
1101 else
1102 return def;
1103 }

Referenced by XMLStorage::const_XMLPos::get(), XMLStorage::XMLPos::get(), and XMLStorage::const_XMLPos::operator[]().

◆ get_attributes() [1/2]

AttributeMap & XMLStorage::XMLNode::get_attributes ( )
inline

Definition at line 1176 of file xmlstorage.h.

1177 {
1178 return _attributes;
1179 }

◆ get_attributes() [2/2]

const AttributeMap & XMLStorage::XMLNode::get_attributes ( ) const
inline

Definition at line 1171 of file xmlstorage.h.

1172 {
1173 return _attributes;
1174 }

◆ get_children() [1/2]

Children & XMLStorage::XMLNode::get_children ( )
inline

Definition at line 1166 of file xmlstorage.h.

1167 {
1168 return _children;
1169 }

◆ get_children() [2/2]

const Children & XMLStorage::XMLNode::get_children ( ) const
inline

Definition at line 1161 of file xmlstorage.h.

1162 {
1163 return _children;
1164 }

◆ get_content()

XS_String XMLStorage::XMLNode::get_content ( ) const
inline

read element node content

Definition at line 1182 of file xmlstorage.h.

1183 {
1184 return DecodeXMLString(_content);
1185 }
XS_String DecodeXMLString(const std::string &str)
decode XML string literals
Definition: xmlstorage.cpp:478

◆ get_first_child()

XMLNode * XMLStorage::XMLNode::get_first_child ( ) const
inline

Definition at line 1261 of file xmlstorage.h.

1262 {
1263 if (!_children.empty())
1264 return _children.front();
1265 else
1266 return NULL;
1267 }

Referenced by XMLStorage::XMLPos::go_down(), and XMLStorage::const_XMLPos::go_down().

◆ get_sub_content()

XS_String XMLStorage::XMLNode::get_sub_content ( const XPath xpath) const
inline

read content of a subnode specified by an XPath expression

Definition at line 1188 of file xmlstorage.h.

1189 {
1190 const XMLNode* node = find_relative(xpath);
1191
1192 if (node)
1193 return node->get_content();
1194 else
1195 return XS_EMPTY_STR;
1196 }
const XMLNode * find_relative(const XPath &xpath) const
XPath find function (const)
Definition: xmlstorage.cpp:251
#define XS_EMPTY_STR
Definition: xmlstorage.h:406

◆ operator=()

XMLNode & XMLStorage::XMLNode::operator= ( const XMLNode other)
inline

Definition at line 1051 of file xmlstorage.h.

1052 {
1053 _children.clear();
1054 _children.copy(other._children);
1055
1056 _attributes = other._attributes;
1057
1058 _leading = other._leading;
1059 _content = other._content;
1060 _end_leading = other._end_leading;
1061 _trailing = other._trailing;
1062
1063 return *this;
1064 }
void copy(const Children &other)
Definition: xmlstorage.h:943

◆ operator[]()

XS_String & XMLStorage::XMLNode::operator[] ( const XS_String attr_name)
inline

index operator write access to an attribute

Definition at line 1089 of file xmlstorage.h.

1090 {
1091 return _attributes[attr_name];
1092 }

◆ original_write_worker()

void XMLStorage::XMLNode::original_write_worker ( std::ostream &  out) const
protected

write node with children tree to output stream using original white space

Definition at line 528 of file xmlstorage.cpp.

529{
530 out << _leading << '<' << EncodeXMLString(*this);
531
532 for(AttributeMap::const_iterator it=_attributes.begin(); it!=_attributes.end(); ++it)
533 out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\"";
534
535 if (!_children.empty() || !_content.empty()) {
536 out << '>';
537
538 if (_cdata_content)
540 else
541 out << _content;
542
543 for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it)
544 (*it)->original_write_worker(out);
545
546 out << _end_leading << "</" << EncodeXMLString(*this) << '>';
547 } else
548 out << "/>";
549
550 out << _trailing;
551}
std::string EncodeXMLString(const XS_String &str, bool cdata)
encode XML string literals
Definition: xmlstorage.cpp:374
static FILE * out
Definition: regtests2xml.c:44
#define CDATA_START
Definition: xmlstorage.h:435
#define CDATA_END
Definition: xmlstorage.h:436

Referenced by write().

◆ plain_write_worker()

void XMLStorage::XMLNode::plain_write_worker ( std::ostream &  out) const
protected

print node without any white space

Definition at line 555 of file xmlstorage.cpp.

556{
557 out << '<' << EncodeXMLString(*this);
558
559 for(AttributeMap::const_iterator it=_attributes.begin(); it!=_attributes.end(); ++it)
560 out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\"";
561
562 // strip leading white space from content
563 const char* content = _content.c_str();
564 while(isspace((unsigned char)*content)) ++content;
565
566 if (!_children.empty() || *content) {
567 out << ">" << content;
568
569 for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it)
570 (*it)->plain_write_worker(out);
571
572 out << "</" << EncodeXMLString(*this) << ">";
573 } else
574 out << "/>";
575}
#define isspace(c)
Definition: acclib.h:69
content
Definition: atl_ax.c:994

Referenced by write().

◆ pretty_write_worker()

void XMLStorage::XMLNode::pretty_write_worker ( std::ostream &  out,
const XMLFormat format,
int  indent 
) const
protected

pretty print node with children tree to output stream

Definition at line 579 of file xmlstorage.cpp.

580{
581 for(int i=indent; i--; )
583
584 out << '<' << EncodeXMLString(*this);
585
586 for(AttributeMap::const_iterator it=_attributes.begin(); it!=_attributes.end(); ++it)
587 out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\"";
588
589 // strip leading white space from content
590 const char* content = _content.c_str();
591 while(isspace((unsigned char)*content)) ++content;
592
593 if (!_children.empty() || *content) {
594 out << '>' << content;
595
596 if (!_children.empty())
597 out << format._endl;
598
599 for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it)
600 (*it)->pretty_write_worker(out, format, indent+1);
601
602 for(int i=indent; i--; )
604
605 out << "</" << EncodeXMLString(*this) << '>' << format._endl;
606 } else
607 out << "/>" << format._endl;
608}
static const WCHAR indent[]
Definition: object.c:1156
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define XML_INDENT_SPACE
Definition: xmlstorage.h:617

Referenced by write().

◆ put()

void XMLStorage::XMLNode::put ( const XS_String attr_name,
const XS_String value 
)
inline

write access to an attribute

Definition at line 1083 of file xmlstorage.h.

1084 {
1085 _attributes[attr_name] = value;
1086 }
Definition: pdh_main.c:94

Referenced by XMLStorage::XMLPos::put().

◆ remove_children()

void XMLStorage::XMLNode::remove_children ( const XS_String name)
inline

remove all children named 'name'

Definition at line 1073 of file xmlstorage.h.

1074 {
1075 Children::iterator it, next=_children.begin();
1076
1077 while((it=next++) != _children.end())
1078 if (**it == name)
1079 _children.erase(it);
1080 }
static unsigned __int64 next
Definition: rand_nt.c:6

Referenced by XMLStorage::XMLPos::remove_children().

◆ set_content()

void XMLStorage::XMLNode::set_content ( const XS_String s,
bool  cdata = false 
)
inline

set element node content

Definition at line 1199 of file xmlstorage.h.

1200 {
1201 _content.assign(EncodeXMLString(s.c_str(), cdata));
1202 }
GLdouble s
Definition: gl.h:2039

Referenced by XMLStorage::XMLPos::create_node_content().

◆ set_sub_content()

bool XMLStorage::XMLNode::set_sub_content ( const XPath xpath,
const XS_String s,
bool  cdata = false 
)
inline

set content of a subnode specified by an XPath expression

Definition at line 1205 of file xmlstorage.h.

1206 {
1207 XMLNode* node = create_relative(xpath);
1208
1209 if (node) {
1210 node->set_content(s, cdata);
1211 return true;
1212 } else
1213 return false;
1214 }
XMLNode * create_relative(const XPath &xpath)
relative XPath create function
Definition: xmlstorage.cpp:279

◆ smart_write_worker()

void XMLStorage::XMLNode::smart_write_worker ( std::ostream &  out,
const XMLFormat format,
int  indent 
) const
protected

write node with children tree to output stream using smart formating

Definition at line 612 of file xmlstorage.cpp.

613{
614 // strip the first line feed from _leading
615 const char* leading = _leading.c_str();
616 if (*leading == '\n') ++leading;
617
618 if (!*leading)
619 for(int i=indent; i--; )
621 else
622 out << leading;
623
624 out << '<' << EncodeXMLString(*this);
625
626 for(AttributeMap::const_iterator it=_attributes.begin(); it!=_attributes.end(); ++it)
627 out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\"";
628
629 // strip leading white space from content
630 const char* content = _content.c_str();
631 while(isspace((unsigned char)*content)) ++content;
632
633 if (_children.empty() && !*content)
634 out << "/>";
635 else {
636 out << '>';
637
638 if (_cdata_content)
640 else if (!*content)
641 out << format._endl;
642 else
643 out << content;
644
645 Children::const_iterator it = _children.begin();
646
647 if (it != _children.end()) {
648 for(; it!=_children.end(); ++it)
649 (*it)->smart_write_worker(out, format, indent+1);
650
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;
654
655 if (!*end_leading)
656 for(int i=indent; i--; )
658 else
659 out << end_leading;
660 } else
661 out << _end_leading;
662
663 out << "</" << EncodeXMLString(*this) << '>';
664 }
665
666 if (_trailing.empty())
667 out << format._endl;
668 else
669 out << _trailing;
670}

Referenced by write().

◆ subvalue() [1/2]

XS_String & XMLStorage::XMLNode::subvalue ( const XS_String child_name,
const XS_String attr_name,
int  n = 0 
)
inline

convenient storage of distinct values in children node

Definition at line 1123 of file xmlstorage.h.

1124 {
1125 XMLNode* node = XPathElement(child_name, n).find(this);
1126
1127 if (!node) {
1128 node = new XMLNode(child_name);
1129 add_child(node);
1130 }
1131
1132 return (*node)[attr_name];
1133 }
void add_child(XMLNode *child)
add a new child node
Definition: xmlstorage.h:1067

◆ subvalue() [2/2]

XS_String XMLStorage::XMLNode::subvalue ( const XS_String child_name,
const XS_String attr_name,
int  n = 0 
) const
inline

convenient value access in children node

Definition at line 1112 of file xmlstorage.h.

1113 {
1114 const XMLNode* node = XPathElement(child_name, n).const_find(this);
1115
1116 if (node)
1117 return node->get(attr_name);
1118 else
1119 return XS_String();
1120 }

◆ write()

bool XMLStorage::XMLNode::write ( std::ostream &  out,
const XMLFormat format,
WRITE_MODE  mode = FORMAT_SMART,
int  indent = 0 
) const
inline

write node with children tree to output stream

Definition at line 1221 of file xmlstorage.h.

1222 {
1223 switch(mode) {
1224 case FORMAT_PLAIN:
1226 break;
1227
1228 case FORMAT_PRETTY:
1230 break;
1231
1232 case FORMAT_ORIGINAL:
1234 break;
1235
1236 default: // FORMAT_SMART
1238 }
1239
1240 return out.good();
1241 }
GLenum mode
Definition: glext.h:6217
@ FORMAT_ORIGINAL
preserve original white space and comments if present; pretty print otherwise
Definition: xmlstorage.h:807
@ FORMAT_PRETTY
write XML stream preserving original white space and comments
Definition: xmlstorage.h:808
void smart_write_worker(std::ostream &out, const XMLFormat &format, int indent) const
write node with children tree to output stream using smart formating
Definition: xmlstorage.cpp:612
void pretty_write_worker(std::ostream &out, const XMLFormat &format, int indent) const
pretty print node with children tree to output stream
Definition: xmlstorage.cpp:579
void plain_write_worker(std::ostream &out) const
print node without any white space
Definition: xmlstorage.cpp:555
void original_write_worker(std::ostream &out) const
write node with children tree to output stream using original white space
Definition: xmlstorage.cpp:528

Friends And Related Function Documentation

◆ const_XMLPos

friend struct const_XMLPos
friend

Definition at line 980 of file xmlstorage.h.

◆ XMLPos

friend struct XMLPos
friend

Definition at line 979 of file xmlstorage.h.

◆ XMLReaderBase

friend struct XMLReaderBase
friend

Definition at line 981 of file xmlstorage.h.

◆ XPathElement

friend struct XPathElement
friend

Definition at line 982 of file xmlstorage.h.

Referenced by subvalue().

Member Data Documentation

◆ _attributes

◆ _cdata_content

bool XMLStorage::XMLNode::_cdata_content
protected

◆ _children

◆ _content

◆ _end_leading

std::string XMLStorage::XMLNode::_end_leading
protected

◆ _leading

std::string XMLStorage::XMLNode::_leading
protected

Definition at line 1273 of file xmlstorage.h.

Referenced by clear(), operator=(), original_write_worker(), and smart_write_worker().

◆ _trailing

std::string XMLStorage::XMLNode::_trailing
protected

The documentation for this struct was generated from the following files: