in memory representation of an XML node More...


Classes | |
| class | Children |
| internal children node list More... | |
Public Types | |
| typedef char[][char[]] | AttributeMap |
| map of XML node attributes | |
Public Member Functions | |
| this (in char[] name) | |
| this (in char[] name, char[] leading) | |
| this (XMLNode other) | |
| void | clear () |
| XMLNode | assign (XMLNode other) |
| void | add_child (XMLNode child) |
| add a new child node | |
| void | put (in char[] attr_name, in char[] value) |
| write access to an attribute | |
| char[] | opIndex (in char[] attr_name) |
| index operator read access to an attribute | |
| void | opIndexAssign (in char[] attr_name, in char[] value) |
| index operator write access to an attribute | |
| char[] | get (in char[] attr_name, in char[] def="") |
| read only access to an attribute | |
| char *[] | get_ref (in char[] attr_name, in char[] def="") |
| write access to an attribute | |
| char[] | subvalue (in char[] name, char[] attr_name, int n=0) |
| convenient value access in children node | |
| char *[] | subvalue_ref (in char[] name, char[] attr_name, int n=0) |
| convenient value access in children node | |
| char[] | put_subvalue (in char[] name, char[] attr_name, int n=0) |
| convenient storage of distinct values in children node | |
| Children | get_children () |
| AttributeMap | get_attributes () |
| char[] | get_content () |
| void | set_content (in char[] s, bool cdata=false) |
| version (XMLNODE_LOCATION) | |
| void | write (Stream o, XMLFormat format, WRITE_MODE mode=WRITE_MODE.FORMAT_SMART, int indent=0) |
| write node with children tree to output stream | |
Public Attributes | |
| char[] | _name |
Protected Member Functions | |
| version (XMLNODE_LOCATION) | |
| XMLNode | get_first_child () |
| XMLNode | find (in char[] name, int n=0) |
| XMLNode | find (in char[] name, char[] attr_name, char[] attr_value, int n=0) |
| XMLNode | find_relative (in char[] path) |
| XPath find function. | |
| XMLNode | create_relative (in char[] path) |
| relative XPath create function | |
| void | write_worker (Stream o) |
| write node with children tree to output stream using original white space | |
| void | plain_write_worker (Stream o) |
| print node without any white space | |
| void | pretty_write_worker (Stream o, XMLFormat format, int indent) |
| pretty print node with children tree to output stream | |
| void | smart_write_worker (Stream o, XMLFormat format, int indent) |
| write node with children tree to output stream using smart formating | |
| XMLNode | get_child_relative (inout char[] path, bool create) |
Protected Attributes | |
| Children | _children |
| AttributeMap | _attributes |
| char[] | _leading |
| char[] | _content |
| char[] | _end_leading |
| char[] | _trailing |
in memory representation of an XML node
Definition at line 499 of file xmlstorage.d.
| typedef char [][char[]] xmlstorage::XMLNode::AttributeMap |
map of XML node attributes
Definition at line 506 of file xmlstorage.d.
| xmlstorage::XMLNode::this | ( | in char[] | name ) | [inline] |
Reimplemented in xmlstorage::XMLDoc, and xmlstorage::XMLMessage.
Definition at line 521 of file xmlstorage.d.
| xmlstorage::XMLNode::this | ( | in char[] | name, |
| char[] | leading | ||
| ) | [inline] |
Definition at line 528 of file xmlstorage.d.
{
this(name);
_leading = leading;
}
| xmlstorage::XMLNode::this | ( | XMLNode | other ) | [inline] |
Definition at line 535 of file xmlstorage.d.
References xmlstorage::version().
{
this(other._name);
_attributes = other._attributes;
_leading = other._leading;
_content = other._content;
_end_leading = other._end_leading;
_trailing = other._trailing;
version(XMLNODE_LOCATION) {
_location = other._location;
}
foreach(node; other._children)
_children.push_back(new XMLNode(node));
}

| void xmlstorage::XMLNode::add_child | ( | XMLNode | child ) | [inline] |
Definition at line 572 of file xmlstorage.d.
References _attributes, _children, _content, _end_leading, _leading, _trailing, and assign().
Referenced by assign().
{
_children.assign(other._children);
_attributes = other._attributes;
_leading = other._leading;
_content = other._content;
_end_leading = other._end_leading;
_trailing = other._trailing;
return this;
}


| void xmlstorage::XMLNode::clear | ( | ) | [inline] |
Definition at line 559 of file xmlstorage.d.
{
_leading.length = 0;
_content.length = 0;
_end_leading.length = 0;
_trailing.length = 0;
_attributes = null;
_children.clear();
_name.length = 0;
}
| XMLNode xmlstorage::XMLNode::create_relative | ( | in char[] | path ) | [inline, protected] |
relative XPath create function
Definition at line 777 of file xmlstorage.d.
References get_child_relative().
Referenced by xmlstorage::XMLPos::create_relative().
{
XMLNode node = this;
// parse relative path
while(path.length) {
node = node.get_child_relative(path, true);
if (*path == '/')
path = path[1..length];
}
return node;
}


| XMLNode xmlstorage::XMLNode::find | ( | in char[] | name, |
| char[] | attr_name, | ||
| char[] | attr_value, | ||
| int | n = 0 |
||
| ) | [inline, protected] |
Definition at line 747 of file xmlstorage.d.
{
foreach(node; _children)
if (node._name==name && node.get(attr_name)==attr_value)
if (!n--)
return node;
return null;
}
| XMLNode xmlstorage::XMLNode::find | ( | in char[] | name, |
| int | n = 0 |
||
| ) | [inline, protected] |
Definition at line 737 of file xmlstorage.d.
Referenced by get_child_relative(), xmlstorage::XMLPos::go_down(), and xmlstorage::XMLPos::smart_create().
{
foreach(node; _children)
if (node._name == name)
if (!n--)
return node;
return null;
}

| XMLNode xmlstorage::XMLNode::find_relative | ( | in char[] | path ) | [inline, protected] |
XPath find function.
Definition at line 758 of file xmlstorage.d.
References get_child_relative().
Referenced by xmlstorage::XMLPos::go().
{
XMLNode node = this;
// parse relative path
while(path.length) {
node = node.get_child_relative(path, false);
if (!node)
return null;
if (*path == '/')
path = path[1..length];
}
return node;
}


| char [] xmlstorage::XMLNode::get | ( | in char[] | attr_name, |
| in char[] | def = "" |
||
| ) | [inline] |
read only access to an attribute
Definition at line 611 of file xmlstorage.d.
Referenced by xmlstorage::XMLPos::get(), put_subvalue(), and subvalue().
{
char[]* found = attr_name in _attributes;
if (found)
return *found;
else
return def;
}

| AttributeMap xmlstorage::XMLNode::get_attributes | ( | ) | [inline] |
Definition at line 676 of file xmlstorage.d.
{
return _attributes;
}
| XMLNode xmlstorage::XMLNode::get_child_relative | ( | inout char[] | path, |
| bool | create | ||
| ) | [inline, protected] |
Definition at line 928 of file xmlstorage.d.
References find(), and xmlstorage::unescape().
Referenced by create_relative(), and find_relative().
{
int slash_pos = .find(path, '/');
if (slash_pos == 0)
return null;
size_t l = slash_pos!=-1? slash_pos: path.length;
char[] comp = path[0 .. l];
path = path[l .. length];
// look for [n] and [@attr_name="attr_value"] expressions in path components
int bracket_pos = .find(comp, '[');
l = bracket_pos!=-1? bracket_pos: comp.length;
char[] child_name = comp[0 .. l];
char[] attr_name, attr_value;
int n = 0;
if (bracket_pos != -1) {
char[] expr = unescape(comp[bracket_pos..length], '[', ']');
n = atoi(expr); // read index number
if (n)
n = n - 1; // convert into zero based index
int at_pos = .find(expr, '@');
if (at_pos != -1) {
expr = expr[at_pos+1 .. length];
int equal_pos = .find(expr, '=');
// read attribute name and value
if (equal_pos != -1) {
attr_name = unescape(expr[0 .. equal_pos]);
attr_value = unescape(expr[equal_pos+1 .. length]);
}
}
}
XMLNode child;
if (!attr_name.length)
// search n.th child node with specified name
child = find(child_name, n);
else
// search n.th child node with specified name and matching attribute value
child = find(child_name, attr_name, attr_value, n);
if (!child && create) {
child = new XMLNode(child_name);
add_child(child);
if (attr_name.length)
this[attr_name] = attr_value;
}
return child;
}


| Children xmlstorage::XMLNode::get_children | ( | ) | [inline] |
Definition at line 671 of file xmlstorage.d.
{
return _children;
}
| char [] xmlstorage::XMLNode::get_content | ( | ) | [inline] |
Definition at line 681 of file xmlstorage.d.
References xmlstorage::DecodeXMLString().
{
return DecodeXMLString(_content);
}

| XMLNode xmlstorage::XMLNode::get_first_child | ( | ) | [inline, protected] |
Definition at line 729 of file xmlstorage.d.
Referenced by xmlstorage::XMLPos::go_down().

| char* [] xmlstorage::XMLNode::get_ref | ( | in char[] | attr_name, |
| in char[] | def = "" |
||
| ) | [inline] |
write access to an attribute
Definition at line 622 of file xmlstorage.d.
Referenced by subvalue_ref().
{
char[]* found = attr_name in _attributes;
if (found)
return found;
else {
_attributes[attr_name] = def;
return &_attributes[attr_name];
}
}

| char [] xmlstorage::XMLNode::opIndex | ( | in char[] | attr_name ) | [inline] |
index operator read access to an attribute
Definition at line 599 of file xmlstorage.d.
{
return _attributes[attr_name];
}
| void xmlstorage::XMLNode::opIndexAssign | ( | in char[] | attr_name, |
| in char[] | value | ||
| ) | [inline] |
index operator write access to an attribute
Definition at line 605 of file xmlstorage.d.
{
_attributes[attr_name] = value;
}
| void xmlstorage::XMLNode::plain_write_worker | ( | Stream | o ) | [inline, protected] |
print node without any white space
Definition at line 814 of file xmlstorage.d.
References xmlstorage::EncodeXMLString().
{
o.writeString('<' ~ EncodeXMLString(_name));
foreach(key,value; _attributes)
o.writeString(' ' ~ EncodeXMLString(key) ~ "=\"" ~ EncodeXMLString(value) ~ "\"");
// strip leading white space from content
char[] content = _content;
while(content.length && isspace(cast(dchar)*content)) content = content[1 .. length];
if (!_children.empty() || content.length) {
o.writeString('>' ~ content);
foreach(child; _children)
child.plain_write_worker(o);
o.writeString("</" ~ EncodeXMLString(_name) ~ ">");
} else
o.writeString("/>");
}

| void xmlstorage::XMLNode::pretty_write_worker | ( | Stream | o, |
| XMLFormat | format, | ||
| int | indent | ||
| ) | [inline, protected] |
pretty print node with children tree to output stream
Definition at line 837 of file xmlstorage.d.
References xmlstorage::XMLFormat::_endl, xmlstorage::EncodeXMLString(), and xmlstorage::XML_INDENT_SPACE.
{
for(int i=indent; i--; )
o.writeString(XML_INDENT_SPACE);
o.writeString('<' ~ EncodeXMLString(_name));
foreach(key,value; _attributes)
o.writeString(' ' ~ EncodeXMLString(key) ~ "=\"" ~ EncodeXMLString(value) ~ "\"");
// strip leading white space from content
char[] content = _content;
while(content.length && isspace(cast(dchar)*content)) content = content[1 .. length];
if (!_children.empty() || content.length) {
o.writeString('>' ~ content);
if (!_children.empty())
o.writeString(format._endl);
foreach(child; _children)
child.pretty_write_worker(o, format, indent+1);
for(int i=indent; i--; )
o.writeString(XML_INDENT_SPACE);
o.writeString("</" ~ EncodeXMLString(_name) ~ '>' ~ format._endl);
} else
o.writeString("/>" ~ format._endl);
}

| void xmlstorage::XMLNode::put | ( | in char[] | attr_name, |
| in char[] | value | ||
| ) | [inline] |
write access to an attribute
Definition at line 593 of file xmlstorage.d.
Referenced by xmlstorage::XMLPos::smart_create().
{
_attributes[attr_name] = value;
}

| char [] xmlstorage::XMLNode::put_subvalue | ( | in char[] | name, |
| char[] | attr_name, | ||
| int | n = 0 |
||
| ) | [inline] |
convenient storage of distinct values in children node
Definition at line 659 of file xmlstorage.d.
References get().
{
XMLNode node = find(name, n);
if (!node) {
node = new XMLNode(name);
add_child(node);
}
return node.get(attr_name);
}

| void xmlstorage::XMLNode::set_content | ( | in char[] | s, |
| bool | cdata = false |
||
| ) | [inline] |
Definition at line 686 of file xmlstorage.d.
References xmlstorage::EncodeXMLString().
{
_content = EncodeXMLString(s, cdata);
}

| void xmlstorage::XMLNode::smart_write_worker | ( | Stream | o, |
| XMLFormat | format, | ||
| int | indent | ||
| ) | [inline, protected] |
write node with children tree to output stream using smart formating
Definition at line 869 of file xmlstorage.d.
References xmlstorage::XMLFormat::_endl, xmlstorage::EncodeXMLString(), and xmlstorage::XML_INDENT_SPACE.
{
// strip the first line feed from _leading
char[] leading = _leading;
while(leading.length && *leading=='\n')
leading = leading[1 .. length];
if (!leading.length)
for(int i=indent; i--; )
o.writeString(XML_INDENT_SPACE);
else
o.writeString(leading);
o.writeString('<' ~ EncodeXMLString(_name));
foreach(key,value; _attributes)
o.writeString(' ' ~ EncodeXMLString(key) ~ "=\"" ~ EncodeXMLString(value) ~ "\"");
// strip leading white space from content
char[] content = _content;
while(content.length && isspace(cast(dchar)*content)) content = content[1 .. length];
if (_children.empty() && !content.length)
o.writeString("/>");
else {
o.writeString(">");
if (!content.length)
o.writeString(format._endl);
else
o.writeString(content);
if (!_children.empty()) {
foreach(child; _children)
child.smart_write_worker(o, format, indent+1);
// strip the first line feed from _end_leading
char[] end_leading = _end_leading;
while(end_leading.length && *end_leading=='\n')
end_leading = end_leading[1 .. length];
if (!end_leading.length)
for(int i=indent; i--; )
o.writeString(XML_INDENT_SPACE);
else
o.writeString(end_leading);
} else
o.writeString(_end_leading);
o.writeString("</" ~ EncodeXMLString(_name) ~ '>');
}
if (!_trailing.length)
o.writeString(format._endl);
else
o.writeString(_trailing);
}

| char [] xmlstorage::XMLNode::subvalue | ( | in char[] | name, |
| char[] | attr_name, | ||
| int | n = 0 |
||
| ) | [inline] |
convenient value access in children node
Definition at line 635 of file xmlstorage.d.
References get().
{
XMLNode node = find(name, n);
if (node)
return node.get(attr_name);
else
return "";
}

| char* [] xmlstorage::XMLNode::subvalue_ref | ( | in char[] | name, |
| char[] | attr_name, | ||
| int | n = 0 |
||
| ) | [inline] |
convenient value access in children node
Definition at line 646 of file xmlstorage.d.
References get_ref().
{
XMLNode node = find(name, n);
if (node)
return node.get_ref(attr_name);
else {
_attributes[attr_name] = "";
return &_attributes[attr_name];
}
}

| xmlstorage::XMLNode::version | ( | XMLNODE_LOCATION | ) | [inline] |
Reimplemented in xmlstorage::XMLDoc.
Definition at line 691 of file xmlstorage.d.
{
XMLLocation get_location() {return _location;}
}
| xmlstorage::XMLNode::version | ( | XMLNODE_LOCATION | ) | [inline, protected] |
Reimplemented in xmlstorage::XMLDoc.
Definition at line 725 of file xmlstorage.d.
{
XMLLocation _location;
}
| void xmlstorage::XMLNode::write | ( | Stream | o, |
| XMLFormat | format, | ||
| WRITE_MODE | mode = WRITE_MODE.FORMAT_SMART, |
||
| int | indent = 0 |
||
| ) | [inline] |
write node with children tree to output stream
Definition at line 696 of file xmlstorage.d.
{
switch(mode) {
case WRITE_MODE.FORMAT_PLAIN:
plain_write_worker(o);
break;
case WRITE_MODE.FORMAT_PRETTY:
pretty_write_worker(o, format, indent);
break;
case WRITE_MODE.FORMAT_ORIGINAL:
write_worker(o);
break;
default: // WRITE_MODE.FORMAT_SMART
smart_write_worker(o, format, indent);
}
}
| void xmlstorage::XMLNode::write_worker | ( | Stream | o ) | [inline, protected] |
write node with children tree to output stream using original white space
Definition at line 793 of file xmlstorage.d.
References xmlstorage::EncodeXMLString(), and write_worker().
Referenced by write_worker().
{
o.writeString(_leading ~ '<' ~ EncodeXMLString(_name));
foreach(key,value; _attributes)
o.writeString(' ' ~ EncodeXMLString(key) ~ "=\"" ~ EncodeXMLString(value) ~ "\"");
if (!_children.empty() || _content.length) {
o.writeString('>' ~ _content);
foreach(child; _children)
child.write_worker(o);
o.writeString(_end_leading ~ "</" ~ EncodeXMLString(_name) ~ '>');
} else
o.writeString("/>");
o.writeString(_trailing);
}


AttributeMap xmlstorage::XMLNode::_attributes [protected] |
Definition at line 718 of file xmlstorage.d.
Referenced by assign(), and xmlstorage::XMLReaderBase::StartElementHandler().
Children xmlstorage::XMLNode::_children [protected] |
Definition at line 717 of file xmlstorage.d.
Referenced by assign().
char [] xmlstorage::XMLNode::_content [protected] |
Definition at line 721 of file xmlstorage.d.
Referenced by assign().
char [] xmlstorage::XMLNode::_end_leading [protected] |
Definition at line 722 of file xmlstorage.d.
Referenced by assign().
char [] xmlstorage::XMLNode::_leading [protected] |
Definition at line 720 of file xmlstorage.d.
Referenced by assign().
| char [] xmlstorage::XMLNode::_name |
Definition at line 503 of file xmlstorage.d.
char [] xmlstorage::XMLNode::_trailing [protected] |
Definition at line 723 of file xmlstorage.d.
Referenced by assign().
1.7.2