XMLNode is the in memory representation of an XML node in the XMLStorage library. More...


Classes | |
| class | Children |
| Children contains the list of immediate child nodes. More... | |
Public Types | |
| enum | WRITE_MODE { FORMAT_SMART, FORMAT_ORIGINAL, FORMAT_PRETTY } |
Public Member Functions | |
| XMLNode (string name) | |
| XMLNode (string name, string leading) | |
| XMLNode (XMLNode other) | |
| override string | getName () |
| override string | ToString () |
| void | clear () |
| void | assign (XMLNode other) |
| void | addChild (XMLNode child) |
| add a new child node | |
| override string | get (string attrName) |
| read only access to an attribute | |
| override string | get (string attrName, string def) |
| read only access to an attribute with default value | |
| void | put (string attrName, string value) |
| Write access to an attribute. | |
| string | getSubattrib (string nodeName, string attrName) |
| convenient value access in children node | |
| string | getSubattrib (string nodeName, string attrName, int n) |
| void | putSubattrib (string nodeName, string attrName, string value) |
| convenient storage of distinct values in children node | |
| void | putSubattrib (string nodeName, string attrName, string value, int n) |
| Children | getChildren () |
| override string | getContent () |
| void | setContent (string s) |
| void | setContent (string s, bool cdata) |
| virtual void | write (TextWriter w) |
| virtual void | write (TextWriter w, WRITE_MODE mode) |
| void | write (TextWriter w, WRITE_MODE mode, int indent) |
| Write node with children tree. | |
| XMLNode | getFirstChild () |
| XMLNode | find (string nodeName) |
| Find a children node by name. | |
| XMLNode | find (string nodeName, int n) |
| Find the n'th children node with tag nodeName. | |
| XMLNode | find (string nodeName, string attrName, string attrValue) |
| Search matching child node identified by key name and an attribute value. | |
| XMLNode | find (string nodeName, string attrName, string attrValue, int n) |
| Search matching child node identified by key name and an attribute value. | |
| XMLNode | findRelative (XPath xpath) |
| XPath find function. | |
| AbstractXMLNode | createRelative (XPath xpath) |
| relative XPath create function | |
| XMLInt | getInt (string attrName) |
| XMLInt | getInt (string attrName, int def) |
| XMLDecimal | getNumber (string attrName) |
| XMLDecimal | getNumber (string attrName, decimal def) |
| XMLBool | getBool (string attrName) |
| XMLBool | getBool (string attrName, bool def) |
| XMLString | getString (string attrName) |
| XMLString | getString (string attrName, string def) |
| void | setAttributes (XmlReader reader) |
| bool | hasAttributes () |
Public Attributes | |
| string | _leading = "" |
| string | _endLeading = "" |
| string | _trailing = "" |
Static Public Attributes | |
| static string | XML_INDENT_SPACE = " " |
Protected Member Functions | |
| void | writeWorker (TextWriter w, int indent) |
| Write node with children tree using original white space. | |
| void | prettyWriteWorker (TextWriter w, int indent) |
| void | smartWriteWorker (TextWriter w, int indent) |
Protected Attributes | |
| string | _name |
| Children | _children = new Children() |
| Dictionary< string, string > | _attributes = new Dictionary<string, string>() |
XMLNode is the in memory representation of an XML node in the XMLStorage library.
Definition at line 49 of file XMLNode.cs.
Definition at line 239 of file XMLNode.cs.
{
//TODO FORMAT_PLAIN, /// Write XML without any white space
FORMAT_SMART, /// preserve original white space and comments if present; pretty print otherwise
FORMAT_ORIGINAL, /// Write XML stream preserving original white space and comments
FORMAT_PRETTY /// pretty print node to stream without preserving original white space
};
| XMLStorage::XMLNode::XMLNode | ( | string | name ) | [inline] |
Definition at line 51 of file XMLNode.cs.
References _name.
Referenced by XMLStorage::XMLNode::Children::assign(), createRelative(), and putSubattrib().
{
_name = name;
}
| XMLStorage::XMLNode::XMLNode | ( | string | name, |
| string | leading | ||
| ) | [inline] |
| XMLStorage::XMLNode::XMLNode | ( | XMLNode | other ) | [inline] |
Definition at line 62 of file XMLNode.cs.
References assign().
{
assign(other);
}

| void XMLStorage::XMLNode::addChild | ( | XMLNode | child ) | [inline] |
add a new child node
Definition at line 135 of file XMLNode.cs.
References _children.
Referenced by XMLStorage::XMLPos::addDown(), createRelative(), and putSubattrib().
{
_children.AddLast(child);
}
| void XMLStorage::XMLNode::assign | ( | XMLNode | other ) | [inline] |
Definition at line 122 of file XMLNode.cs.
References XMLStorage::AbstractXMLNode::_attributes, _children, XMLStorage::AbstractXMLNode::_content, _endLeading, _leading, _trailing, and XMLStorage::XMLNode::Children::assign().
Referenced by XMLNode().
{
_children.assign(other._children);
_attributes = (Dictionary<string, string>) other._attributes;//@@ .clone();
_leading = other._leading;
_content = other._content;
_endLeading = other._endLeading;
_trailing = other._trailing;
}

| void XMLStorage::XMLNode::clear | ( | ) | [inline] |
Definition at line 109 of file XMLNode.cs.
References XMLStorage::AbstractXMLNode::_attributes, _children, XMLStorage::AbstractXMLNode::_content, _endLeading, _leading, _name, and _trailing.
Referenced by XMLStorage::XMLNode::Children::clear().
{
_leading = "";
_content = "";
_endLeading = "";
_trailing = "";
_attributes.Clear();
_children.Clear();
_name = "";
}
| AbstractXMLNode XMLStorage::XMLNode::createRelative | ( | XPath | xpath ) | [inline] |
relative XPath create function
Definition at line 363 of file XMLNode.cs.
References XMLStorage::XPathElement::_childName, XMLStorage::XPathElement::_mAttrAndAttr, addChild(), XMLStorage::XPathElement::find(), put(), and XMLNode().
{
XMLNode node = this;
foreach(XPathElement elem in xpath) {
XMLNode child = elem.find(node);
if (child == null) {
child = new XMLNode(elem._childName);
node.addChild(child);
foreach(KeyValuePair<string, string> it in elem._mAttrAndAttr)
put(it.Key, it.Value);
}
node = child;
}
return node;
}

| XMLNode XMLStorage::XMLNode::find | ( | string | nodeName ) | [inline] |
Find a children node by name.
| nodeName |
Definition at line 287 of file XMLNode.cs.
References _children, and _name.
Referenced by getSubattrib(), and putSubattrib().
| XMLNode XMLStorage::XMLNode::find | ( | string | nodeName, |
| int | n | ||
| ) | [inline] |
| XMLNode XMLStorage::XMLNode::find | ( | string | nodeName, |
| string | attrName, | ||
| string | attrValue | ||
| ) | [inline] |
Search matching child node identified by key name and an attribute value.
| nodeName | |
| attrName | |
| attrValue |
Definition at line 319 of file XMLNode.cs.
References _children, _name, and get().
{
foreach(XMLNode child in _children)
if (child._name==nodeName && child.get(attrName)==attrValue)
return child;
return null;
}

| XMLNode XMLStorage::XMLNode::find | ( | string | nodeName, |
| string | attrName, | ||
| string | attrValue, | ||
| int | n | ||
| ) | [inline] |
Search matching child node identified by key name and an attribute value.
| nodeName | |
| attrName | |
| attrValue | |
| n |
Definition at line 336 of file XMLNode.cs.
References _children, _name, and get().
{
foreach(XMLNode node in _children)
if (node._name==nodeName && node.get(attrName)==attrValue)
if (n-- == 0)
return node;
return null;
}

XPath find function.
Definition at line 347 of file XMLNode.cs.
References XMLStorage::XPathElement::find().
Referenced by XMLStorage::XMLPos::go().
{
XMLNode node = this;
foreach(XPathElement xelem in xpath)
{
node = xelem.find(node);
if (node == null)
break;
}
return node;
}

| override string XMLStorage::XMLNode::get | ( | string | attrName ) | [inline, virtual] |
read only access to an attribute
Implements XMLStorage::AbstractXMLNode.
Definition at line 141 of file XMLNode.cs.
References XMLStorage::AbstractXMLNode::_attributes.
Referenced by XMLStorage::XMLBoolRef::boolValue(), XMLStorage::XMLNumberRef::decimalValue(), XMLStorage::XMLDoubleRef::doubleValue(), find(), XMLStorage::XMLPos::get(), XMLStorage::XMLStringRef::init(), XMLStorage::XMLIntRef::init(), XMLStorage::XMLDoubleRef::init(), XMLStorage::XMLNumberRef::init(), XMLStorage::XMLBoolRef::init(), XMLStorage::XMLIntRef::intValue(), and XMLStorage::XMLStringRef::ToString().
{
string found;
if (_attributes.TryGetValue(attrName, out found))
return found;
else
return "";
}
| override string XMLStorage::XMLNode::get | ( | string | attrName, |
| string | def | ||
| ) | [inline, virtual] |
read only access to an attribute with default value
Implements XMLStorage::AbstractXMLNode.
Definition at line 152 of file XMLNode.cs.
References XMLStorage::AbstractXMLNode::_attributes.
{
string found;
if (_attributes.TryGetValue(attrName, out found))
return found;
else
return def;
}
| XMLBool XMLStorage::AbstractXMLNode::getBool | ( | string | attrName ) | [inline, inherited] |
Definition at line 85 of file AbstractXMLNode.cs.
{
return new XMLBool(this, attrName);
}
| XMLBool XMLStorage::AbstractXMLNode::getBool | ( | string | attrName, |
| bool | def | ||
| ) | [inline, inherited] |
Definition at line 89 of file AbstractXMLNode.cs.
{
return new XMLBool(this, attrName, def);
}
| Children XMLStorage::XMLNode::getChildren | ( | ) | [inline] |
Definition at line 219 of file XMLNode.cs.
References _children.
Referenced by XMLStorage::XMLDocReader::endElement(), XMLStorage::XMLChildrenFilter::filterChildren(), XMLStorage::XPathElement::find(), XMLStorage::XMLDocReader::read(), and XMLStorage::XMLDocReader::startElement().
{
return _children;
}
| override string XMLStorage::XMLNode::getContent | ( | ) | [inline, virtual] |
Implements XMLStorage::AbstractXMLNode.
Definition at line 224 of file XMLNode.cs.
References XMLStorage::AbstractXMLNode::_content, and XMLStorage::XMLHelper::decodeXMLString().
Referenced by XMLStorage::XMLPos::getContent().
{
return XMLHelper.decodeXMLString(_content);
}

| XMLNode XMLStorage::XMLNode::getFirstChild | ( | ) | [inline] |
Definition at line 274 of file XMLNode.cs.
References _children.
Referenced by XMLStorage::XMLPos::goDown().
| XMLInt XMLStorage::AbstractXMLNode::getInt | ( | string | attrName, |
| int | def | ||
| ) | [inline, inherited] |
Definition at line 71 of file AbstractXMLNode.cs.
{
return new XMLInt(this, attrName, def);
}
| XMLInt XMLStorage::AbstractXMLNode::getInt | ( | string | attrName ) | [inline, inherited] |
Definition at line 67 of file AbstractXMLNode.cs.
{
return new XMLInt(this, attrName);
}
| override string XMLStorage::XMLNode::getName | ( | ) | [inline, virtual] |
Implements XMLStorage::AbstractXMLNode.
Definition at line 69 of file XMLNode.cs.
References _name.
Referenced by XMLStorage::XMLChildrenFilter::filterChildren().
{
return _name;
}
| XMLDecimal XMLStorage::AbstractXMLNode::getNumber | ( | string | attrName ) | [inline, inherited] |
Definition at line 76 of file AbstractXMLNode.cs.
{
return new XMLDecimal(this, attrName);
}
| XMLDecimal XMLStorage::AbstractXMLNode::getNumber | ( | string | attrName, |
| decimal | def | ||
| ) | [inline, inherited] |
Definition at line 80 of file AbstractXMLNode.cs.
{
return new XMLDecimal(this, attrName, def);
}
| XMLString XMLStorage::AbstractXMLNode::getString | ( | string | attrName ) | [inline, inherited] |
Definition at line 94 of file AbstractXMLNode.cs.
{
return new XMLString(this, attrName);
}
| XMLString XMLStorage::AbstractXMLNode::getString | ( | string | attrName, |
| string | def | ||
| ) | [inline, inherited] |
Definition at line 98 of file AbstractXMLNode.cs.
{
return new XMLString(this, attrName, def);
}
| string XMLStorage::XMLNode::getSubattrib | ( | string | nodeName, |
| string | attrName | ||
| ) | [inline] |
convenient value access in children node
Definition at line 174 of file XMLNode.cs.
References find(), and XMLStorage::AbstractXMLNode::get().
{
AbstractXMLNode node = find(nodeName);
if (node != null)
return node.get(attrName);
else
return "";
}

| string XMLStorage::XMLNode::getSubattrib | ( | string | nodeName, |
| string | attrName, | ||
| int | n | ||
| ) | [inline] |
Definition at line 184 of file XMLNode.cs.
References find(), and XMLStorage::AbstractXMLNode::get().
{
AbstractXMLNode node = find(nodeName, n);
if (node != null)
return node.get(attrName);
else
return "";
}

| bool XMLStorage::AbstractXMLNode::hasAttributes | ( | ) | [inline, inherited] |
Definition at line 117 of file AbstractXMLNode.cs.
References XMLStorage::AbstractXMLNode::_attributes.
Referenced by XMLStorage::XMLStreamReader::handlePendingEndElement().
{
return _attributes.Count > 0;
}
| void XMLStorage::XMLNode::prettyWriteWorker | ( | TextWriter | w, |
| int | indent | ||
| ) | [inline, protected] |
Definition at line 428 of file XMLNode.cs.
References XMLStorage::AbstractXMLNode::_attributes, _children, XMLStorage::AbstractXMLNode::_content, _name, XMLStorage::XMLHelper::encodeXMLString(), prettyWriteWorker(), and XML_INDENT_SPACE.
Referenced by prettyWriteWorker(), and write().
{
for(int i=indent; i-->0; )
w.Write(XML_INDENT_SPACE);
w.Write('<');
w.Write(XMLHelper.encodeXMLString(_name));
foreach(KeyValuePair<string,string> it in _attributes) {
string attrValue = it.Value;
if (attrValue != null) {
w.Write(' ');
w.Write(XMLHelper.encodeXMLString(it.Key));
w.Write("=\"");
w.Write(XMLHelper.encodeXMLString(attrValue));
w.Write("\"");
}
}
if (_children.Count>0 || _content.Length>0) {
w.Write(">\n");
foreach(XMLNode child in _children)
child.prettyWriteWorker(w, indent+1);
for(int i=indent; i-->0; )
w.Write(XML_INDENT_SPACE);
w.Write("</");
w.Write(XMLHelper.encodeXMLString(_name));
w.Write(">\n");
} else
w.Write("/>\n");
}

| void XMLStorage::XMLNode::put | ( | string | attrName, |
| string | value | ||
| ) | [inline] |
Write access to an attribute.
Definition at line 163 of file XMLNode.cs.
References XMLStorage::AbstractXMLNode::_attributes.
Referenced by XMLStorage::XMLStringRef::assign(), XMLStorage::XMLIntRef::assign(), XMLStorage::XMLDoubleRef::assign(), XMLStorage::XMLNumberRef::assign(), XMLStorage::XMLBoolRef::assign(), createRelative(), XMLStorage::XMLPos::put(), putSubattrib(), and XMLStorage::XMLPos::smartCreate().
{
try {
_attributes.Add(attrName, value);
} catch(ArgumentException) {
_attributes.Remove(attrName);
_attributes.Add(attrName, value);
}
}
| void XMLStorage::XMLNode::putSubattrib | ( | string | nodeName, |
| string | attrName, | ||
| string | value | ||
| ) | [inline] |
convenient storage of distinct values in children node
Definition at line 195 of file XMLNode.cs.
References addChild(), find(), put(), and XMLNode().
Referenced by XMLStorage::XMLPos::putSubattrib().
{
XMLNode node = find(nodeName);
if (node == null) {
node = new XMLNode(nodeName);
addChild(node);
}
node.put(attrName, value);
}

| void XMLStorage::XMLNode::putSubattrib | ( | string | nodeName, |
| string | attrName, | ||
| string | value, | ||
| int | n | ||
| ) | [inline] |
Definition at line 207 of file XMLNode.cs.
References addChild(), find(), put(), and XMLNode().
{
XMLNode node = find(nodeName, n);
if (node == null) {
node = new XMLNode(nodeName);
addChild(node);
}
node.put(attrName, value);
}

| void XMLStorage::AbstractXMLNode::setAttributes | ( | XmlReader | reader ) | [inline, inherited] |
Definition at line 103 of file AbstractXMLNode.cs.
References XMLStorage::AbstractXMLNode::_attributes.
Referenced by XMLStorage::XMLStreamReader::startElement(), and XMLStorage::XMLDocReader::startElement().
{
while(reader.MoveToNextAttribute()) {
string attrNS = reader.NamespaceURI;
string attrName = reader.Name;
string attrValue = reader.Value;
if (attrNS.Length > 0)
attrName = attrNS + ":" + attrName;
_attributes.Add(attrName, attrValue);
}
}
| void XMLStorage::XMLNode::setContent | ( | string | s, |
| bool | cdata | ||
| ) | [inline] |
Definition at line 234 of file XMLNode.cs.
References XMLStorage::AbstractXMLNode::_content, and XMLStorage::XMLHelper::encodeXMLString().
{
_content = XMLHelper.encodeXMLString(s, cdata);
}

| void XMLStorage::XMLNode::setContent | ( | string | s ) | [inline] |
Definition at line 229 of file XMLNode.cs.
Referenced by XMLStorage::XMLPos::setContent().
{
setContent(s, false);
}
| void XMLStorage::XMLNode::smartWriteWorker | ( | TextWriter | w, |
| int | indent | ||
| ) | [inline, protected] |
Definition at line 464 of file XMLNode.cs.
References XMLStorage::AbstractXMLNode::_attributes, _children, XMLStorage::AbstractXMLNode::_content, _endLeading, _leading, _name, _trailing, XMLStorage::XMLHelper::encodeXMLString(), and XML_INDENT_SPACE.
Referenced by write().
{
if (_leading.Length == 0)
for(int i=indent; i-->0; )
w.Write(XML_INDENT_SPACE);
else
w.Write(_leading);
w.Write('<');
w.Write(XMLHelper.encodeXMLString(_name));
foreach(KeyValuePair<string,string> it in _attributes) {
string attrValue = it.Value;
if (attrValue != null) {
w.Write(' ');
w.Write(XMLHelper.encodeXMLString(it.Key));
w.Write("=\"");
w.Write(XMLHelper.encodeXMLString(attrValue));
w.Write("\"");
}
}
if (_children.Count==0 && _content.Length==0)
w.Write("/>");
else {
w.Write('>');
if (_content.Length == 0)
w.Write('\n');
else
w.Write(_content);
LinkedListNode<XMLNode> it = _children.First;
if (it != null) {
for( ; it != null; it = it.Next )
it.Value.smartWriteWorker( w, indent + 1 );
if (_endLeading.Length == 0)
for(int i=indent; i-->0; )
w.Write(XML_INDENT_SPACE);
else
w.Write(_endLeading);
} else
w.Write(_endLeading);
w.Write("</");
w.Write(XMLHelper.encodeXMLString(_name));
w.Write('>');
}
if (_trailing.Length == 0)
w.Write('\n');
else
w.Write(_trailing);
}

| override string XMLStorage::XMLNode::ToString | ( | ) | [inline, virtual] |
Implements XMLStorage::AbstractXMLNode.
Definition at line 74 of file XMLNode.cs.
References _name.
Referenced by XMLStorage::XMLPos::ToString().
{
return _name;
}
| void XMLStorage::XMLNode::write | ( | TextWriter | w, |
| WRITE_MODE | mode, | ||
| int | indent | ||
| ) | [inline] |
Write node with children tree.
Definition at line 257 of file XMLNode.cs.
References prettyWriteWorker(), smartWriteWorker(), and writeWorker().
{
switch(mode) {
case WRITE_MODE.FORMAT_PRETTY:
prettyWriteWorker(w, indent);
break;
case WRITE_MODE.FORMAT_ORIGINAL:
writeWorker(w, indent);
break;
default: // FORMAT_SMART
smartWriteWorker(w, indent);
break;
}
}

| virtual void XMLStorage::XMLNode::write | ( | TextWriter | w, |
| WRITE_MODE | mode | ||
| ) | [inline, virtual] |
Reimplemented in XMLStorage::XMLDoc.
Definition at line 251 of file XMLNode.cs.
References write().
{
write(w, mode, 0);
}

| virtual void XMLStorage::XMLNode::write | ( | TextWriter | w ) | [inline, virtual] |
Reimplemented in XMLStorage::XMLDoc.
Definition at line 246 of file XMLNode.cs.
Referenced by write().
{
write(w, WRITE_MODE.FORMAT_SMART, 0);
}
| void XMLStorage::XMLNode::writeWorker | ( | TextWriter | w, |
| int | indent | ||
| ) | [inline, protected] |
Write node with children tree using original white space.
| o | |
| indent |
Definition at line 390 of file XMLNode.cs.
References XMLStorage::AbstractXMLNode::_attributes, _children, XMLStorage::AbstractXMLNode::_content, _endLeading, _leading, _name, _trailing, XMLStorage::XMLHelper::encodeXMLString(), and writeWorker().
Referenced by write(), and writeWorker().
{
w.Write(_leading);
w.Write('<');
w.Write(XMLHelper.encodeXMLString(_name));
foreach(KeyValuePair<string,string> it in _attributes) {
string attrValue = it.Value;
if (attrValue != null) {
w.Write(' ');
w.Write(XMLHelper.encodeXMLString(it.Key));
w.Write("=\"");
w.Write(XMLHelper.encodeXMLString(attrValue));
w.Write("\"");
}
}
if (_children.Count>0 || _content.Length>0) {
w.Write('>');
w.Write(_content);
foreach(XMLNode child in _children)
child.writeWorker(w, indent+1);
w.Write(_endLeading);
w.Write("</");
w.Write(XMLHelper.encodeXMLString(_name));
w.Write('>');
} else
w.Write("/>");
w.Write(_trailing);
}

Dictionary<string, string> XMLStorage::AbstractXMLNode::_attributes = new Dictionary<string, string>() [protected, inherited] |
Definition at line 52 of file AbstractXMLNode.cs.
Referenced by XMLStorage::XMLStreamNode::assign(), assign(), clear(), XMLStorage::XMLStreamNode::get(), get(), XMLStorage::AbstractXMLNode::hasAttributes(), prettyWriteWorker(), put(), XMLStorage::AbstractXMLNode::setAttributes(), smartWriteWorker(), and writeWorker().
Children XMLStorage::XMLNode::_children = new Children() [protected] |
Definition at line 103 of file XMLNode.cs.
Referenced by addChild(), assign(), clear(), find(), getChildren(), getFirstChild(), prettyWriteWorker(), smartWriteWorker(), XMLStorage::XMLDoc::write(), and writeWorker().
| string XMLStorage::XMLNode::_endLeading = "" |
Definition at line 106 of file XMLNode.cs.
Referenced by assign(), clear(), XMLStorage::XMLDocReader::endElement(), smartWriteWorker(), and writeWorker().
| string XMLStorage::XMLNode::_leading = "" |
Definition at line 105 of file XMLNode.cs.
Referenced by assign(), clear(), smartWriteWorker(), writeWorker(), and XMLNode().
string XMLStorage::XMLNode::_name [protected] |
Definition at line 67 of file XMLNode.cs.
Referenced by clear(), find(), getName(), prettyWriteWorker(), smartWriteWorker(), ToString(), writeWorker(), and XMLNode().
| string XMLStorage::XMLNode::_trailing = "" |
Definition at line 107 of file XMLNode.cs.
Referenced by assign(), clear(), XMLStorage::XMLDocReader::read(), smartWriteWorker(), XMLStorage::XMLDocReader::startElement(), and writeWorker().
string XMLStorage::XMLNode::XML_INDENT_SPACE = " " [static] |
Definition at line 426 of file XMLNode.cs.
Referenced by prettyWriteWorker(), smartWriteWorker(), XMLStorage::XMLStreamWriter::writePost(), and XMLStorage::XMLStreamWriter::writePre().
1.7.2