xmlstorage-commits Mailing List for XMLStorage
Brought to you by:
martinfuchs
You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(7) |
Feb
(10) |
Mar
(1) |
Apr
|
May
(7) |
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <mar...@us...> - 2008-07-13 08:10:04
|
Revision: 99 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=99&view=rev Author: martinfuchs Date: 2008-07-13 01:10:12 -0700 (Sun, 13 Jul 2008) Log Message: ----------- also allow dots in XML names to fulfill the XML specification Modified Paths: -------------- trunk/c++/xmlstorage.cpp Modified: trunk/c++/xmlstorage.cpp =================================================================== --- trunk/c++/xmlstorage.cpp 2008-07-13 07:39:12 UTC (rev 98) +++ trunk/c++/xmlstorage.cpp 2008-07-13 08:10:12 UTC (rev 99) @@ -665,9 +665,10 @@ for(; *p; ++p) { char c = *p; + // NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender if (c == '\xC3') // UTF-8 escape character ++p; //TODO only continue on umlaut characters - else if (!isalnum(c) && c!='_' && c!='-' && c!=':') + else if (!isalnum(c) && c!='.' && c!='-' && c!='_' && c!=':') break; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-07-13 07:39:05
|
Revision: 98 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=98&view=rev Author: martinfuchs Date: 2008-07-13 00:39:12 -0700 (Sun, 13 Jul 2008) Log Message: ----------- allow colons in attribute names (extended by Tobias Lange) Modified Paths: -------------- trunk/c++/xmlstorage.cpp Modified: trunk/c++/xmlstorage.cpp =================================================================== --- trunk/c++/xmlstorage.cpp 2008-05-30 12:11:47 UTC (rev 97) +++ trunk/c++/xmlstorage.cpp 2008-07-13 07:39:12 UTC (rev 98) @@ -667,7 +667,7 @@ if (c == '\xC3') // UTF-8 escape character ++p; //TODO only continue on umlaut characters - else if (!isalnum(c) && c!='_' && c!='-') + else if (!isalnum(c) && c!='_' && c!='-' && c!=':') break; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-05-30 12:11:39
|
Revision: 97 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=97&view=rev Author: martinfuchs Date: 2008-05-30 05:11:47 -0700 (Fri, 30 May 2008) Log Message: ----------- avoid duplicate variable definition Modified Paths: -------------- trunk/java/src/de/mfuchs/xmlstorage/XMLReader.java Modified: trunk/java/src/de/mfuchs/xmlstorage/XMLReader.java =================================================================== --- trunk/java/src/de/mfuchs/xmlstorage/XMLReader.java 2008-05-30 12:03:59 UTC (rev 96) +++ trunk/java/src/de/mfuchs/xmlstorage/XMLReader.java 2008-05-30 12:11:47 UTC (rev 97) @@ -153,7 +153,7 @@ i = _content.length(); else { // search for content end leaving only whitespaces for leading - int i = _content.length(); + i = _content.length(); for (; i>0; i--) { char ch = _content.charAt(i-1); if (!Character.isWhitespace(ch)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-05-30 12:03:51
|
Revision: 96 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=96&view=rev Author: martinfuchs Date: 2008-05-30 05:03:59 -0700 (Fri, 30 May 2008) Log Message: ----------- adjust constness for find calls Modified Paths: -------------- trunk/c++/xmlstorage.h Modified: trunk/c++/xmlstorage.h =================================================================== --- trunk/c++/xmlstorage.h 2008-05-30 12:03:14 UTC (rev 95) +++ trunk/c++/xmlstorage.h 2008-05-30 12:03:59 UTC (rev 96) @@ -1111,7 +1111,7 @@ /// convenient value access in children node XS_String subvalue(const char* child_name, const char* attr_name, int n=0) const { - const XMLNode* node = XPathElement(child_name, n).find(this); + const XMLNode* node = XPathElement(child_name, n).const_find(this); if (node) return node->get(attr_name); @@ -1120,7 +1120,7 @@ } /// convenient storage of distinct values in children node - XS_String& subvalue(const char* name, const XS_String& attr_name, int n=0) + XS_String& subvalue(const char* child_name, const XS_String& attr_name, int n=0) { XMLNode* node = XPathElement(child_name, n).find(this); @@ -1645,7 +1645,7 @@ /// create node if not already existing and move to it void smart_create(const char* child_name) { - XMLNode* node = _cur->find(child_name); + XMLNode* node = XPathElement(child_name).find(_cur); if (node) go_to(node); @@ -1657,12 +1657,12 @@ template<typename T, typename U> void smart_create(const char* child_name, const T& attr_name, const U& attr_value) { - XMLNode* node = _cur->find(child_name, attr_name, attr_value); + XMLNode* node = XPathElement(child_name, 0, attr_name, attr_value).find(_cur); if (node) go_to(node); else { - XMLNode* node = new XMLNode(child_name); + node = new XMLNode(child_name); add_down(node); (*node)[attr_name] = attr_value; } @@ -1801,7 +1801,7 @@ /// search for child and go down bool go_down(const char* child_name, int n=0) { - XMLNode* node = XPathElement(child_name, n).const_find(_cur); + const XMLNode* node = XPathElement(child_name, n).const_find(_cur); if (node) { go_to(node); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-05-30 12:03:08
|
Revision: 95 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=95&view=rev Author: martinfuchs Date: 2008-05-30 05:03:14 -0700 (Fri, 30 May 2008) Log Message: ----------- Unicode string wrapper Modified Paths: -------------- trunk/c++/xmlstorage.cpp Modified: trunk/c++/xmlstorage.cpp =================================================================== --- trunk/c++/xmlstorage.cpp 2008-05-30 12:02:36 UTC (rev 94) +++ trunk/c++/xmlstorage.cpp 2008-05-30 12:03:14 UTC (rev 95) @@ -204,7 +204,7 @@ bool XPathElement::matches(const XMLNode& node, int& n) const { if (node != _child_name) - if (_child_name != "*") // use asterisk as wildcard + if (_child_name != XS_TEXT("*")) // use asterisk as wildcard return false; if (!_attr_name.empty()) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-05-30 12:02:28
|
Revision: 94 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=94&view=rev Author: martinfuchs Date: 2008-05-30 05:02:36 -0700 (Fri, 30 May 2008) Log Message: ----------- fix problems with the Xerces interface of XMLStorage reported by Tobias Lange Modified Paths: -------------- trunk/c++/xs-xerces.cpp Modified: trunk/c++/xs-xerces.cpp =================================================================== --- trunk/c++/xs-xerces.cpp 2008-05-30 12:01:49 UTC (rev 93) +++ trunk/c++/xs-xerces.cpp 2008-05-30 12:02:36 UTC (rev 94) @@ -1,8 +1,8 @@ // - // XML storage C++ classes version 1.2 + // XML storage C++ classes version 1.3 // - // Copyright (c) 2006 Martin Fuchs <mar...@gm...> + // Copyright (c) 2006, 2008 Martin Fuchs <mar...@gm...> // /// \file xs-xerces.cpp @@ -62,7 +62,7 @@ { XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::Initialize(); } -}; +} s_XercesInit; XMLReaderBase::XMLReaderBase(XMLNode* node, InputSource* source, bool adoptSource) @@ -137,7 +137,7 @@ { } -XercesXMLReader::XercesXMLReader(XMLNode* node, const XMLByte* buffer, size_t bytes, const std::string& system_id=std::string()) +XercesXMLReader::XercesXMLReader(XMLNode* node, const XMLByte* buffer, size_t bytes, const std::string& system_id) #ifdef UNICODE : XMLReaderBase(node, new XERCES_CPP_NAMESPACE_QUALIFIER MemBufInputSource(buffer, bytes, system_id, true) #else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-05-30 12:01:41
|
Revision: 93 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=93&view=rev Author: martinfuchs Date: 2008-05-30 05:01:49 -0700 (Fri, 30 May 2008) Log Message: ----------- update local path Modified Paths: -------------- trunk/c++/Makefile.VC6 Modified: trunk/c++/Makefile.VC6 =================================================================== --- trunk/c++/Makefile.VC6 2008-05-30 08:23:51 UTC (rev 92) +++ trunk/c++/Makefile.VC6 2008-05-30 12:01:49 UTC (rev 93) @@ -1,8 +1,8 @@ PROJ = xmlstorage -INCL_PATH = E:\include -LIB32 = E:\lib32 -HTML_DIR = E:\html\newhome +INCL_PATH = W:\include +LIB32 = W:\lib32 +HTML_DIR = W:\html\newhome CFLAGS = -nologo -GX LFLAGS = -nologo This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-05-30 08:23:52
|
Revision: 92 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=92&view=rev Author: martinfuchs Date: 2008-05-30 01:23:51 -0700 (Fri, 30 May 2008) Log Message: ----------- don't clip whitespace in CDATA sections Modified Paths: -------------- trunk/java/src/de/mfuchs/xmlstorage/XMLReader.java Modified: trunk/java/src/de/mfuchs/xmlstorage/XMLReader.java =================================================================== --- trunk/java/src/de/mfuchs/xmlstorage/XMLReader.java 2008-05-01 21:39:07 UTC (rev 91) +++ trunk/java/src/de/mfuchs/xmlstorage/XMLReader.java 2008-05-30 08:23:51 UTC (rev 92) @@ -147,12 +147,18 @@ public void endElement(String uri, String localName, String qName) throws SAXException { - // search for content end leaving only whitespaces for leading - int i = _content.length(); - for (; i>0; i--) { - char ch = _content.charAt(i-1); - if (!Character.isWhitespace(ch)) - break; + int i; + + if (_isContentCDATA) + i = _content.length(); + else { + // search for content end leaving only whitespaces for leading + int i = _content.length(); + for (; i>0; i--) { + char ch = _content.charAt(i-1); + if (!Character.isWhitespace(ch)) + break; + } } if (i > 0) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-05-01 21:39:09
|
Revision: 91 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=91&view=rev Author: martinfuchs Date: 2008-05-01 14:39:07 -0700 (Thu, 01 May 2008) Log Message: ----------- add brace Modified Paths: -------------- trunk/c++/xs-native.cpp Modified: trunk/c++/xs-native.cpp =================================================================== --- trunk/c++/xs-native.cpp 2008-03-31 11:16:06 UTC (rev 90) +++ trunk/c++/xs-native.cpp 2008-05-01 21:39:07 UTC (rev 91) @@ -356,7 +356,7 @@ // read white space for(;;) { // check for the encoding of the first line end - if (!_endl_defined) + if (!_endl_defined) { if (c == '\n') { _format._endl = "\n"; _endl_defined = true; @@ -364,6 +364,7 @@ _format._endl = "\r\n"; _endl_defined = true; } + } c = get(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-03-31 11:16:03
|
Revision: 90 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=90&view=rev Author: martinfuchs Date: 2008-03-31 04:16:06 -0700 (Mon, 31 Mar 2008) Log Message: ----------- parsing of multiline content Modified Paths: -------------- trunk/java/src/de/mfuchs/xmlstorage/XMLReader.java Modified: trunk/java/src/de/mfuchs/xmlstorage/XMLReader.java =================================================================== --- trunk/java/src/de/mfuchs/xmlstorage/XMLReader.java 2008-02-07 22:27:25 UTC (rev 89) +++ trunk/java/src/de/mfuchs/xmlstorage/XMLReader.java 2008-03-31 11:16:06 UTC (rev 90) @@ -62,8 +62,8 @@ SAXParserFactory factory = SAXParserFactory.newInstance(); _parser = factory.newSAXParser(); - // Aktivierung der CDATA-Benachrichtigungen - _parser.setProperty("http://xml.org/sax/properties/lexical-handler", this); + // Aktivierung der CDATA-Benachrichtigungen + _parser.setProperty("http://xml.org/sax/properties/lexical-handler", this); _last_tag = TAG_NONE; } @@ -71,7 +71,7 @@ /// read XML stream into XML tree below _pos void read(InputSource source) throws SAXException, IOException { - _parser.parse(source, this); + _parser.parse(source, this); if (_pos.cur()._children.isEmpty()) _pos.cur()._trailing += _content; @@ -79,11 +79,11 @@ _pos.cur()._children.back()._trailing += _content; _content = ""; - _isContentCDATA = false; + _isContentCDATA = false; } protected XMLPos _pos; - protected SAXParser _parser; + protected SAXParser _parser; protected String _xml_version; protected String _encoding; @@ -93,7 +93,7 @@ protected static final int TAG_NONE = 0; protected static final int TAG_START = 1; protected static final int TAG_END = 2; - int _last_tag; // enum + int _last_tag; // enum /* information about XML version and encoding not available using SAX parser @@ -102,16 +102,16 @@ protected static void XMLCALL XML_XmlDeclHandler(void* userData, const XML_Char* version, const XML_Char* encoding, int standalone); */ - public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException + public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { - // search for end of first line - int i = _content.indexOf('\n'); + // search for content end leaving only whitespaces for _end_leading + int i = _content.length(); + for (; i>0; i--) { + char ch = _content.charAt(i-1); + if (!Character.isWhitespace(ch)) + break; + } - if (i != -1) - ++i; - else - i = _content.length(); - if (i > 0) if (_pos.cur()._children.isEmpty()) { // no children in last node? if (_last_tag == TAG_START) @@ -133,7 +133,7 @@ _pos.addDown(node); for(int n=0; n<attributes.getLength(); ++n) { - final String attrName = attributes.getQName(n); + final String attrName = attributes.getQName(n); final String attr_value = attributes.getValue(n); node.put(attrName, attr_value); @@ -142,27 +142,21 @@ _last_tag = TAG_START; _content = ""; - _isContentCDATA = false; + _isContentCDATA = false; } - public void endElement(String uri, String localName, String qName) throws SAXException - { - // search for end of first line - int i; + public void endElement(String uri, String localName, String qName) throws SAXException + { + // search for content end leaving only whitespaces for leading + int i = _content.length(); + for (; i>0; i--) { + char ch = _content.charAt(i-1); + if (!Character.isWhitespace(ch)) + break; + } - if (_isContentCDATA) - i = _content.length(); - else { - i = _content.indexOf('\n'); - - if (i != -1) - ++i; - else - i = _content.length(); - } - if (i > 0) - if (_pos.cur()._children.isEmpty()) // no children in current node? + if (_pos.cur()._children.isEmpty()) // no children in current node? _pos.cur()._content += _content.substring(0, i); else if (_last_tag == TAG_START) @@ -177,44 +171,44 @@ _last_tag = TAG_END; _content = ""; - _isContentCDATA = false; - } + _isContentCDATA = false; + } - public void characters(char ch[], int start, int length) throws SAXException - { - // encode _content compatible to XMLNode.setContent() - _content += XMLHelper.encodeXMLString(new String(ch, start, length)); + public void characters(char ch[], int start, int length) throws SAXException + { + // encode _content compatible to XMLNode.setContent() + _content += XMLHelper.encodeXMLString(new String(ch, start, length)); - if (_inCDATASection) - _isContentCDATA = true; - } + if (_inCDATASection) + _isContentCDATA = true; + } - // CDATA-Handling + // CDATA-Handling - protected boolean _inCDATASection = false; - protected boolean _isContentCDATA = false; + protected boolean _inCDATASection = false; + protected boolean _isContentCDATA = false; - public void startCDATA() throws SAXException - { - _inCDATASection = true; - } + public void startCDATA() throws SAXException + { + _inCDATASection = true; + } - public void endCDATA() throws SAXException - { - _inCDATASection = false; - } + public void endCDATA() throws SAXException + { + _inCDATASection = false; + } - public void processingInstruction (String target, String data) + public void processingInstruction (String target, String data) throws SAXException - { + { _instructions.append("<?").append(target) .append(" ").append(data).append("?>"); - } + } - public String getInstructions() - { - return _instructions.toString(); - } + public String getInstructions() + { + return _instructions.toString(); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-02-07 22:27:53
|
Revision: 89 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=89&view=rev Author: martinfuchs Date: 2008-02-07 14:27:25 -0800 (Thu, 07 Feb 2008) Log Message: ----------- std::string constructor for XPath struct Modified Paths: -------------- trunk/c++/xmlstorage.cpp trunk/c++/xmlstorage.h Modified: trunk/c++/xmlstorage.cpp =================================================================== --- trunk/c++/xmlstorage.cpp 2008-02-07 22:19:43 UTC (rev 88) +++ trunk/c++/xmlstorage.cpp 2008-02-07 22:27:25 UTC (rev 89) @@ -220,7 +220,7 @@ } -XPath::XPath(const char* path) +void XPath::init(const char* path) { // Is this an absolute path? if (*path == '/') { Modified: trunk/c++/xmlstorage.h =================================================================== --- trunk/c++/xmlstorage.h 2008-02-07 22:19:43 UTC (rev 88) +++ trunk/c++/xmlstorage.h 2008-02-07 22:27:25 UTC (rev 89) @@ -820,8 +820,11 @@ struct XPath : std::list<XPathElement> { - XPath(const char* path); + XPath(const char* path) {init(path);} + XPath(const std::string path) {init(path.c_str());} + void init(const char* path); + bool _absolute; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-02-07 22:19:39
|
Revision: 88 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=88&view=rev Author: martinfuchs Date: 2008-02-07 14:19:43 -0800 (Thu, 07 Feb 2008) Log Message: ----------- move implementation code into xmlstorage.cpp Modified Paths: -------------- trunk/c++/xmlstorage.cpp trunk/c++/xmlstorage.h Modified: trunk/c++/xmlstorage.cpp =================================================================== --- trunk/c++/xmlstorage.cpp 2008-02-07 21:56:14 UTC (rev 87) +++ trunk/c++/xmlstorage.cpp 2008-02-07 22:19:43 UTC (rev 88) @@ -923,5 +923,91 @@ XS_String XMLWriter::s_empty_attr; +void XMLWriter::create(const XS_String& name) +{ + if (!_stack.empty()) { + StackEntry& last = _stack.top(); + if (last._state < PRE_CLOSED) { + write_attributes(last); + close_pre(last); + } + + ++last._children; + } + + StackEntry entry; + entry._node_name = name; + _stack.push(entry); + + write_pre(entry); +} + +bool XMLWriter::back() +{ + if (!_stack.empty()) { + write_post(_stack.top()); + + _stack.pop(); + return true; + } else + return false; +} + +void XMLWriter::close_pre(StackEntry& entry) +{ + _out << '>'; + + entry._state = PRE_CLOSED; +} + +void XMLWriter::write_pre(StackEntry& entry) +{ + if (_format._pretty >= PRETTY_LINEFEED) + _out << _format._endl; + + if (_format._pretty == PRETTY_INDENT) + for(size_t i=_stack.size(); --i>0; ) + _out << XML_INDENT_SPACE; + + _out << '<' << EncodeXMLString(entry._node_name); + //entry._state = PRE; +} + +void XMLWriter::write_attributes(StackEntry& entry) +{ + for(AttrMap::const_iterator it=entry._attributes.begin(); it!=entry._attributes.end(); ++it) + _out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\""; + + entry._state = ATTRIBUTES; +} + +void XMLWriter::write_post(StackEntry& entry) +{ + if (entry._state < ATTRIBUTES) + write_attributes(entry); + + if (entry._children || !entry._content.empty()) { + if (entry._state < PRE_CLOSED) + close_pre(entry); + + _out << entry._content; + //entry._state = CONTENT; + + if (_format._pretty>=PRETTY_LINEFEED && entry._content.empty()) + _out << _format._endl; + + if (_format._pretty==PRETTY_INDENT && entry._content.empty()) + for(size_t i=_stack.size(); --i>0; ) + _out << XML_INDENT_SPACE; + + _out << "</" << EncodeXMLString(entry._node_name) << ">"; + } else { + _out << "/>"; + } + + entry._state = POST; +} + + } // namespace XMLStorage Modified: trunk/c++/xmlstorage.h =================================================================== --- trunk/c++/xmlstorage.h 2008-02-07 21:56:14 UTC (rev 87) +++ trunk/c++/xmlstorage.h 2008-02-07 22:19:43 UTC (rev 88) @@ -2818,38 +2818,11 @@ } /// create node and move to it - void create(const XS_String& name) - { - if (!_stack.empty()) { - StackEntry& last = _stack.top(); + void create(const XS_String& name); - if (last._state < PRE_CLOSED) { - write_attributes(last); - close_pre(last); - } - - ++last._children; - } - - StackEntry entry; - entry._node_name = name; - _stack.push(entry); - - write_pre(entry); - } - /// go back to previous position - bool back() - { - if (!_stack.empty()) { - write_post(_stack.top()); + bool back(); - _stack.pop(); - return true; - } else - return false; - } - /// attribute setting void put(const XS_String& attr_name, const XS_String& value) { @@ -2899,60 +2872,10 @@ static XS_String s_empty_attr; - void close_pre(StackEntry& entry) - { - _out << '>'; - - entry._state = PRE_CLOSED; - } - - void write_pre(StackEntry& entry) - { - if (_format._pretty >= PRETTY_LINEFEED) - _out << _format._endl; - - if (_format._pretty == PRETTY_INDENT) - for(size_t i=_stack.size(); --i>0; ) - _out << XML_INDENT_SPACE; - - _out << '<' << EncodeXMLString(entry._node_name); - //entry._state = PRE; - } - - void write_attributes(StackEntry& entry) - { - for(AttrMap::const_iterator it=entry._attributes.begin(); it!=entry._attributes.end(); ++it) - _out << ' ' << EncodeXMLString(it->first) << "=\"" << EncodeXMLString(it->second) << "\""; - - entry._state = ATTRIBUTES; - } - - void write_post(StackEntry& entry) - { - if (entry._state < ATTRIBUTES) - write_attributes(entry); - - if (entry._children || !entry._content.empty()) { - if (entry._state < PRE_CLOSED) - close_pre(entry); - - _out << entry._content; - //entry._state = CONTENT; - - if (_format._pretty>=PRETTY_LINEFEED && entry._content.empty()) - _out << _format._endl; - - if (_format._pretty==PRETTY_INDENT && entry._content.empty()) - for(size_t i=_stack.size(); --i>0; ) - _out << XML_INDENT_SPACE; - - _out << "</" << EncodeXMLString(entry._node_name) << ">"; - } else { - _out << "/>"; - } - - entry._state = POST; - } + void close_pre(StackEntry& entry); + void write_pre(StackEntry& entry); + void write_attributes(StackEntry& entry); + void write_post(StackEntry& entry); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-02-07 21:56:15
|
Revision: 87 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=87&view=rev Author: martinfuchs Date: 2008-02-07 13:56:14 -0800 (Thu, 07 Feb 2008) Log Message: ----------- utility functions to manage key/value properties stored in XML Modified Paths: -------------- trunk/c++/xmlstorage.cpp trunk/c++/xmlstorage.h trunk/c++/xs-native.cpp Modified: trunk/c++/xmlstorage.cpp =================================================================== --- trunk/c++/xmlstorage.cpp 2008-02-07 21:18:15 UTC (rev 86) +++ trunk/c++/xmlstorage.cpp 2008-02-07 21:56:14 UTC (rev 87) @@ -56,7 +56,11 @@ const LPCXSSTR XS_FLOATFMT = XS_FLOATFMT_STR; #endif +const XS_String XS_KEY = XS_KEY_STR; +const XS_String XS_VALUE = XS_VALUE_STR; +const XS_String XS_PROPERTY = XS_PROPERTY_STR; + /// remove escape characters from zero terminated string static std::string unescape(const char* s, char b, char e) { Modified: trunk/c++/xmlstorage.h =================================================================== --- trunk/c++/xmlstorage.h 2008-02-07 21:18:15 UTC (rev 86) +++ trunk/c++/xmlstorage.h 2008-02-07 21:56:14 UTC (rev 87) @@ -395,6 +395,10 @@ #define XS_INTFMT_STR XS_TEXT("%d") #define XS_FLOATFMT_STR XS_TEXT("%f") +#define XS_KEY_STR XS_TEXT("key") +#define XS_VALUE_STR XS_TEXT("value") +#define XS_PROPERTY_STR XS_TEXT("property") + // work around GCC's wide string constant bug #ifdef __GNUC__ extern const LPCXSSTR XS_EMPTY; @@ -410,7 +414,11 @@ #define XS_FLOATFMT XS_FLOATFMT_STR #endif +extern const XS_String XS_KEY; +extern const XS_String XS_VALUE; +extern const XS_String XS_PROPERTY; + #ifndef XS_STRING_UTF8 // from UTF-8 to XS internal string encoding @@ -1257,6 +1265,7 @@ struct iterator { typedef XMLNode::Children::iterator BaseIterator; + typedef iterator myType; iterator(BaseIterator begin, BaseIterator end, const XS_String& filter_name) : _cur(begin), @@ -1281,7 +1290,7 @@ return *_cur; } - iterator& operator++() + myType& operator++() { ++_cur; search_next(); @@ -1289,9 +1298,9 @@ return *this; } - iterator operator++(int) + myType operator++(int) { - iterator ret = *this; + myType ret = *this; ++_cur; search_next(); @@ -1299,14 +1308,14 @@ return ret; } - bool operator==(const BaseIterator& other) const + bool operator==(const myType& other) const { - return _cur == other; + return _cur == other._cur; } - bool operator!=(const BaseIterator& other) const + bool operator!=(const myType& other) const { - return _cur != other; + return _cur != other._cur; } protected: @@ -1356,6 +1365,7 @@ struct const_iterator { typedef XMLNode::Children::const_iterator BaseIterator; + typedef const_iterator myType; const_iterator(BaseIterator begin, BaseIterator end, const XS_String& filter_name) : _cur(begin), @@ -1375,7 +1385,7 @@ return *_cur; } - const_iterator& operator++() + myType& operator++() { ++_cur; search_next(); @@ -1383,9 +1393,9 @@ return *this; } - const_iterator operator++(int) + myType operator++(int) { - const_iterator ret = *this; + myType ret = *this; ++_cur; search_next(); @@ -1393,14 +1403,14 @@ return ret; } - bool operator==(const BaseIterator& other) const + bool operator==(const myType& other) const { - return _cur == other; + return _cur == other._cur; } - bool operator!=(const BaseIterator& other) const + bool operator!=(const myType& other) const { - return _cur != other; + return _cur != other._cur; } protected: @@ -1686,6 +1696,15 @@ XS_String& str() {return *_cur;} const XS_String& str() const {return *_cur;} + // property (key/value pair) setter functions + void set_property(const XS_String& key, int value, const XS_String& name=XS_PROPERTY); + void set_property(const XS_String& key, double value, const XS_String& name=XS_PROPERTY); + void set_property(const XS_String& key, const XS_String& value, const XS_String& name=XS_PROPERTY); + void set_property(const XS_String& key, const struct XMLBool& value, const XS_String& name=XS_PROPERTY); + + void set_property(const XS_String& key, const char* value, const XS_String& name=XS_PROPERTY) + {set_property(key, XS_String(value), name);} + protected: XMLNode* _root; XMLNode* _cur; @@ -1815,7 +1834,7 @@ XMLBool(LPCXSSTR value, bool def=false) { - if (value && *value) + if (value && *value)//@@ also handle white space and return def instead of false _value = !XS_icmp(value, XS_TRUE); else _value = def; @@ -1905,7 +1924,7 @@ XMLInt(LPCXSSTR value, int def=0) { - if (value && *value) + if (value && *value)//@@ also handle white space and return def instead of 0 _value = XS_toi(value); else _value = def; @@ -1986,7 +2005,7 @@ { LPTSTR end; - if (value && *value) + if (value && *value)//@@ also handle white space and return def instead of 0 _value = XS_tod(value, &end); else _value = def; @@ -2160,6 +2179,141 @@ } +inline void XMLPos::set_property(const XS_String& key, int value, const XS_String& name) +{ + smart_create(name, XS_KEY, key); + XMLIntRef(_cur, XS_VALUE) = value; + back(); +} + +inline void XMLPos::set_property(const XS_String& key, double value, const XS_String& name) +{ + smart_create(name, XS_KEY, key); + XMLDoubleRef(_cur, XS_VALUE) = value; + back(); +} + +inline void XMLPos::set_property(const XS_String& key, const XS_String& value, const XS_String& name) +{ + smart_create(name, XS_KEY, key); + put(XS_VALUE, value); + back(); +} + +inline void XMLPos::set_property(const XS_String& key, const XMLBool& value, const XS_String& name) +{ + smart_create(name, XS_KEY, key); + XMLBoolRef(_cur, XS_VALUE) = value; + back(); +} + + + /// a key/value pair for property data access +struct XMLProperty { + XMLProperty(const XMLNode* node) + : _key(node->get(XS_KEY)), + _value(node->get(XS_VALUE)) + { + } + + XS_String _key; + XS_String _value; +}; + + + /// utility class to read property settings from a XML tree +struct XMLPropertyReader +{ + XMLPropertyReader(const XMLNode::Children& children) + : _filter(children, XS_PROPERTY), + _begin(_filter.begin(), _filter.end()), + _end(_filter.end(), _filter.end()) + { + } + + XMLPropertyReader(const XMLNode* node) + : _filter(node, XS_PROPERTY), + _begin(_filter.begin(), _filter.end()), + _end(_filter.end(), _filter.end()) + { + } + + /// internal iterator class + struct const_iterator + { + typedef const_XMLChildrenFilter::const_iterator BaseIterator; + typedef const_iterator myType; + + const_iterator(BaseIterator begin, BaseIterator end) + : _cur(begin), + _end(end) + { + } + + operator BaseIterator() + { + return _cur; + } + + XMLProperty operator*() const + { + return XMLProperty(*_cur); + } + + const XMLNode* get_node() const + { + return *_cur; + } + + myType& operator++() + { + ++_cur; + + return *this; + } + + myType operator++(int) + { + myType ret = *this; + + ++_cur; + + return ret; + } + + bool operator==(const myType& other) const + { + return _cur == other._cur; + } + + bool operator!=(const myType& other) const + { + return _cur != other._cur; + } + + protected: + BaseIterator _cur; + BaseIterator _end; + }; + + const_iterator begin() + { + return _begin; + } + + const_iterator end() + { + return _end; + } + +protected: + const_XMLChildrenFilter _filter; + + const_iterator _begin; + const_iterator _end; +}; + + #ifdef _MSC_VER #pragma warning(disable: 4355) #endif Modified: trunk/c++/xs-native.cpp =================================================================== --- trunk/c++/xs-native.cpp 2008-02-07 21:18:15 UTC (rev 86) +++ trunk/c++/xs-native.cpp 2008-02-07 21:56:14 UTC (rev 87) @@ -1,8 +1,8 @@ // - // XML storage C++ classes version 1.2 + // XML storage C++ classes version 1.3 // - // Copyright (c) 2006, 2007 Martin Fuchs <mar...@gm...> + // Copyright (c) 2006, 2007, 2008 Martin Fuchs <mar...@gm...> // /// \file xs-native.cpp This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-02-07 21:18:56
|
Revision: 86 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=86&view=rev Author: martinfuchs Date: 2008-02-07 13:18:15 -0800 (Thu, 07 Feb 2008) Log Message: ----------- Borland Builder compatibility Modified Paths: -------------- trunk/c++/xmlstorage.h Modified: trunk/c++/xmlstorage.h =================================================================== --- trunk/c++/xmlstorage.h 2008-02-07 21:17:04 UTC (rev 85) +++ trunk/c++/xmlstorage.h 2008-02-07 21:18:15 UTC (rev 86) @@ -202,7 +202,7 @@ #endif #ifdef __BORLANDC__ -#define _strcmpi strcmpi +#define _stricmp stricmp #endif @@ -1930,7 +1930,7 @@ { XS_CHAR buffer[32]; XS_snprintf(buffer, COUNTOF(buffer), XS_INTFMT, _value); - return buffer; + return XS_String(buffer); } protected: @@ -2012,7 +2012,7 @@ { XS_CHAR buffer[32]; XS_snprintf(buffer, COUNTOF(buffer), XS_FLOATFMT, _value); - return buffer; + return XS_String(buffer); } protected: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-02-07 21:17:36
|
Revision: 85 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=85&view=rev Author: martinfuchs Date: 2008-02-07 13:17:04 -0800 (Thu, 07 Feb 2008) Log Message: ----------- update copyright for 2008 Modified Paths: -------------- trunk/c++/xmlstorage-license.txt Modified: trunk/c++/xmlstorage-license.txt =================================================================== --- trunk/c++/xmlstorage-license.txt 2008-02-04 09:35:15 UTC (rev 84) +++ trunk/c++/xmlstorage-license.txt 2008-02-07 21:17:04 UTC (rev 85) @@ -2,7 +2,7 @@ // // XML storage classes // - // Copyright (c) 2004, 2005, 2006, 2007 Martin Fuchs <mar...@gm...> + // Copyright (c) 2004, 2005, 2006, 2007, 2008 Martin Fuchs <mar...@gm...> // This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-02-04 09:35:16
|
Revision: 84 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=84&view=rev Author: martinfuchs Date: 2008-02-04 01:35:15 -0800 (Mon, 04 Feb 2008) Log Message: ----------- add xmltest for D Added Paths: ----------- trunk/d/xmltest.d Added: trunk/d/xmltest.d =================================================================== --- trunk/d/xmltest.d (rev 0) +++ trunk/d/xmltest.d 2008-02-04 09:35:15 UTC (rev 84) @@ -0,0 +1,117 @@ +module xmltest; + + // + // XML storage D classes version 1.2 + // + // Copyright (c) 2004, 2005, 2006, 2007 Martin Fuchs <mar...@gm...> + // + + /// \file xmltest.d + /// XMLStorage example file + + +/* + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +*/ + +import xmlstorage; +import std.stdio; + + +bool xml_test() +{ + auto doc = new XMLDoc; + bool ret; + + //ret = doc.read_file("poem.xml"); + //ret = doc.read_file("machines.xml"); + ret = doc.read_file("packets.xml"); + + if (!ret) { + fwritef(stderr, doc._errors.str()); + return false; + } + + doc.write_file("out.xml"); + + auto pos = new XMLPos(doc); + +// if (pos.go("get_packets/packet")) +// if (pos.go("/get_packets/packet")) +// if (pos.go("/get_packets/packet[5]")) + if (pos.go("/get_packets/packet[@db_id=\"7628\"]")) +// if (pos.go("get_machines/machine[@wsid=\"client2\"]")) + { + writefln("db_id = " ~ pos.get("db_id")); + writefln("name = " ~ pos.get("name")); + writefln("short_name = ", pos.get("short_name")); +/*@@ + writefln("db_id = %d", XMLInt(pos, "db_id")); + writefln("name = %s", XMLString(pos, "name").c_str()); + writefln("short_name = %s", XMLString(pos, "short_name").c_str()); +*/ + pos.back(); + } + + return true; +} + + +void print_gc_stats() +{ + std.gc.GCStats stats; + std.gc.getStats(stats); + + printf("poolsize = x%x, usedsize = x%x, freelistsize = x%x, freeblocks = %d, pageblocks = %d\n", + stats.poolsize, stats.usedsize, stats.freelistsize, stats.freeblocks, stats.pageblocks); +} + +int main(char[][] args) +{ + writefln(); // insert an empty line after unit test output + + print_gc_stats(); + writefln(); + + int ret = xml_test()? 0: 1; + + writefln(); + print_gc_stats(); + + writefln(); + + std.gc.minimize(); + print_gc_stats(); + + std.gc.genCollect(); + print_gc_stats(); + + std.gc.fullCollect(); + print_gc_stats(); + + return ret; +} Property changes on: trunk/d/xmltest.d ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-02-04 09:34:26
|
Revision: 83 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=83&view=rev Author: martinfuchs Date: 2008-02-04 01:34:30 -0800 (Mon, 04 Feb 2008) Log Message: ----------- fix file name Modified Paths: -------------- trunk/c++/example-parse.cpp Modified: trunk/c++/example-parse.cpp =================================================================== --- trunk/c++/example-parse.cpp 2008-02-04 09:34:00 UTC (rev 82) +++ trunk/c++/example-parse.cpp 2008-02-04 09:34:30 UTC (rev 83) @@ -2,7 +2,7 @@ // // XML storage classes // - // exampleparse.cpp + // example-parse.cpp // // Copyright (c) 2005 Martin Fuchs <mar...@gm...> // This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-02-04 09:34:00
|
Revision: 82 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=82&view=rev Author: martinfuchs Date: 2008-02-04 01:34:00 -0800 (Mon, 04 Feb 2008) Log Message: ----------- XMLStorage Version 1.3: - introduction of XPathElement and XPath - use XPathElement to search for child nodes - count() to count child nodes using simple XPath expressions - filter() to filter XML tree structures using simple XPath expressions Modified Paths: -------------- trunk/c++/xmlstorage.cpp trunk/c++/xmlstorage.dsw trunk/c++/xmlstorage.h Added Paths: ----------- trunk/c++/example-xpath.cpp Added: trunk/c++/example-xpath.cpp =================================================================== --- trunk/c++/example-xpath.cpp (rev 0) +++ trunk/c++/example-xpath.cpp 2008-02-04 09:34:00 UTC (rev 82) @@ -0,0 +1,91 @@ + + // + // XML storage classes + // + // example-xpath.cpp + // + // Copyright (c) 2008 Martin Fuchs <mar...@gm...> + // + + +/* + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +*/ + +#include <xmlstorage.h> +using namespace XMLStorage; + +#include <iostream> +using namespace std; + + +void test_write() +{ + XMLWriter out("example-xpath.xml"); + + out.create("Test"); + out.create("Child"); + out.set_content("Wert1"); + out.back(); + + out.create("Child"); + out["id"] = XMLInt(1234); + out.set_content("Wert2"); + out.back(); + + out.create("Child"); + out.set_content("Wert3"); + out.back(); + out.back(); +} + + +void test_read() +{ + XMLDoc doc; + + // Einlesen des XML-Files + doc.read_file("example-xpath.xml"); + + XMLPos pos(&doc); + + cout << "matching 'Test/Child': " << pos.count("Test/Child") << endl; + cout << "matching 'Test/Child[@id=1234]': " << pos.count("Test/Child[@id=1234]") << endl; + + XMLDoc target; + pos.filter("Test/Child[@id=1234]", target); + target.write(cout); +} + + +int main() +{ + test_write(); + test_read(); + + return 0; +} Property changes on: trunk/c++/example-xpath.cpp ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Modified: trunk/c++/xmlstorage.cpp =================================================================== --- trunk/c++/xmlstorage.cpp 2008-02-04 09:31:26 UTC (rev 81) +++ trunk/c++/xmlstorage.cpp 2008-02-04 09:34:00 UTC (rev 82) @@ -1,6 +1,6 @@ // - // XML storage C++ classes version 1.2 + // XML storage C++ classes version 1.3 // // Copyright (c) 2004, 2005, 2006, 2007, 2008 Martin Fuchs <mar...@gm...> // @@ -104,19 +104,13 @@ } - /// move XPath like to position in XML tree -bool XMLPos::go(const char* path) + /// move to the position defined by xpath in XML tree +bool XMLPos::go(const XPath& xpath) { - XMLNode* node = _cur; + XMLNode* node = xpath._absolute? _root: _cur; - // Is this an absolute path? - if (*path == '/') { - node = _root; - ++path; - } + node = node->find_relative(xpath); - node = node->find_relative(path); - if (node) { go_to(node); return true; @@ -124,19 +118,13 @@ return false; } - /// move XPath like to position in XML tree -bool const_XMLPos::go(const char* path) + /// move to the position defined by xpath in XML tree +bool const_XMLPos::go(const XPath& xpath) { - const XMLNode* node = _cur; + const XMLNode* node = xpath._absolute? _root: _cur; - // Is this an absolute path? - if (*path == '/') { - node = _root; - ++path; - } + node = node->find_relative(xpath); - node = node->find_relative(path); - if (node) { go_to(node); return true; @@ -145,41 +133,8 @@ } -const XMLNode* XMLNode::find_relative(const char* path) const +const char* XPathElement::parse(const char* path) { - const XMLNode* node = this; - - // parse relative path - while(*path) { - node = const_cast<XMLNode*>(node)->get_child_relative(path, false); // get_child_relative() ist const for create==false - - if (!node) - return NULL; - - if (*path == '/') - ++path; - } - - return node; -} - -XMLNode* XMLNode::create_relative(const char* path) -{ - XMLNode* node = this; - - // parse relative path - while(*path) { - node = node->get_child_relative(path, true); - - if (*path == '/') - ++path; - } - - return node; -} - -XMLNode* XMLNode::get_child_relative(const char*& path, bool create) -{ const char* slash = strchr(path, '/'); if (slash == path) return NULL; @@ -191,8 +146,7 @@ // look for [n] and [@attr_name="attr_value"] expressions in path components const char* bracket = strchr(comp.c_str(), '['); l = bracket? bracket-comp.c_str(): comp.length(); - std::string child_name(comp.c_str(), l); - std::string attr_name, attr_value; + _child_name.assign(comp.c_str(), l); int n = 0; if (bracket) { @@ -202,7 +156,7 @@ n = atoi(p); // read index number if (n) - n = n - 1; // convert into zero based index + _child_idx = n - 1; // convert into zero based index const char* at = strchr(p, '@'); @@ -212,33 +166,201 @@ // read attribute name and value if (equal) { - attr_name = unescape(p, equal-p); - attr_value = unescape(equal+1); + _attr_name = unescape(p, equal-p); + _attr_value = unescape(equal+1); } } } - XMLNode* child; + return path; +} - if (attr_name.empty()) - // search n.th child node with specified name - child = find(child_name, n); +XMLNode* XPathElement::find(XMLNode* node) const +{ + int n = 0; + + for(XMLNode::Children::const_iterator it=node->_children.begin(); it!=node->_children.end(); ++it) + if (matches(**it, n)) + return *it; + + return NULL; +} + +const XMLNode* XPathElement::const_find(const XMLNode* node) const +{ + int n = 0; + + for(XMLNode::Children::const_iterator it=node->_children.begin(); it!=node->_children.end(); ++it) + if (matches(**it, n)) + return *it; + + return NULL; +} + +bool XPathElement::matches(const XMLNode& node, int& n) const +{ + if (node != _child_name) + if (_child_name != "*") // use asterisk as wildcard + return false; + + if (!_attr_name.empty()) + if (node.get(_attr_name) != _attr_value) + return false; + + if (_child_idx == -1) + return true; + else if (n++ == _child_idx) + return true; else - // search n.th child node with specified name and matching attribute value - child = find(child_name, attr_name, attr_value, n); + return false; +} - if (!child && create) { - child = new XMLNode(child_name); - add_child(child); - if (!attr_name.empty()) - (*this)[attr_name] = attr_value; +XPath::XPath(const char* path) +{ + // Is this an absolute path? + if (*path == '/') { + _absolute = true; + ++path; + } else + _absolute = false; + + // parse path + while(*path) { + XPathElement elem; + + path = elem.parse(path); + + if (!path) + break; + + if (*path == '/') + ++path; + + push_back(elem); } +} - return child; + +const XMLNode* XMLNode::find_relative(const XPath& xpath) const +{ + const XMLNode* node = this; + + for(XPath::const_iterator it=xpath.begin(); it!=xpath.end(); ++it) { + node = it->const_find(node); + + if (!node) + return NULL; + } + + return node; } +XMLNode* XMLNode::find_relative(const XPath& xpath) +{ + XMLNode* node = this; + for(XPath::const_iterator it=xpath.begin(); it!=xpath.end(); ++it) { + node = it->find(node); + + if (!node) + return NULL; + } + + return node; +} + +XMLNode* XMLNode::create_relative(const XPath& xpath) +{ + XMLNode* node = this; + + for(XPath::const_iterator it=xpath.begin(); it!=xpath.end(); ++it) { + XMLNode* child = it->find(this); + + if (!child) { + child = new XMLNode(it->_child_name); + add_child(child); + + if (!it->_attr_name.empty()) + (*this)[it->_attr_name] = it->_attr_value; + } + } + + return node; +} + + /// count the nodes matching the given relative XPath expression +int XMLNode::count(XPath::const_iterator from, const XPath::const_iterator& to) const +{ + const XPathElement& elem = *from++; + int cnt = 0; + int n = 0; + + for(XMLNode::Children::const_iterator it=_children.begin(); it!=_children.end(); ++it) + if (elem.matches(**it, n)) + if (from != to) + // iterate deeper + cnt += (*it)->count(from, to); + else + // increment match counter + ++cnt; + + return cnt; +} + + /// copy matching tree nodes using the given XPath filter expression +bool XMLNode::filter(const XPath& xpath, XMLNode& target) const +{ + XMLNode* ret = filter(xpath.begin(), xpath.end()); + + if (ret) { + // move returned nodes to target node + target._children.move(ret->_children); + target._attributes = ret->_attributes; + + delete ret; + + return true; + } else + return false; +} + + /// create a new node tree using the given XPath filter expression +XMLNode* XMLNode::filter(XPath::const_iterator from, const XPath::const_iterator& to) const +{ + XMLNode* copy = NULL; + + const XPathElement& elem = *from++; + int cnt = 0; + int n = 0; + + for(XMLNode::Children::const_iterator it=_children.begin(); it!=_children.end(); ++it) + if (elem.matches(**it, n)) { + if (!copy) + copy = new XMLNode(*this, XMLNode::COPY_NOCHILDREN); + + if (from != to) { + XMLNode* ret = (*it)->filter(from, to); + + if (ret) { + copy->add_child(ret); + ++cnt; + } + } else { + copy->add_child(new XMLNode(**it, XMLNode::COPY_NOCHILDREN)); + ++cnt; + } + } + + if (cnt > 0) { + return copy; + } else { + delete copy; + return NULL; + } +} + + /// encode XML string literals std::string EncodeXMLString(const XS_String& str, bool cdata) { Modified: trunk/c++/xmlstorage.dsw =================================================================== --- trunk/c++/xmlstorage.dsw 2008-02-04 09:31:26 UTC (rev 81) +++ trunk/c++/xmlstorage.dsw 2008-02-04 09:34:00 UTC (rev 82) @@ -72,6 +72,18 @@ ############################################################################### +Project: "example_xpath"=".\example-xpath.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + Project: "writertest"=.\writertest.dsp - Package Owner=<4> Package=<5> Modified: trunk/c++/xmlstorage.h =================================================================== --- trunk/c++/xmlstorage.h 2008-02-04 09:31:26 UTC (rev 81) +++ trunk/c++/xmlstorage.h 2008-02-04 09:34:00 UTC (rev 82) @@ -1,6 +1,6 @@ // - // XML storage C++ classes version 1.2 + // XML storage C++ classes version 1.3 // // Copyright (c) 2004, 2005, 2006, 2007, 2008 Martin Fuchs <mar...@gm...> // @@ -781,6 +781,43 @@ }; +struct XMLNode; + +struct XPathElement +{ + XPathElement() : _child_idx(-1) {} + + XPathElement(const XS_String& child_name, int child_idx=-1) + : _child_name(child_name), _child_idx(child_idx) {} + + XPathElement(const XS_String& child_name, int child_idx, const XS_String& attr_name, const XS_String& attr_value) + : _child_name(child_name), _child_idx(child_idx), + _attr_name(attr_name), _attr_value(attr_value) + { + } + + XS_String _child_name; + int _child_idx; + + XS_String _attr_name; + XS_String _attr_value; + + const char* parse(const char* path); + + XMLNode* find(XMLNode* node) const; + const XMLNode* const_find(const XMLNode* node) const; + + bool matches(const XMLNode& node, int& n) const; +}; + +struct XPath : std::list<XPathElement> +{ + XPath(const char* path); + + bool _absolute; +}; + + /// in memory representation of an XML node struct XMLNode : public XS_String { @@ -839,11 +876,41 @@ /// internal children node list struct Children : public std::list<XMLNode*> { - void assign(const Children& other) + typedef std::list<XMLNode*> super; + + Children() { + } + + Children(Children& other) + { + for(Children::const_iterator it=other.begin(); it!=other.end(); ++it) + push_back(*it); + } + + void assign(Children& other) + { clear(); + move(other); + } + void move(Children& other) + { for(Children::const_iterator it=other.begin(); it!=other.end(); ++it) + push_back(*it); + + other.reset(); + } + + Children& operator=(Children& other) + { + assign(other); + return *this; + } + + void copy(const Children& other) + { + for(Children::const_iterator it=other.begin(); it!=other.end(); ++it) push_back(new XMLNode(**it)); } @@ -868,12 +935,19 @@ return false; } + + private: + void reset() + { + super::clear(); + } }; // access to protected class members for XMLPos and XMLReader friend struct XMLPos; friend struct const_XMLPos; friend struct XMLReaderBase; + friend struct XPathElement; XMLNode(const XS_String& name) : XS_String(name) @@ -901,6 +975,22 @@ _children.push_back(new XMLNode(**it)); } + enum COPY_FLAGS {COPY_NOCHILDREN}; + + XMLNode(const XMLNode& other, COPY_FLAGS copy_no_children) + : XS_String(other), + _attributes(other._attributes), + _leading(other._leading), + _content(other._content), + _end_leading(other._end_leading), + _trailing(other._trailing) +#ifdef XMLNODE_LOCATION + , _location(other._location) +#endif + { +// assert(copy_no_children==COPY_NOCHILDREN); + } + virtual ~XMLNode() { while(!_children.empty()) { @@ -924,7 +1014,8 @@ XMLNode& operator=(const XMLNode& other) { - _children.assign(other._children); + _children.clear(); + _children.copy(other._children); _attributes = other._attributes; @@ -982,9 +1073,9 @@ } /// convenient value access in children node - XS_String subvalue(const XS_String& name, const XS_String& attr_name, int n=0) const + XS_String subvalue(const XS_String& child_name, const XS_String& attr_name, int n=0) const { - const XMLNode* node = find(name, n); + const XMLNode* node = XPathElement(child_name, n).const_find(this); if (node) return node->get(attr_name); @@ -993,12 +1084,12 @@ } /// convenient storage of distinct values in children node - XS_String& subvalue(const XS_String& name, const XS_String& attr_name, int n=0) + XS_String& subvalue(const XS_String& child_name, const XS_String& attr_name, int n=0) { - XMLNode* node = find(name, n); + XMLNode* node = XPathElement(child_name, n).find(this); if (!node) { - node = new XMLNode(name); + node = new XMLNode(child_name); add_child(node); } @@ -1007,9 +1098,9 @@ #if defined(UNICODE) && !defined(XS_STRING_UTF8) /// convenient value access in children node - XS_String subvalue(const char* name, const char* attr_name, int n=0) const + XS_String subvalue(const char* child_name, const char* attr_name, int n=0) const { - const XMLNode* node = find(name, n); + const XMLNode* node = XPathElement(child_name, n).find(this); if (node) return node->get(attr_name); @@ -1020,10 +1111,10 @@ /// convenient storage of distinct values in children node XS_String& subvalue(const char* name, const XS_String& attr_name, int n=0) { - XMLNode* node = find(name, n); + XMLNode* node = XPathElement(child_name, n).find(this); if (!node) { - node = new XMLNode(name); + node = new XMLNode(child_name); add_child(node); } @@ -1095,6 +1186,18 @@ return out.good(); } + /// count the nodes matching the given relative XPath expression + int count(const XPath& xpath) const + { + return count(xpath.begin(), xpath.end()); + } + + /// count the nodes matching the given relative XPath expression + int count(XPath::const_iterator from, const XPath::const_iterator& to) const; + + /// copy matching tree nodes using the given XPath filter expression + bool filter(const XPath& xpath, XMLNode& target) const; + protected: Children _children; AttributeMap _attributes; @@ -1116,72 +1219,22 @@ return NULL; } - XMLNode* find(const XS_String& name, int n=0) const - { - for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it) - if (**it == name) - if (!n--) - return *it; - - return NULL; - } - - XMLNode* find(const XS_String& name, const XS_String& attr_name, const XS_String& attr_value, int n=0) const - { - for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it) { - const XMLNode& node = **it; - - if (node==name && node.get(attr_name)==attr_value) - if (!n--) - return *it; - } - - return NULL; - } - -#if defined(UNICODE) && !defined(XS_STRING_UTF8) - XMLNode* find(const char* name, int n=0) const - { - for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it) - if (**it == name) - if (!n--) - return *it; - - return NULL; - } - - template<typename T, typename U> - XMLNode* find(const char* name, const T& attr_name, const U& attr_value, int n=0) const - { - for(Children::const_iterator it=_children.begin(); it!=_children.end(); ++it) { - const XMLNode& node = **it; - - if (node==name && node.get(attr_name)==attr_value) - if (!n--) - return *it; - } - - return NULL; - } -#endif - /// XPath find function (const) - const XMLNode* find_relative(const char* path) const; + const XMLNode* find_relative(const XPath& xpath) const; /// XPath find function - XMLNode* find_relative(const char* path) - {return const_cast<XMLNode*>(const_cast<const XMLNode*>(this)->find_relative(path));} + XMLNode* find_relative(const XPath& xpath); /// relative XPath create function - XMLNode* create_relative(const char* path); + XMLNode* create_relative(const XPath& xpath); + /// create a new node tree using the given XPath filter expression + XMLNode* filter(XPath::const_iterator from, const XPath::const_iterator& to) const; + void write_worker(std::ostream& out) const; void plain_write_worker(std::ostream& out) const; void pretty_write_worker(std::ostream& out, const XMLFormat& format, int indent) const; void smart_write_worker(std::ostream& out, const XMLFormat& format, int indent) const; - -protected: - XMLNode* get_child_relative(const char*& path, bool create); // mutable for create==true }; @@ -1489,9 +1542,9 @@ } /// search for child and go down - bool go_down(const XS_String& name, int n=0) + bool go_down(const XS_String& child_name, int n=0) { - XMLNode* node = _cur->find(name, n); + XMLNode* node = XPathElement(child_name, n).find(_cur); if (node) { go_to(node); @@ -1500,13 +1553,13 @@ return false; } - /// move XPath like to position in XML tree - bool go(const char* path); + /// move to the position defined by xpath in XML tree + bool go(const XPath& xpath); /// create child nodes using XPath notation and move to the deepest child - bool create_relative(const char* path) + bool create_relative(const XPath& xpath) { - XMLNode* node = _cur->create_relative(path); + XMLNode* node = _cur->create_relative(xpath); if (!node) return false; // invalid path specified @@ -1521,35 +1574,47 @@ } /// create node if not already existing and move to it - void smart_create(const XS_String& name) + void smart_create(const XS_String& child_name) { - XMLNode* node = _cur->find(name); + XMLNode* node = XPathElement(child_name).find(_cur); if (node) go_to(node); else - add_down(new XMLNode(name)); + add_down(new XMLNode(child_name)); } /// search matching child node identified by key name and an attribute value - void smart_create(const XS_String& name, const XS_String& attr_name, const XS_String& attr_value) + void smart_create(const XS_String& child_name, const XS_String& attr_name, const XS_String& attr_value) { - XMLNode* node = _cur->find(name, attr_name, attr_value); + XMLNode* node = XPathElement(child_name, 0, attr_name, attr_value).find(_cur); if (node) go_to(node); else { - node = new XMLNode(name); + node = new XMLNode(child_name); add_down(node); (*node)[attr_name] = attr_value; } } + /// count the nodes matching the given relative XPath expression + int count(const XPath& xpath) const + { + return _cur->count(xpath); + } + + /// create a new node tree using the given XPath filter expression + int filter(const XPath& xpath, XMLNode& target) const + { + return _cur->filter(xpath, target); + } + #if defined(UNICODE) && !defined(XS_STRING_UTF8) /// search for child and go down - bool go_down(const char* name, int n=0) + bool go_down(const char* child_name, int n=0) { - XMLNode* node = _cur->find(name, n); + XMLNode* node = XPathElement(child_name, n).find(_cur); if (node) { go_to(node); @@ -1559,32 +1624,32 @@ } /// create node and move to it - void create(const char* name) + void create(const char* child_name) { - add_down(new XMLNode(name)); + add_down(new XMLNode(child_name)); } /// create node if not already existing and move to it - void smart_create(const char* name) + void smart_create(const char* child_name) { - XMLNode* node = _cur->find(name); + XMLNode* node = _cur->find(child_name); if (node) go_to(node); else - add_down(new XMLNode(name)); + add_down(new XMLNode(child_name)); } /// search matching child node identified by key name and an attribute value template<typename T, typename U> - void smart_create(const char* name, const T& attr_name, const U& attr_value) + void smart_create(const char* child_name, const T& attr_name, const U& attr_value) { - XMLNode* node = _cur->find(name, attr_name, attr_value); + XMLNode* node = _cur->find(child_name, attr_name, attr_value); if (node) go_to(node); else { - XMLNode* node = new XMLNode(name); + XMLNode* node = new XMLNode(child_name); add_down(node); (*node)[attr_name] = attr_value; } @@ -1696,9 +1761,9 @@ } /// search for child and go down - bool go_down(const XS_String& name, int n=0) + bool go_down(const XS_String& child_name, int n=0) { - XMLNode* node = _cur->find(name, n); + const XMLNode* node = XPathElement(child_name, n).const_find(_cur); if (node) { go_to(node); @@ -1707,14 +1772,14 @@ return false; } - /// move XPath like to position in XML tree - bool go(const char* path); + /// move to the position defined by xpath in XML tree + bool go(const XPath& xpath); #if defined(UNICODE) && !defined(XS_STRING_UTF8) /// search for child and go down - bool go_down(const char* name, int n=0) + bool go_down(const char* child_name, int n=0) { - XMLNode* node = _cur->find(name, n); + XMLNode* node = XPathElement(child_name, n).const_find(_cur); if (node) { go_to(node); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-02-04 09:31:22
|
Revision: 81 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=81&view=rev Author: martinfuchs Date: 2008-02-04 01:31:26 -0800 (Mon, 04 Feb 2008) Log Message: ----------- add Unix Makefile Modified Paths: -------------- trunk/c++/xmlstorage.dsp Modified: trunk/c++/xmlstorage.dsp =================================================================== --- trunk/c++/xmlstorage.dsp 2008-02-04 09:27:51 UTC (rev 80) +++ trunk/c++/xmlstorage.dsp 2008-02-04 09:31:26 UTC (rev 81) @@ -52,6 +52,10 @@ # Begin Source File +SOURCE=.\Makefile +# End Source File +# Begin Source File + SOURCE=.\Makefile.VC6 # End Source File # Begin Source File This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-02-04 09:27:52
|
Revision: 80 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=80&view=rev Author: martinfuchs Date: 2008-02-04 01:27:51 -0800 (Mon, 04 Feb 2008) Log Message: ----------- add new example code Modified Paths: -------------- trunk/c++/Makefile trunk/c++/Makefile.VC6 trunk/c++/example5.cpp Modified: trunk/c++/Makefile =================================================================== --- trunk/c++/Makefile 2008-01-31 23:22:34 UTC (rev 79) +++ trunk/c++/Makefile 2008-02-04 09:27:51 UTC (rev 80) @@ -4,6 +4,8 @@ g++ $(CFLAGS) xmlstorage.cpp xs-native.cpp example1.cpp -o example1 g++ $(CFLAGS) xmlstorage.cpp xs-native.cpp example2.cpp -o example2 g++ $(CFLAGS) xmlstorage.cpp xs-native.cpp example3.cpp -o example3 + g++ $(CFLAGS) xmlstorage.cpp xs-native.cpp example3.cpp -o example4 + g++ $(CFLAGS) xmlstorage.cpp xs-native.cpp example3.cpp -o example5 g++ $(CFLAGS) xmlstorage.cpp xs-native.cpp example-parse.cpp -o example-parse g++ $(CFLAGS) xmlstorage.cpp xs-native.cpp writertest.cpp -o writertest Modified: trunk/c++/Makefile.VC6 =================================================================== --- trunk/c++/Makefile.VC6 2008-01-31 23:22:34 UTC (rev 79) +++ trunk/c++/Makefile.VC6 2008-02-04 09:27:51 UTC (rev 80) @@ -16,7 +16,7 @@ xs-native.cpp xs-expat.cpp xs-xerces.cpp \ xmlstorage-license.txt -EXAMPLES = example1.cpp example2.cpp example3.cpp +EXAMPLES = example1.cpp example2.cpp example3.cpp example4.cpp example5.cpp example-parse.cpp example-xpath.cpp TARGETS = $(PROJ)-$(VC_VER).lib $(PROJ)-$(VC_VER)d.lib $(PROJ)-$(VC_VER)l.lib $(PROJ)-$(VC_VER)t.lib Modified: trunk/c++/example5.cpp =================================================================== --- trunk/c++/example5.cpp 2008-01-31 23:22:34 UTC (rev 79) +++ trunk/c++/example5.cpp 2008-02-04 09:27:51 UTC (rev 80) @@ -82,6 +82,7 @@ pos.go_down("PERSON"); // pos.remove_children("VORNAME"); + pos.go_down("VORNAME"); pos.delete_this(); pos.back(); // </PERSON> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-01-31 23:22:36
|
Revision: 79 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=79&view=rev Author: martinfuchs Date: 2008-01-31 15:22:34 -0800 (Thu, 31 Jan 2008) Log Message: ----------- add remove_children() and erase() to remove named children and attributes Modified Paths: -------------- trunk/c++/example5.cpp trunk/c++/xmlstorage.h Modified: trunk/c++/example5.cpp =================================================================== --- trunk/c++/example5.cpp 2008-01-31 23:21:12 UTC (rev 78) +++ trunk/c++/example5.cpp 2008-01-31 23:22:34 UTC (rev 79) @@ -45,55 +45,60 @@ void test_write() { - XMLDoc doc; - XMLPos pos(&doc); + XMLDoc doc; + XMLPos pos(&doc); - // Zusammenstellen der XML-Struktur im Dokument 'doc' - pos.create("PERSON"); + // Zusammenstellen der XML-Struktur im Dokument 'doc' + pos.create("PERSON"); - pos.create("NAME"); - pos->set_content("Mustername"); - pos.back(); // </NAME> + pos.create("NAME"); + pos->set_content("Mustername"); + pos.back(); // </NAME> - pos.create("VORNAME"); - pos->set_content("Mustervorname"); - pos.back(); // </VORNAME> + pos.create("VORNAME"); + pos->set_content("Mustervorname"); + pos.back(); // </VORNAME> - pos.create("ADRESSE"); - pos->set_content("Musteradresse"); - pos.back(); // </ADRESSE> + pos.create("ADRESSE"); + pos["private"] = "true"; + pos->set_content("Musteradresse"); + pos.back(); // </ADRESSE> pos.back(); // </PERSON> - // Schreiben der XML-Datei - doc.write_file("example5.xml"); + // Schreiben der XML-Datei + doc.write_file("example5.xml"); } void test_delete() { - XMLDoc doc; + XMLDoc doc; - // Einlesen des XML-Files - doc.read_file("example5.xml"); + // Einlesen des XML-Files + doc.read_file("example5.xml"); - XMLPos pos(&doc); + XMLPos pos(&doc); - pos.go_down("PERSON"); +// pos.remove_children("VORNAME"); pos.go_down("VORNAME"); pos.delete_this(); pos.back(); // </PERSON> - // Schreiben der XML-Datei - doc.write_file("example5.xml"); + pos.go_down("ADRESSE"); + pos.erase("private"); + pos.back(); + + // Schreiben der XML-Datei + doc.write_file("example5.xml"); } int main() { - test_write(); - test_delete(); + test_write(); + test_delete(); - return 0; + return 0; } Modified: trunk/c++/xmlstorage.h =================================================================== --- trunk/c++/xmlstorage.h 2008-01-31 23:21:12 UTC (rev 78) +++ trunk/c++/xmlstorage.h 2008-01-31 23:22:34 UTC (rev 79) @@ -942,6 +942,16 @@ _children.push_back(child); } + /// remove all children named 'name' + void remove_children(const XS_String& name) + { + Children::iterator it, next=_children.begin(); + + while((it=next++)!=_children.end()) + if (**it == name) + _children.erase(it); + } + /// write access to an attribute void put(const XS_String& attr_name, const XS_String& value) { @@ -965,6 +975,12 @@ return def; } + /// remove the attribute 'attr_name' + void erase(const XS_String& attr_name) + { + _attributes.erase(attr_name); + } + /// convenient value access in children node XS_String subvalue(const XS_String& name, const XS_String& attr_name, int n=0) const { @@ -1460,21 +1476,6 @@ return false; } - /// delete current node and go back to previous position - bool delete_this() - { - if (!_stack.empty()) { - XMLNode* pLast = _stack.top(); - - if (pLast->_children.remove(_cur)) { - _cur = _stack.top(); - return true; - } - } - - return false; - } - /// go down to first child bool go_down() { @@ -1590,6 +1591,33 @@ } #endif + /// delete current node and go back to previous position + bool delete_this() + { + if (!_stack.empty()) { + XMLNode* pLast = _stack.top(); + + if (pLast->_children.remove(_cur)) { + _cur = _stack.top(); + return true; + } + } + + return false; + } + + /// remove all children named 'name' + void remove_children(const XS_String& name) + { + _cur->remove_children(name); + } + + /// remove the attribute 'attr_name' from the current node + void erase(const XS_String& attr_name) + { + _cur->erase(attr_name); + } + XS_String& str() {return *_cur;} const XS_String& str() const {return *_cur;} @@ -2046,6 +2074,7 @@ }; + // read option (for example configuration) values from XML node attributes template<typename T> inline void read_option(T& var, const_XMLPos& cfg, LPCXSSTR key) { @@ -2055,6 +2084,7 @@ var = val; } + // read integer option values from XML node attributes template<> inline void read_option(int& var, const_XMLPos& cfg, LPCXSSTR key) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-01-31 23:21:08
|
Revision: 78 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=78&view=rev Author: martinfuchs Date: 2008-01-31 15:21:12 -0800 (Thu, 31 Jan 2008) Log Message: ----------- change read() to read_file() Modified Paths: -------------- trunk/c++/xmltest.cpp Modified: trunk/c++/xmltest.cpp =================================================================== --- trunk/c++/xmltest.cpp 2008-01-30 23:09:16 UTC (rev 77) +++ trunk/c++/xmltest.cpp 2008-01-31 23:21:12 UTC (rev 78) @@ -52,8 +52,8 @@ XMLDoc doc; bool ret; - //ret = doc.read("poem.xml"); - //ret = doc.read("machines.xml"); + //ret = doc.read_file("poem.xml"); + //ret = doc.read_file("machines.xml"); ret = doc.read_file("packets.xml"); if (!ret) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-01-30 23:09:22
|
Revision: 77 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=77&view=rev Author: martinfuchs Date: 2008-01-30 15:09:16 -0800 (Wed, 30 Jan 2008) Log Message: ----------- added XMLPos::delete_this() and XMLNode::Children::remove() to allow removing of XML nodes Modified Paths: -------------- trunk/c++/xmlstorage.dsw trunk/c++/xmlstorage.h Added Paths: ----------- trunk/c++/example5.cpp trunk/c++/example5.dsp Added: trunk/c++/example5.cpp =================================================================== --- trunk/c++/example5.cpp (rev 0) +++ trunk/c++/example5.cpp 2008-01-30 23:09:16 UTC (rev 77) @@ -0,0 +1,99 @@ + + // + // XML storage classes + // + // example5.cpp + // + // Copyright (c) 2008 Martin Fuchs <mar...@gm...> + // + + +/* + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +*/ + +#include <xmlstorage.h> +using namespace XMLStorage; + +#include <iostream> +using namespace std; + + +void test_write() +{ + XMLDoc doc; + XMLPos pos(&doc); + + // Zusammenstellen der XML-Struktur im Dokument 'doc' + pos.create("PERSON"); + + pos.create("NAME"); + pos->set_content("Mustername"); + pos.back(); // </NAME> + + pos.create("VORNAME"); + pos->set_content("Mustervorname"); + pos.back(); // </VORNAME> + + pos.create("ADRESSE"); + pos->set_content("Musteradresse"); + pos.back(); // </ADRESSE> + + pos.back(); // </PERSON> + + // Schreiben der XML-Datei + doc.write_file("example5.xml"); +} + + +void test_delete() +{ + XMLDoc doc; + + // Einlesen des XML-Files + doc.read_file("example5.xml"); + + XMLPos pos(&doc); + + + pos.go_down("PERSON"); + pos.go_down("VORNAME"); + pos.delete_this(); + pos.back(); // </PERSON> + + // Schreiben der XML-Datei + doc.write_file("example5.xml"); +} + + +int main() +{ + test_write(); + test_delete(); + + return 0; +} Property changes on: trunk/c++/example5.cpp ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Added: trunk/c++/example5.dsp =================================================================== --- trunk/c++/example5.dsp (rev 0) +++ trunk/c++/example5.dsp 2008-01-30 23:09:16 UTC (rev 77) @@ -0,0 +1,97 @@ +# Microsoft Developer Studio Project File - Name="example5" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=example5 - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "example5.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "example5.mak" CFG="example5 - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "example5 - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "example5 - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "example5 - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x407 /d "NDEBUG" +# ADD RSC /l 0x407 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /machine:I386 +# SUBTRACT LINK32 /verbose + +!ELSEIF "$(CFG)" == "example5 - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "_DEBUG" /FR /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x407 /d "_DEBUG" +# ADD RSC /l 0x407 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "example5 - Win32 Release" +# Name "example5 - Win32 Debug" +# Begin Source File + +SOURCE=.\example5.cpp +# End Source File +# Begin Source File + +SOURCE=.\example5.xml +# End Source File +# End Target +# End Project Property changes on: trunk/c++/example5.dsp ___________________________________________________________________ Name: svn:eol-style + CRLF Modified: trunk/c++/xmlstorage.dsw =================================================================== --- trunk/c++/xmlstorage.dsw 2008-01-30 23:07:48 UTC (rev 76) +++ trunk/c++/xmlstorage.dsw 2008-01-30 23:09:16 UTC (rev 77) @@ -48,6 +48,30 @@ ############################################################################### +Project: "example4"=.\example4.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "example5"=.\example5.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + Project: "writertest"=.\writertest.dsp - Package Owner=<4> Package=<5> Modified: trunk/c++/xmlstorage.h =================================================================== --- trunk/c++/xmlstorage.h 2008-01-30 23:07:48 UTC (rev 76) +++ trunk/c++/xmlstorage.h 2008-01-30 23:09:16 UTC (rev 77) @@ -2,7 +2,7 @@ // // XML storage C++ classes version 1.2 // - // Copyright (c) 2004, 2005, 2006, 2007 Martin Fuchs <mar...@gm...> + // Copyright (c) 2004, 2005, 2006, 2007, 2008 Martin Fuchs <mar...@gm...> // /// \file xmlstorage.h @@ -265,10 +265,7 @@ #endif -int inline isxmlsym(unsigned char c) -{ - return isalnum(c) || c=='_' || c=='-'; -} +extern const char* get_xmlsym_end_utf8(const char* p); #if defined(_STRING_DEFINED) && !defined(XS_STRING_UTF8) @@ -860,6 +857,17 @@ delete node; } } + + bool remove(XMLNode* node) + { + for(iterator it=begin(); it!=end(); ++it) + if (*it == node) { + erase(it); + return true; + } + + return false; + } }; // access to protected class members for XMLPos and XMLReader @@ -1452,6 +1460,21 @@ return false; } + /// delete current node and go back to previous position + bool delete_this() + { + if (!_stack.empty()) { + XMLNode* pLast = _stack.top(); + + if (pLast->_children.remove(_cur)) { + _cur = _stack.top(); + return true; + } + } + + return false; + } + /// go down to first child bool go_down() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-01-30 23:07:50
|
Revision: 76 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=76&view=rev Author: martinfuchs Date: 2008-01-30 15:07:48 -0800 (Wed, 30 Jan 2008) Log Message: ----------- example 4 to show usage of set_content() and get_content() Added Paths: ----------- trunk/c++/example4.cpp trunk/c++/example4.dsp Added: trunk/c++/example4.cpp =================================================================== --- trunk/c++/example4.cpp (rev 0) +++ trunk/c++/example4.cpp 2008-01-30 23:07:48 UTC (rev 76) @@ -0,0 +1,91 @@ + + // + // XML storage classes + // + // example4.cpp + // + // Copyright (c) 2007 Martin Fuchs <mar...@gm...> + // + + +/* + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + +*/ + +#include <xmlstorage.h> +using namespace XMLStorage; + +#include <iostream> +using namespace std; + + +void test_write() +{ + XMLWriter out("enum-children.xml"); + + out.create("Test"); + out.create("Child"); + out.set_content("Wert1"); + out.back(); + + out.create("Child"); + out.set_content("Wert2"); + out.back(); + out.back(); +} + + +void test_read() +{ + XMLDoc doc; + + // Einlesen des XML-Files + doc.read_file("enum-children.xml"); + + XMLPos pos(&doc); + + if (pos.go("Test")) { + const_XMLChildrenFilter children(pos, "Child"); + + for(const_XMLChildrenFilter::const_iterator it=children.begin(); it!=children.end(); ++it) { + const XMLNode* node = *it; + + cout << node->get_content() << endl; + } + + pos.back(); + } +} + + +int main() +{ + test_write(); + test_read(); + + return 0; +} Property changes on: trunk/c++/example4.cpp ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Added: trunk/c++/example4.dsp =================================================================== --- trunk/c++/example4.dsp (rev 0) +++ trunk/c++/example4.dsp 2008-01-30 23:07:48 UTC (rev 76) @@ -0,0 +1,97 @@ +# Microsoft Developer Studio Project File - Name="example4" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=example4 - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "example4.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "example4.mak" CFG="example4 - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "example4 - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "example4 - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "example4 - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "." +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /D "NDEBUG" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x407 /d "NDEBUG" +# ADD RSC /l 0x407 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 /nologo /subsystem:console /machine:I386 +# SUBTRACT LINK32 /verbose + +!ELSEIF "$(CFG)" == "example4 - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "_DEBUG" /FR /FD /GZ /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x407 /d "_DEBUG" +# ADD RSC /l 0x407 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "example4 - Win32 Release" +# Name "example4 - Win32 Debug" +# Begin Source File + +SOURCE=".\enum-children.xml" +# End Source File +# Begin Source File + +SOURCE=.\example4.cpp +# End Source File +# End Target +# End Project Property changes on: trunk/c++/example4.dsp ___________________________________________________________________ Name: svn:eol-style + CRLF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mar...@us...> - 2008-01-30 23:05:55
|
Revision: 75 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=75&view=rev Author: martinfuchs Date: 2008-01-30 15:05:56 -0800 (Wed, 30 Jan 2008) Log Message: ----------- allow UTF-8 encoded umlaut characters in tag names Modified Paths: -------------- trunk/c++/xmlstorage.cpp trunk/c++/xs-native.cpp Modified: trunk/c++/xmlstorage.cpp =================================================================== --- trunk/c++/xmlstorage.cpp 2008-01-19 18:00:57 UTC (rev 74) +++ trunk/c++/xmlstorage.cpp 2008-01-30 23:05:56 UTC (rev 75) @@ -2,7 +2,7 @@ // // XML storage C++ classes version 1.2 // - // Copyright (c) 2004, 2005, 2006, 2007 Martin Fuchs <mar...@gm...> + // Copyright (c) 2004, 2005, 2006, 2007, 2008 Martin Fuchs <mar...@gm...> // /// \file xmlstorage.cpp @@ -534,18 +534,33 @@ } +const char* get_xmlsym_end_utf8(const char* p) +{ + for(; *p; ++p) { + char c = *p; + + if (c == '\xC3') // UTF-8 escape character + ++p; //TODO only continue on umlaut characters + else if (!isalnum(c) && c!='_' && c!='-') + break; + } + + return p; +} + + void DocType::parse(const char* p) { while(isspace((unsigned char)*p)) ++p; const char* start = p; - while(isxmlsym(*p)) ++p; + p = get_xmlsym_end_utf8(p); _name.assign(start, p-start); while(isspace((unsigned char)*p)) ++p; start = p; - while(isxmlsym(*p)) ++p; + p = get_xmlsym_end_utf8(p); std::string keyword(p, p-start); // "PUBLIC" or "SYSTEM" while(isspace((unsigned char)*p)) ++p; Modified: trunk/c++/xs-native.cpp =================================================================== --- trunk/c++/xs-native.cpp 2008-01-19 18:00:57 UTC (rev 74) +++ trunk/c++/xs-native.cpp 2008-01-30 23:05:56 UTC (rev 75) @@ -93,7 +93,7 @@ _buffer_str.erase(); } - void append(char c) + void append(int c) { size_t wpos = _wptr-_buffer; @@ -103,7 +103,7 @@ _wptr = _buffer + wpos; } - *_wptr++ = c; + *_wptr++ = static_cast<char>(c); } const std::string& str(bool utf8) // returns UTF-8 encoded buffer content @@ -148,8 +148,7 @@ if (*q == '?') ++q; - while(isxmlsym(*q)) - ++q; + q = get_xmlsym_end_utf8(q); #ifdef XS_STRING_UTF8 return XS_String(p, q-p); @@ -174,8 +173,7 @@ else if (*p == '?') ++p; - while(isxmlsym(*p)) - ++p; + p = get_xmlsym_end_utf8(p); // read attributes from buffer while(*p && *p!='>' && *p!='/') { @@ -184,8 +182,7 @@ const char* attr_name = p; - while(isxmlsym(*p)) - ++p; + p = get_xmlsym_end_utf8(p); if (*p != '=') break; //@TODO error handling This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |