gambas-source-code/gb.xml/src/CNode.cpp

439 lines
10 KiB
C++
Raw Normal View History

/***************************************************************************
(c) 2012 Adrien Prokopowicz <prokopy@users.sourceforge.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
***************************************************************************/
#include "CNode.h"
#include "node.h"
#include "document.h"
#include "element.h"
#include "textnode.h"
#include "serializer.h"
#include <stdlib.h>
#define THISOBJ ((CNode*)_object)
[GB.XML] OPT : A few compilation optimizations in headers inclusions. OPT : Use of separated internal classes of gambas objects. This might prevent from a lot of problems. OPT : Strings are not stored as wchar_t* anymore, but as simple char*, and are converted only when necessary (like UTF8 characters verification). OPT : Does not use STL classes anymore. They are too slow. Uses now handmade classes. OPT : Nodes are now internally linked to their brothers, so it makes find them really fasters, and allows no longer use of external linked list. OPT : When creating new nodes, linked Gambas objects are created only when necessary, so it makes internals instanciations very faster (such as the parser). OPT : Handmade string/memory classes and functions are now separated from the main.cpp component file. OPT : Use specialized memory management functions (like memcpy, memchr ...) into the parser. They are really faster than C loops, and speeds up the parser for documents that have a lot of plain text. OPT : Internally, the stream parser (XmlReader) takes only one char, not a unuseful wole string object. OPT : Does not updates debugging data when parsing a file. They will be generated only if an error is raised (not implemented yet). It will allow a speedier parser and more precise informations. BUG : When loading a document from a file, now correctly releases the file data. BUG : Solved a few XmlReader uninitialized variables, that could make the stream parser crash or returns strange results. git-svn-id: svn://localhost/gambas/trunk@4737 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-17 22:49:54 +02:00
#define THIS (static_cast<CNode*>(_object)->node)
#define NODE_BASE 0
#define NODE_ELEMENT 1
#define NODE_TEXT 2
#define NODE_COMMENT 3
#define NODE_CDATA 4
#define NODE_ATTRIBUTE 5
#define NODE_DOCUMENT 6
[GB.XML] OPT : A few compilation optimizations in headers inclusions. OPT : Use of separated internal classes of gambas objects. This might prevent from a lot of problems. OPT : Strings are not stored as wchar_t* anymore, but as simple char*, and are converted only when necessary (like UTF8 characters verification). OPT : Does not use STL classes anymore. They are too slow. Uses now handmade classes. OPT : Nodes are now internally linked to their brothers, so it makes find them really fasters, and allows no longer use of external linked list. OPT : When creating new nodes, linked Gambas objects are created only when necessary, so it makes internals instanciations very faster (such as the parser). OPT : Handmade string/memory classes and functions are now separated from the main.cpp component file. OPT : Use specialized memory management functions (like memcpy, memchr ...) into the parser. They are really faster than C loops, and speeds up the parser for documents that have a lot of plain text. OPT : Internally, the stream parser (XmlReader) takes only one char, not a unuseful wole string object. OPT : Does not updates debugging data when parsing a file. They will be generated only if an error is raised (not implemented yet). It will allow a speedier parser and more precise informations. BUG : When loading a document from a file, now correctly releases the file data. BUG : Solved a few XmlReader uninitialized variables, that could make the stream parser crash or returns strange results. git-svn-id: svn://localhost/gambas/trunk@4737 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-17 22:49:54 +02:00
BEGIN_METHOD_VOID(CNode_new)
if(XMLNode_NoInstanciate()) return;
[GB.XML] OPT : A few compilation optimizations in headers inclusions. OPT : Use of separated internal classes of gambas objects. This might prevent from a lot of problems. OPT : Strings are not stored as wchar_t* anymore, but as simple char*, and are converted only when necessary (like UTF8 characters verification). OPT : Does not use STL classes anymore. They are too slow. Uses now handmade classes. OPT : Nodes are now internally linked to their brothers, so it makes find them really fasters, and allows no longer use of external linked list. OPT : When creating new nodes, linked Gambas objects are created only when necessary, so it makes internals instanciations very faster (such as the parser). OPT : Handmade string/memory classes and functions are now separated from the main.cpp component file. OPT : Use specialized memory management functions (like memcpy, memchr ...) into the parser. They are really faster than C loops, and speeds up the parser for documents that have a lot of plain text. OPT : Internally, the stream parser (XmlReader) takes only one char, not a unuseful wole string object. OPT : Does not updates debugging data when parsing a file. They will be generated only if an error is raised (not implemented yet). It will allow a speedier parser and more precise informations. BUG : When loading a document from a file, now correctly releases the file data. BUG : Solved a few XmlReader uninitialized variables, that could make the stream parser crash or returns strange results. git-svn-id: svn://localhost/gambas/trunk@4737 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-17 22:49:54 +02:00
END_METHOD
BEGIN_METHOD_VOID(CNode_free)
XMLNode_DestroyGBObject(THIS);
END_METHOD
BEGIN_METHOD(CNode_tostring, GB_BOOLEAN indent)
char *str = 0;
size_t len = 0;
GBserializeNode(THIS, str, len, VARG(indent) ? 0 : -1);
GB.ReturnString(str);
END_METHOD
BEGIN_PROPERTY(CNode_type)
switch(THIS->type)
{
case Node::ElementNode:
GB.ReturnInteger(NODE_ELEMENT);break;
case Node::Comment:
GB.ReturnInteger(NODE_COMMENT);break;
case Node::NodeText:
GB.ReturnInteger(NODE_TEXT);break;
case Node::CDATA:
GB.ReturnInteger(NODE_CDATA);break;
default:
GB.ReturnInteger(NODE_BASE);
}
END_PROPERTY
BEGIN_PROPERTY(CNode_isElement)
GB.ReturnBoolean(THIS->type == Node::ElementNode);
END_PROPERTY
BEGIN_PROPERTY(CNode_isText)
GB.ReturnBoolean(THIS->type == Node::NodeText);
END_PROPERTY
BEGIN_PROPERTY(CNode_isComment)
GB.ReturnBoolean(THIS->type == Node::Comment);
END_PROPERTY
BEGIN_PROPERTY(CNode_isCDATA)
GB.ReturnBoolean(THIS->type == Node::CDATA);
END_PROPERTY
BEGIN_PROPERTY(CNode_element)
XML_ReturnNode(THIS);
END_PROPERTY
BEGIN_PROPERTY(CNode_ownerDocument)
XML_ReturnNode((Node*)XMLNode_GetOwnerDocument((Node*)THIS));
END_PROPERTY
BEGIN_PROPERTY(CNode_parent)
XML_ReturnNode((Node*)(THIS->parent));
END_PROPERTY
BEGIN_PROPERTY(CNode_previous)
XML_ReturnNode((Node*)(THIS->previousNode));
END_PROPERTY
BEGIN_PROPERTY(CNode_next)
XML_ReturnNode((Node*)(THIS->nextNode));
END_PROPERTY
BEGIN_PROPERTY(CNode_textContent)
if(READ_PROPERTY)
{
char *data; size_t len;
GBGetXMLTextContent(THIS, data, len);
GB.ReturnString(data);
}
else
{
XMLNode_setTextContent(THIS, PSTRING(), PLENGTH());
}
END_PROPERTY
BEGIN_PROPERTY(CNode_name)
if(!READ_PROPERTY)
{
if(THIS->type == Node::ElementNode)
{
XMLElement_SetTagName((Element*)THIS, PSTRING(), PLENGTH());
}
return;
}
switch (THIS->type)
{
case Node::ElementNode:
GB.ReturnNewString(((Element*)THIS)->tagName, ((Element*)THIS)->lenTagName);break;
case Node::NodeText:
GB.ReturnNewZeroString("#text");break;
case Node::Comment:
GB.ReturnNewZeroString("#comment");break;
case Node::CDATA:
GB.ReturnNewZeroString("#cdata");break;
case Node::AttributeNode:
GB.ReturnNewString(((Attribute*)THIS)->attrName, ((Attribute*)THIS)->lenAttrName);break;
default:
GB.ReturnNewZeroString("");
}
END_PROPERTY
BEGIN_METHOD(CNode_newElement, GB_STRING name; GB_STRING value)
if(!SUPPORT_CHILDREN(THIS)) return;
Element *elmt = XMLElement_New(STRING(name), LENGTH(name));
if(!MISSING(value)) XMLElement_SetTextContent(elmt, STRING(value), LENGTH(value));
XMLNode_appendChild(THIS, elmt);
END_METHOD
BEGIN_METHOD(CNode_setAttribute, GB_STRING attr; GB_STRING val)
if(THIS->type != Node::ElementNode) return;
XMLElement_SetAttribute(((Element*)THIS), STRING(attr), LENGTH(attr),
STRING(val), LENGTH(val));
END_METHOD
[GB.XML] * NEW : Added a new property "State" to XmlExplorer and XmlReader, that allows to know the reader state, without knowing Read() return value. * NEW : When enumerating XmlReader.Node.Attributes, XmlReader.Node represents the current attribute. * NEW : Added an new method Open() that loads an HtmlDocument from a file and defines it as the document to read. * NEW : The Attributes property has now moved from XmlElement to XmlNode. XmlNode.Attributes returns Null if the node isn't an element. * NEW : Then enumeration of XmlNode.Attributes now returns an .XmlElementAttribute instead of a string. * NEW : The XmlNode.Attribute constant is not obsolete anymore. * NEW : Two consecutives whitespaces are now ignored (only one is preserved). * NEW : When parsing a file, line-breaks and tabulations are replaced by spaces. * BUG : XmlExplorer flags are now correctly initialized. * BUG : Added an Eof property on XmlExplorer, that was missing. * BUG : Calling XmlExplorer.Read() after Eof just returns XmlReaderNodeType.Eof, not more. * BUG : Calling XmlNode.Next() when the node hasn't got any brother after him doesn't crash anymore, it just returns Null. * BUG : Calling XmlElement.NextSibling() when the node hasn't got any element brother after him doesn't crash anymore, it just returns Null. * BUG : By default, XmlReader correctly stops when reading the end of an element. * BUG : XmlExplorer now correctly initializes and releases itself. * BUG : XmlExplorer now correctly supports its read flags. * OPT : Solved a memory leak when releasing a XmlReader. * OPT : When setting text content to a XmlNode, the string is not duplicated anymore. * OPT : When testing if characters are whitespaces or names characters while parsing texts, puts the temporary variable into registers instead of memory. git-svn-id: svn://localhost/gambas/trunk@4669 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-04-25 01:47:14 +02:00
BEGIN_METHOD(CElementAttributes_get, GB_STRING name)
if(THIS->type != Node::ElementNode) return;
Attribute *attr = XMLElement_GetAttribute((Element*)THIS, STRING(name), LENGTH(name));
if(attr && attr->attrValue && attr->lenAttrValue)
{
GB.ReturnNewString(attr->attrValue, attr->lenAttrValue);
}
else
{
GB.ReturnNull();
}
[GB.XML] * NEW : Added a new property "State" to XmlExplorer and XmlReader, that allows to know the reader state, without knowing Read() return value. * NEW : When enumerating XmlReader.Node.Attributes, XmlReader.Node represents the current attribute. * NEW : Added an new method Open() that loads an HtmlDocument from a file and defines it as the document to read. * NEW : The Attributes property has now moved from XmlElement to XmlNode. XmlNode.Attributes returns Null if the node isn't an element. * NEW : Then enumeration of XmlNode.Attributes now returns an .XmlElementAttribute instead of a string. * NEW : The XmlNode.Attribute constant is not obsolete anymore. * NEW : Two consecutives whitespaces are now ignored (only one is preserved). * NEW : When parsing a file, line-breaks and tabulations are replaced by spaces. * BUG : XmlExplorer flags are now correctly initialized. * BUG : Added an Eof property on XmlExplorer, that was missing. * BUG : Calling XmlExplorer.Read() after Eof just returns XmlReaderNodeType.Eof, not more. * BUG : Calling XmlNode.Next() when the node hasn't got any brother after him doesn't crash anymore, it just returns Null. * BUG : Calling XmlElement.NextSibling() when the node hasn't got any element brother after him doesn't crash anymore, it just returns Null. * BUG : By default, XmlReader correctly stops when reading the end of an element. * BUG : XmlExplorer now correctly initializes and releases itself. * BUG : XmlExplorer now correctly supports its read flags. * OPT : Solved a memory leak when releasing a XmlReader. * OPT : When setting text content to a XmlNode, the string is not duplicated anymore. * OPT : When testing if characters are whitespaces or names characters while parsing texts, puts the temporary variable into registers instead of memory. git-svn-id: svn://localhost/gambas/trunk@4669 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-04-25 01:47:14 +02:00
END_METHOD
BEGIN_METHOD(CElementAttributes_put, GB_STRING value; GB_STRING name)
if(THIS->type != Node::ElementNode) return;
XMLElement_SetAttribute((Element*)THIS, STRING(name), LENGTH(name),
STRING(value), LENGTH(value));
[GB.XML] * NEW : Added a new property "State" to XmlExplorer and XmlReader, that allows to know the reader state, without knowing Read() return value. * NEW : When enumerating XmlReader.Node.Attributes, XmlReader.Node represents the current attribute. * NEW : Added an new method Open() that loads an HtmlDocument from a file and defines it as the document to read. * NEW : The Attributes property has now moved from XmlElement to XmlNode. XmlNode.Attributes returns Null if the node isn't an element. * NEW : Then enumeration of XmlNode.Attributes now returns an .XmlElementAttribute instead of a string. * NEW : The XmlNode.Attribute constant is not obsolete anymore. * NEW : Two consecutives whitespaces are now ignored (only one is preserved). * NEW : When parsing a file, line-breaks and tabulations are replaced by spaces. * BUG : XmlExplorer flags are now correctly initialized. * BUG : Added an Eof property on XmlExplorer, that was missing. * BUG : Calling XmlExplorer.Read() after Eof just returns XmlReaderNodeType.Eof, not more. * BUG : Calling XmlNode.Next() when the node hasn't got any brother after him doesn't crash anymore, it just returns Null. * BUG : Calling XmlElement.NextSibling() when the node hasn't got any element brother after him doesn't crash anymore, it just returns Null. * BUG : By default, XmlReader correctly stops when reading the end of an element. * BUG : XmlExplorer now correctly initializes and releases itself. * BUG : XmlExplorer now correctly supports its read flags. * OPT : Solved a memory leak when releasing a XmlReader. * OPT : When setting text content to a XmlNode, the string is not duplicated anymore. * OPT : When testing if characters are whitespaces or names characters while parsing texts, puts the temporary variable into registers instead of memory. git-svn-id: svn://localhost/gambas/trunk@4669 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-04-25 01:47:14 +02:00
END_METHOD
BEGIN_PROPERTY(CElementAttributes_count)
if(THIS->type != Node::ElementNode)
{
GB.ReturnInteger(0);
return;
}
[GB.XML] * NEW : Added a new property "State" to XmlExplorer and XmlReader, that allows to know the reader state, without knowing Read() return value. * NEW : When enumerating XmlReader.Node.Attributes, XmlReader.Node represents the current attribute. * NEW : Added an new method Open() that loads an HtmlDocument from a file and defines it as the document to read. * NEW : The Attributes property has now moved from XmlElement to XmlNode. XmlNode.Attributes returns Null if the node isn't an element. * NEW : Then enumeration of XmlNode.Attributes now returns an .XmlElementAttribute instead of a string. * NEW : The XmlNode.Attribute constant is not obsolete anymore. * NEW : Two consecutives whitespaces are now ignored (only one is preserved). * NEW : When parsing a file, line-breaks and tabulations are replaced by spaces. * BUG : XmlExplorer flags are now correctly initialized. * BUG : Added an Eof property on XmlExplorer, that was missing. * BUG : Calling XmlExplorer.Read() after Eof just returns XmlReaderNodeType.Eof, not more. * BUG : Calling XmlNode.Next() when the node hasn't got any brother after him doesn't crash anymore, it just returns Null. * BUG : Calling XmlElement.NextSibling() when the node hasn't got any element brother after him doesn't crash anymore, it just returns Null. * BUG : By default, XmlReader correctly stops when reading the end of an element. * BUG : XmlExplorer now correctly initializes and releases itself. * BUG : XmlExplorer now correctly supports its read flags. * OPT : Solved a memory leak when releasing a XmlReader. * OPT : When setting text content to a XmlNode, the string is not duplicated anymore. * OPT : When testing if characters are whitespaces or names characters while parsing texts, puts the temporary variable into registers instead of memory. git-svn-id: svn://localhost/gambas/trunk@4669 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-04-25 01:47:14 +02:00
if(READ_PROPERTY)
{
GB.ReturnInteger(((Element*)THIS)->attributeCount);
[GB.XML] * NEW : Added a new property "State" to XmlExplorer and XmlReader, that allows to know the reader state, without knowing Read() return value. * NEW : When enumerating XmlReader.Node.Attributes, XmlReader.Node represents the current attribute. * NEW : Added an new method Open() that loads an HtmlDocument from a file and defines it as the document to read. * NEW : The Attributes property has now moved from XmlElement to XmlNode. XmlNode.Attributes returns Null if the node isn't an element. * NEW : Then enumeration of XmlNode.Attributes now returns an .XmlElementAttribute instead of a string. * NEW : The XmlNode.Attribute constant is not obsolete anymore. * NEW : Two consecutives whitespaces are now ignored (only one is preserved). * NEW : When parsing a file, line-breaks and tabulations are replaced by spaces. * BUG : XmlExplorer flags are now correctly initialized. * BUG : Added an Eof property on XmlExplorer, that was missing. * BUG : Calling XmlExplorer.Read() after Eof just returns XmlReaderNodeType.Eof, not more. * BUG : Calling XmlNode.Next() when the node hasn't got any brother after him doesn't crash anymore, it just returns Null. * BUG : Calling XmlElement.NextSibling() when the node hasn't got any element brother after him doesn't crash anymore, it just returns Null. * BUG : By default, XmlReader correctly stops when reading the end of an element. * BUG : XmlExplorer now correctly initializes and releases itself. * BUG : XmlExplorer now correctly supports its read flags. * OPT : Solved a memory leak when releasing a XmlReader. * OPT : When setting text content to a XmlNode, the string is not duplicated anymore. * OPT : When testing if characters are whitespaces or names characters while parsing texts, puts the temporary variable into registers instead of memory. git-svn-id: svn://localhost/gambas/trunk@4669 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-04-25 01:47:14 +02:00
}
END_PROPERTY
BEGIN_METHOD_VOID(CElementAttributes_next)
if(THIS->type != Node::ElementNode) {GB.StopEnum(); return;}
Attribute *attr = *reinterpret_cast<Attribute**>((GB.GetEnum()));
if(attr == 0)
[GB.XML] * NEW : Added a new property "State" to XmlExplorer and XmlReader, that allows to know the reader state, without knowing Read() return value. * NEW : When enumerating XmlReader.Node.Attributes, XmlReader.Node represents the current attribute. * NEW : Added an new method Open() that loads an HtmlDocument from a file and defines it as the document to read. * NEW : The Attributes property has now moved from XmlElement to XmlNode. XmlNode.Attributes returns Null if the node isn't an element. * NEW : Then enumeration of XmlNode.Attributes now returns an .XmlElementAttribute instead of a string. * NEW : The XmlNode.Attribute constant is not obsolete anymore. * NEW : Two consecutives whitespaces are now ignored (only one is preserved). * NEW : When parsing a file, line-breaks and tabulations are replaced by spaces. * BUG : XmlExplorer flags are now correctly initialized. * BUG : Added an Eof property on XmlExplorer, that was missing. * BUG : Calling XmlExplorer.Read() after Eof just returns XmlReaderNodeType.Eof, not more. * BUG : Calling XmlNode.Next() when the node hasn't got any brother after him doesn't crash anymore, it just returns Null. * BUG : Calling XmlElement.NextSibling() when the node hasn't got any element brother after him doesn't crash anymore, it just returns Null. * BUG : By default, XmlReader correctly stops when reading the end of an element. * BUG : XmlExplorer now correctly initializes and releases itself. * BUG : XmlExplorer now correctly supports its read flags. * OPT : Solved a memory leak when releasing a XmlReader. * OPT : When setting text content to a XmlNode, the string is not duplicated anymore. * OPT : When testing if characters are whitespaces or names characters while parsing texts, puts the temporary variable into registers instead of memory. git-svn-id: svn://localhost/gambas/trunk@4669 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-04-25 01:47:14 +02:00
{
attr = ((Element*)THIS)->firstAttribute;
*reinterpret_cast<Attribute**>(GB.GetEnum()) = attr;
[GB.XML] * NEW : Added a new property "State" to XmlExplorer and XmlReader, that allows to know the reader state, without knowing Read() return value. * NEW : When enumerating XmlReader.Node.Attributes, XmlReader.Node represents the current attribute. * NEW : Added an new method Open() that loads an HtmlDocument from a file and defines it as the document to read. * NEW : The Attributes property has now moved from XmlElement to XmlNode. XmlNode.Attributes returns Null if the node isn't an element. * NEW : Then enumeration of XmlNode.Attributes now returns an .XmlElementAttribute instead of a string. * NEW : The XmlNode.Attribute constant is not obsolete anymore. * NEW : Two consecutives whitespaces are now ignored (only one is preserved). * NEW : When parsing a file, line-breaks and tabulations are replaced by spaces. * BUG : XmlExplorer flags are now correctly initialized. * BUG : Added an Eof property on XmlExplorer, that was missing. * BUG : Calling XmlExplorer.Read() after Eof just returns XmlReaderNodeType.Eof, not more. * BUG : Calling XmlNode.Next() when the node hasn't got any brother after him doesn't crash anymore, it just returns Null. * BUG : Calling XmlElement.NextSibling() when the node hasn't got any element brother after him doesn't crash anymore, it just returns Null. * BUG : By default, XmlReader correctly stops when reading the end of an element. * BUG : XmlExplorer now correctly initializes and releases itself. * BUG : XmlExplorer now correctly supports its read flags. * OPT : Solved a memory leak when releasing a XmlReader. * OPT : When setting text content to a XmlNode, the string is not duplicated anymore. * OPT : When testing if characters are whitespaces or names characters while parsing texts, puts the temporary variable into registers instead of memory. git-svn-id: svn://localhost/gambas/trunk@4669 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-04-25 01:47:14 +02:00
}
else
{
attr = (Attribute*)attr->nextNode;
*reinterpret_cast<Attribute**>(GB.GetEnum()) = attr;
[GB.XML] * NEW : Added a new property "State" to XmlExplorer and XmlReader, that allows to know the reader state, without knowing Read() return value. * NEW : When enumerating XmlReader.Node.Attributes, XmlReader.Node represents the current attribute. * NEW : Added an new method Open() that loads an HtmlDocument from a file and defines it as the document to read. * NEW : The Attributes property has now moved from XmlElement to XmlNode. XmlNode.Attributes returns Null if the node isn't an element. * NEW : Then enumeration of XmlNode.Attributes now returns an .XmlElementAttribute instead of a string. * NEW : The XmlNode.Attribute constant is not obsolete anymore. * NEW : Two consecutives whitespaces are now ignored (only one is preserved). * NEW : When parsing a file, line-breaks and tabulations are replaced by spaces. * BUG : XmlExplorer flags are now correctly initialized. * BUG : Added an Eof property on XmlExplorer, that was missing. * BUG : Calling XmlExplorer.Read() after Eof just returns XmlReaderNodeType.Eof, not more. * BUG : Calling XmlNode.Next() when the node hasn't got any brother after him doesn't crash anymore, it just returns Null. * BUG : Calling XmlElement.NextSibling() when the node hasn't got any element brother after him doesn't crash anymore, it just returns Null. * BUG : By default, XmlReader correctly stops when reading the end of an element. * BUG : XmlExplorer now correctly initializes and releases itself. * BUG : XmlExplorer now correctly supports its read flags. * OPT : Solved a memory leak when releasing a XmlReader. * OPT : When setting text content to a XmlNode, the string is not duplicated anymore. * OPT : When testing if characters are whitespaces or names characters while parsing texts, puts the temporary variable into registers instead of memory. git-svn-id: svn://localhost/gambas/trunk@4669 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-04-25 01:47:14 +02:00
}
THISOBJ->curAttrEnum = attr;
if(attr == 0) {GB.StopEnum(); return;}
[GB.XML] * NEW : Added a new property "State" to XmlExplorer and XmlReader, that allows to know the reader state, without knowing Read() return value. * NEW : When enumerating XmlReader.Node.Attributes, XmlReader.Node represents the current attribute. * NEW : Added an new method Open() that loads an HtmlDocument from a file and defines it as the document to read. * NEW : The Attributes property has now moved from XmlElement to XmlNode. XmlNode.Attributes returns Null if the node isn't an element. * NEW : Then enumeration of XmlNode.Attributes now returns an .XmlElementAttribute instead of a string. * NEW : The XmlNode.Attribute constant is not obsolete anymore. * NEW : Two consecutives whitespaces are now ignored (only one is preserved). * NEW : When parsing a file, line-breaks and tabulations are replaced by spaces. * BUG : XmlExplorer flags are now correctly initialized. * BUG : Added an Eof property on XmlExplorer, that was missing. * BUG : Calling XmlExplorer.Read() after Eof just returns XmlReaderNodeType.Eof, not more. * BUG : Calling XmlNode.Next() when the node hasn't got any brother after him doesn't crash anymore, it just returns Null. * BUG : Calling XmlElement.NextSibling() when the node hasn't got any element brother after him doesn't crash anymore, it just returns Null. * BUG : By default, XmlReader correctly stops when reading the end of an element. * BUG : XmlExplorer now correctly initializes and releases itself. * BUG : XmlExplorer now correctly supports its read flags. * OPT : Solved a memory leak when releasing a XmlReader. * OPT : When setting text content to a XmlNode, the string is not duplicated anymore. * OPT : When testing if characters are whitespaces or names characters while parsing texts, puts the temporary variable into registers instead of memory. git-svn-id: svn://localhost/gambas/trunk@4669 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-04-25 01:47:14 +02:00
XML_ReturnNode(attr);
[GB.XML] * NEW : Added a new property "State" to XmlExplorer and XmlReader, that allows to know the reader state, without knowing Read() return value. * NEW : When enumerating XmlReader.Node.Attributes, XmlReader.Node represents the current attribute. * NEW : Added an new method Open() that loads an HtmlDocument from a file and defines it as the document to read. * NEW : The Attributes property has now moved from XmlElement to XmlNode. XmlNode.Attributes returns Null if the node isn't an element. * NEW : Then enumeration of XmlNode.Attributes now returns an .XmlElementAttribute instead of a string. * NEW : The XmlNode.Attribute constant is not obsolete anymore. * NEW : Two consecutives whitespaces are now ignored (only one is preserved). * NEW : When parsing a file, line-breaks and tabulations are replaced by spaces. * BUG : XmlExplorer flags are now correctly initialized. * BUG : Added an Eof property on XmlExplorer, that was missing. * BUG : Calling XmlExplorer.Read() after Eof just returns XmlReaderNodeType.Eof, not more. * BUG : Calling XmlNode.Next() when the node hasn't got any brother after him doesn't crash anymore, it just returns Null. * BUG : Calling XmlElement.NextSibling() when the node hasn't got any element brother after him doesn't crash anymore, it just returns Null. * BUG : By default, XmlReader correctly stops when reading the end of an element. * BUG : XmlExplorer now correctly initializes and releases itself. * BUG : XmlExplorer now correctly supports its read flags. * OPT : Solved a memory leak when releasing a XmlReader. * OPT : When setting text content to a XmlNode, the string is not duplicated anymore. * OPT : When testing if characters are whitespaces or names characters while parsing texts, puts the temporary variable into registers instead of memory. git-svn-id: svn://localhost/gambas/trunk@4669 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-04-25 01:47:14 +02:00
END_METHOD
BEGIN_PROPERTY(CElementAttributes_name)
if(!THISOBJ->curAttrEnum)
{
GB.Error("No enumerated attribute available");
GB.ReturnNull();
return;
}
if(!THISOBJ->curAttrEnum->attrName || !THISOBJ->curAttrEnum->lenAttrName)
{
GB.ReturnNull();
return;
}
GB.ReturnNewString(THISOBJ->curAttrEnum->attrName, THISOBJ->curAttrEnum->lenAttrName);
END_PROPERTY
BEGIN_PROPERTY(CElementAttributes_value)
if(!THISOBJ->curAttrEnum)
{
GB.Error("No enumerated attribute available");
GB.ReturnNull();
return;
}
if(!THISOBJ->curAttrEnum->attrValue || !THISOBJ->curAttrEnum->lenAttrValue)
{
GB.ReturnNull();
return;
}
GB.ReturnNewString(THISOBJ->curAttrEnum->attrValue, THISOBJ->curAttrEnum->lenAttrValue);
END_PROPERTY
BEGIN_PROPERTY(CNode_childNodes)
GB_ARRAY array;
XMLNode_getGBChildren(THIS, &array);
GB.ReturnObject(array);
END_PROPERTY
BEGIN_METHOD(CNode_getUserData, GB_STRING key)
GB_VARIANT *value = XMLNode_getUserData(THIS, STRING(key), LENGTH(key));
if(value)
{
GB.ReturnVariant(&(value->value));
delete value;
}
else
{
GB.ReturnNull();
}
END_METHOD
BEGIN_METHOD(CNode_setUserData, GB_STRING key; GB_VARIANT value)
XMLNode_addUserData(THIS, STRING(key), LENGTH(key), ARG(value));
END_METHOD
BEGIN_METHOD(CNode_escapeContent, GB_STRING data)
if(!LENGTH(data))
{
GB.ReturnNull();
return;
}
char *escapedData; size_t lenEscapedData;
XMLText_escapeContent(STRING(data), LENGTH(data), escapedData, lenEscapedData);
GB.ReturnNewString(escapedData, lenEscapedData);
if(escapedData != STRING(data)) free(escapedData);
END_METHOD
BEGIN_METHOD(CNode_unEscapeContent, GB_STRING data)
if(!LENGTH(data))
{
GB.ReturnNull();
return;
}
char *unescapedData; size_t lenUnEscapedData;
XMLText_unEscapeContent(STRING(data), LENGTH(data), unescapedData, lenUnEscapedData);
GB.ReturnNewString(unescapedData, lenUnEscapedData);
if(unescapedData != STRING(data)) free(unescapedData);
END_METHOD
GB_DESC CElementAttributeNodeDesc[] =
[GB.XML] * NEW : Added a new property "State" to XmlExplorer and XmlReader, that allows to know the reader state, without knowing Read() return value. * NEW : When enumerating XmlReader.Node.Attributes, XmlReader.Node represents the current attribute. * NEW : Added an new method Open() that loads an HtmlDocument from a file and defines it as the document to read. * NEW : The Attributes property has now moved from XmlElement to XmlNode. XmlNode.Attributes returns Null if the node isn't an element. * NEW : Then enumeration of XmlNode.Attributes now returns an .XmlElementAttribute instead of a string. * NEW : The XmlNode.Attribute constant is not obsolete anymore. * NEW : Two consecutives whitespaces are now ignored (only one is preserved). * NEW : When parsing a file, line-breaks and tabulations are replaced by spaces. * BUG : XmlExplorer flags are now correctly initialized. * BUG : Added an Eof property on XmlExplorer, that was missing. * BUG : Calling XmlExplorer.Read() after Eof just returns XmlReaderNodeType.Eof, not more. * BUG : Calling XmlNode.Next() when the node hasn't got any brother after him doesn't crash anymore, it just returns Null. * BUG : Calling XmlElement.NextSibling() when the node hasn't got any element brother after him doesn't crash anymore, it just returns Null. * BUG : By default, XmlReader correctly stops when reading the end of an element. * BUG : XmlExplorer now correctly initializes and releases itself. * BUG : XmlExplorer now correctly supports its read flags. * OPT : Solved a memory leak when releasing a XmlReader. * OPT : When setting text content to a XmlNode, the string is not duplicated anymore. * OPT : When testing if characters are whitespaces or names characters while parsing texts, puts the temporary variable into registers instead of memory. git-svn-id: svn://localhost/gambas/trunk@4669 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-04-25 01:47:14 +02:00
{
GB_DECLARE("_XmlAttrNode", sizeof(CNode)), GB_INHERITS("XmlNode"),
[GB.XML] * NEW : Added a new property "State" to XmlExplorer and XmlReader, that allows to know the reader state, without knowing Read() return value. * NEW : When enumerating XmlReader.Node.Attributes, XmlReader.Node represents the current attribute. * NEW : Added an new method Open() that loads an HtmlDocument from a file and defines it as the document to read. * NEW : The Attributes property has now moved from XmlElement to XmlNode. XmlNode.Attributes returns Null if the node isn't an element. * NEW : Then enumeration of XmlNode.Attributes now returns an .XmlElementAttribute instead of a string. * NEW : The XmlNode.Attribute constant is not obsolete anymore. * NEW : Two consecutives whitespaces are now ignored (only one is preserved). * NEW : When parsing a file, line-breaks and tabulations are replaced by spaces. * BUG : XmlExplorer flags are now correctly initialized. * BUG : Added an Eof property on XmlExplorer, that was missing. * BUG : Calling XmlExplorer.Read() after Eof just returns XmlReaderNodeType.Eof, not more. * BUG : Calling XmlNode.Next() when the node hasn't got any brother after him doesn't crash anymore, it just returns Null. * BUG : Calling XmlElement.NextSibling() when the node hasn't got any element brother after him doesn't crash anymore, it just returns Null. * BUG : By default, XmlReader correctly stops when reading the end of an element. * BUG : XmlExplorer now correctly initializes and releases itself. * BUG : XmlExplorer now correctly supports its read flags. * OPT : Solved a memory leak when releasing a XmlReader. * OPT : When setting text content to a XmlNode, the string is not duplicated anymore. * OPT : When testing if characters are whitespaces or names characters while parsing texts, puts the temporary variable into registers instead of memory. git-svn-id: svn://localhost/gambas/trunk@4669 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-04-25 01:47:14 +02:00
GB_END_DECLARE
};
[GB.XML] * NEW : Added a new property "State" to XmlExplorer and XmlReader, that allows to know the reader state, without knowing Read() return value. * NEW : When enumerating XmlReader.Node.Attributes, XmlReader.Node represents the current attribute. * NEW : Added an new method Open() that loads an HtmlDocument from a file and defines it as the document to read. * NEW : The Attributes property has now moved from XmlElement to XmlNode. XmlNode.Attributes returns Null if the node isn't an element. * NEW : Then enumeration of XmlNode.Attributes now returns an .XmlElementAttribute instead of a string. * NEW : The XmlNode.Attribute constant is not obsolete anymore. * NEW : Two consecutives whitespaces are now ignored (only one is preserved). * NEW : When parsing a file, line-breaks and tabulations are replaced by spaces. * BUG : XmlExplorer flags are now correctly initialized. * BUG : Added an Eof property on XmlExplorer, that was missing. * BUG : Calling XmlExplorer.Read() after Eof just returns XmlReaderNodeType.Eof, not more. * BUG : Calling XmlNode.Next() when the node hasn't got any brother after him doesn't crash anymore, it just returns Null. * BUG : Calling XmlElement.NextSibling() when the node hasn't got any element brother after him doesn't crash anymore, it just returns Null. * BUG : By default, XmlReader correctly stops when reading the end of an element. * BUG : XmlExplorer now correctly initializes and releases itself. * BUG : XmlExplorer now correctly supports its read flags. * OPT : Solved a memory leak when releasing a XmlReader. * OPT : When setting text content to a XmlNode, the string is not duplicated anymore. * OPT : When testing if characters are whitespaces or names characters while parsing texts, puts the temporary variable into registers instead of memory. git-svn-id: svn://localhost/gambas/trunk@4669 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-04-25 01:47:14 +02:00
GB_DESC CElementAttributesDesc[] =
{
GB_DECLARE(".XmlElementAttributes", 0), GB_VIRTUAL_CLASS(),
GB_METHOD("_get", "s", CElementAttributes_get, "(Name)s"),
GB_METHOD("_put", "s", CElementAttributes_put, "(Value)s(Name)s"),
GB_METHOD("_next", "XmlNode", CElementAttributes_next, ""),
GB_PROPERTY_READ("Count", "i", CElementAttributes_count),
GB_PROPERTY_READ("Name", "s", CElementAttributes_name),
GB_PROPERTY_READ("Value", "s", CElementAttributes_value),
[GB.XML] * NEW : Added a new property "State" to XmlExplorer and XmlReader, that allows to know the reader state, without knowing Read() return value. * NEW : When enumerating XmlReader.Node.Attributes, XmlReader.Node represents the current attribute. * NEW : Added an new method Open() that loads an HtmlDocument from a file and defines it as the document to read. * NEW : The Attributes property has now moved from XmlElement to XmlNode. XmlNode.Attributes returns Null if the node isn't an element. * NEW : Then enumeration of XmlNode.Attributes now returns an .XmlElementAttribute instead of a string. * NEW : The XmlNode.Attribute constant is not obsolete anymore. * NEW : Two consecutives whitespaces are now ignored (only one is preserved). * NEW : When parsing a file, line-breaks and tabulations are replaced by spaces. * BUG : XmlExplorer flags are now correctly initialized. * BUG : Added an Eof property on XmlExplorer, that was missing. * BUG : Calling XmlExplorer.Read() after Eof just returns XmlReaderNodeType.Eof, not more. * BUG : Calling XmlNode.Next() when the node hasn't got any brother after him doesn't crash anymore, it just returns Null. * BUG : Calling XmlElement.NextSibling() when the node hasn't got any element brother after him doesn't crash anymore, it just returns Null. * BUG : By default, XmlReader correctly stops when reading the end of an element. * BUG : XmlExplorer now correctly initializes and releases itself. * BUG : XmlExplorer now correctly supports its read flags. * OPT : Solved a memory leak when releasing a XmlReader. * OPT : When setting text content to a XmlNode, the string is not duplicated anymore. * OPT : When testing if characters are whitespaces or names characters while parsing texts, puts the temporary variable into registers instead of memory. git-svn-id: svn://localhost/gambas/trunk@4669 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-04-25 01:47:14 +02:00
GB_END_DECLARE
};
GB_DESC CNodeDesc[] =
{
[GB.XML] OPT : A few compilation optimizations in headers inclusions. OPT : Use of separated internal classes of gambas objects. This might prevent from a lot of problems. OPT : Strings are not stored as wchar_t* anymore, but as simple char*, and are converted only when necessary (like UTF8 characters verification). OPT : Does not use STL classes anymore. They are too slow. Uses now handmade classes. OPT : Nodes are now internally linked to their brothers, so it makes find them really fasters, and allows no longer use of external linked list. OPT : When creating new nodes, linked Gambas objects are created only when necessary, so it makes internals instanciations very faster (such as the parser). OPT : Handmade string/memory classes and functions are now separated from the main.cpp component file. OPT : Use specialized memory management functions (like memcpy, memchr ...) into the parser. They are really faster than C loops, and speeds up the parser for documents that have a lot of plain text. OPT : Internally, the stream parser (XmlReader) takes only one char, not a unuseful wole string object. OPT : Does not updates debugging data when parsing a file. They will be generated only if an error is raised (not implemented yet). It will allow a speedier parser and more precise informations. BUG : When loading a document from a file, now correctly releases the file data. BUG : Solved a few XmlReader uninitialized variables, that could make the stream parser crash or returns strange results. git-svn-id: svn://localhost/gambas/trunk@4737 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-05-17 22:49:54 +02:00
GB_DECLARE("XmlNode", sizeof(CNode)), GB_NOT_CREATABLE(),
GB_METHOD("_new", NULL, CNode_new, ""),
GB_METHOD("_free", NULL, CNode_free, ""),
GB_CONSTANT("ElementNode", "i", NODE_ELEMENT),
GB_CONSTANT("TextNode", "i", NODE_TEXT),
GB_CONSTANT("CommentNode", "i", NODE_COMMENT),
GB_CONSTANT("CDATASectionNode", "i", NODE_CDATA),
[GB.XML] * NEW : Added a new property "State" to XmlExplorer and XmlReader, that allows to know the reader state, without knowing Read() return value. * NEW : When enumerating XmlReader.Node.Attributes, XmlReader.Node represents the current attribute. * NEW : Added an new method Open() that loads an HtmlDocument from a file and defines it as the document to read. * NEW : The Attributes property has now moved from XmlElement to XmlNode. XmlNode.Attributes returns Null if the node isn't an element. * NEW : Then enumeration of XmlNode.Attributes now returns an .XmlElementAttribute instead of a string. * NEW : The XmlNode.Attribute constant is not obsolete anymore. * NEW : Two consecutives whitespaces are now ignored (only one is preserved). * NEW : When parsing a file, line-breaks and tabulations are replaced by spaces. * BUG : XmlExplorer flags are now correctly initialized. * BUG : Added an Eof property on XmlExplorer, that was missing. * BUG : Calling XmlExplorer.Read() after Eof just returns XmlReaderNodeType.Eof, not more. * BUG : Calling XmlNode.Next() when the node hasn't got any brother after him doesn't crash anymore, it just returns Null. * BUG : Calling XmlElement.NextSibling() when the node hasn't got any element brother after him doesn't crash anymore, it just returns Null. * BUG : By default, XmlReader correctly stops when reading the end of an element. * BUG : XmlExplorer now correctly initializes and releases itself. * BUG : XmlExplorer now correctly supports its read flags. * OPT : Solved a memory leak when releasing a XmlReader. * OPT : When setting text content to a XmlNode, the string is not duplicated anymore. * OPT : When testing if characters are whitespaces or names characters while parsing texts, puts the temporary variable into registers instead of memory. git-svn-id: svn://localhost/gambas/trunk@4669 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2012-04-25 01:47:14 +02:00
GB_CONSTANT("AttributeNode", "i", NODE_ATTRIBUTE),
GB_PROPERTY_READ("Type", "i", CNode_type),
GB_PROPERTY_READ("IsElement", "b", CNode_isElement),
GB_PROPERTY_READ("IsText", "b", CNode_isText),
GB_PROPERTY_READ("IsComment", "b", CNode_isComment),
GB_PROPERTY_READ("IsCDATA", "b", CNode_isCDATA),
GB_PROPERTY_READ("Element", "XmlElement", CNode_element),
GB_PROPERTY_READ("OwnerDocument", "XmlDocument", CNode_ownerDocument),
GB_PROPERTY_READ("ChildNodes", "XmlNode[]", CNode_childNodes),
GB_PROPERTY_READ("Children", "XmlNode[]", CNode_childNodes),
GB_PROPERTY_READ("Parent", "XmlElement", CNode_parent),
GB_PROPERTY_READ("Previous", "XmlNode", CNode_previous),
GB_PROPERTY_READ("Next", "XmlNode", CNode_next),
GB_PROPERTY_READ("PreviousSibling", "XmlNode", CNode_previous),
GB_PROPERTY_READ("NextSibling", "XmlNode", CNode_next),
GB_METHOD("ToString", "s", CNode_tostring, "[(Indent)b]"),
GB_METHOD("GetUserData", "v", CNode_getUserData, "(Key)s"),
GB_METHOD("SetUserData", NULL, CNode_setUserData, "(Key)s(Value)v"),
GB_PROPERTY("TextContent", "s", CNode_textContent),
GB_PROPERTY("Value", "s", CNode_textContent),
GB_PROPERTY("Name", "s", CNode_name),
GB_STATIC_METHOD("Serialize", "s", CNode_escapeContent, "(Data)s"),
GB_STATIC_METHOD("Deserialize", "s", CNode_unEscapeContent, "(Data)s"),
GB_METHOD("NewElement", NULL, CNode_newElement, "(Name)s[(Value)s]"),
GB_METHOD("NewAttribute", NULL, CNode_setAttribute, "(Name)s(Value)s"),
GB_PROPERTY_SELF("Attributes", ".XmlElementAttributes"),
GB_END_DECLARE
};