XMLDocReader is the XML file reader of XMLStorage. More...

Public Member Functions | |
| XMLDocReader (XMLNode node) | |
| void | read (TextReader reader, XmlReaderSettings xmlSettings=null) |
| read XML stream into XML tree below _pos | |
| void | startElement (string qName, XmlReader reader) |
| void | endElement (string qName) |
| void | characters (string text) |
| void | startCDATA () |
| void | endCDATA () |
| void | processingInstruction (string target, string data) |
| string | getInstructions () |
Private Attributes | |
| XMLPos | _pos |
| XmlReader | _parser |
| string | _content = "" |
| StringBuilder | _instructions = new StringBuilder() |
| int | _lastTag |
| bool | _inCDATASection = false |
| bool | _isContentCDATA = false |
Static Private Attributes | |
| static int | TAG_NONE = 0 |
| static int | TAG_START = 1 |
| static int | TAG_END = 2 |
XMLDocReader is the XML file reader of XMLStorage.
Definition at line 49 of file XMLDocReader.cs.
| XMLStorage::XMLDocReader::XMLDocReader | ( | XMLNode | node ) | [inline] |
| void XMLStorage::XMLDocReader::characters | ( | string | text ) | [inline] |
Definition at line 201 of file XMLDocReader.cs.
References _content, _inCDATASection, _isContentCDATA, and XMLStorage::XMLHelper::encodeXMLString().
Referenced by read().
{
// encode _content compatible to XMLNode.setContent()
_content += XMLHelper.encodeXMLString(text);
if (_inCDATASection)
_isContentCDATA = true;
}

| void XMLStorage::XMLDocReader::endCDATA | ( | ) | [inline] |
Definition at line 221 of file XMLDocReader.cs.
References _inCDATASection.
{
_inCDATASection = false;
}
| void XMLStorage::XMLDocReader::endElement | ( | string | qName ) | [inline] |
Definition at line 166 of file XMLDocReader.cs.
References _content, XMLStorage::XMLNode::_endLeading, _isContentCDATA, _lastTag, _pos, XMLStorage::XMLPos::back(), XMLStorage::XMLPos::cur(), XMLStorage::XMLNode::getChildren(), TAG_END, and TAG_START.
Referenced by read().
{
int i;
if (_isContentCDATA)
i = _content.Length;
else {
// search for content end leaving only whitespaces for leading
i = _content.Length;
for (; i>0; i--) {
char ch = _content[i-1];
if (!char.IsWhiteSpace(ch))
break;
}
}
if (i > 0)
if (_pos.cur().getChildren().Count == 0) // no children in current node?
_pos.cur()._content += _content.Substring(0, i);
else
if (_lastTag == TAG_START)
_pos.cur()._content += _content.Substring(0, i);
else
_pos.cur().getChildren().Last.Value._trailing += _content.Substring(0, i);
if (i < _content.Length)
_pos.cur()._endLeading = _content.Substring(i);
_pos.back();
_lastTag = TAG_END;
_content = "";
_isContentCDATA = false;
}

| string XMLStorage::XMLDocReader::getInstructions | ( | ) | [inline] |
Definition at line 232 of file XMLDocReader.cs.
References _instructions.
Referenced by XMLStorage::XMLDoc::read().
{
return _instructions.ToString();
}
| void XMLStorage::XMLDocReader::processingInstruction | ( | string | target, |
| string | data | ||
| ) | [inline] |
Definition at line 227 of file XMLDocReader.cs.
References _instructions.
Referenced by read().
{
_instructions.Append("<?").Append(target).Append(" ").Append(data).Append("?>");
}
| void XMLStorage::XMLDocReader::read | ( | TextReader | reader, |
| XmlReaderSettings | xmlSettings = null |
||
| ) | [inline] |
read XML stream into XML tree below _pos
Definition at line 58 of file XMLDocReader.cs.
References _content, _isContentCDATA, _parser, _pos, XMLStorage::XMLNode::_trailing, characters(), XMLStorage::XMLPos::cur(), endElement(), XMLStorage::XMLNode::getChildren(), processingInstruction(), and startElement().
Referenced by XMLStorage::XMLDoc::read().
{
// read XML data
_parser = XmlReader.Create(reader, xmlSettings);
XMLNode.Children children = _pos.cur().getChildren();
while(_parser.Read())
{
switch(_parser.NodeType)
{
case XmlNodeType.Element:
{
bool emptyElement = _parser.IsEmptyElement;
startElement(_parser.Name, _parser);
if (emptyElement)
endElement(_parser.Name);
}
break;
case XmlNodeType.EndElement:
endElement(_parser.Name);
break;
case XmlNodeType.Text:
characters(_parser.Value);
break;
case XmlNodeType.CDATA:
characters(_parser.Value);
break;
case XmlNodeType.Comment:
characters(_parser.Value);
break;
case XmlNodeType.XmlDeclaration:
break;
case XmlNodeType.ProcessingInstruction:
processingInstruction(_parser.Name, _parser.Value);
break;
case XmlNodeType.DocumentType:
break;
}
}
// process last data pieces
if (children.Count == 0)
_pos.cur()._trailing += _content;
else
children.Last.Value._trailing += _content;
_content = "";
_isContentCDATA = false;
}

| void XMLStorage::XMLDocReader::startCDATA | ( | ) | [inline] |
Definition at line 216 of file XMLDocReader.cs.
References _inCDATASection.
{
_inCDATASection = true;
}
| void XMLStorage::XMLDocReader::startElement | ( | string | qName, |
| XmlReader | reader | ||
| ) | [inline] |
Definition at line 129 of file XMLDocReader.cs.
References _content, _isContentCDATA, _lastTag, _pos, XMLStorage::XMLNode::_trailing, XMLStorage::XMLPos::addDown(), XMLStorage::XMLPos::cur(), XMLStorage::XMLNode::getChildren(), XMLStorage::AbstractXMLNode::setAttributes(), TAG_END, and TAG_START.
Referenced by read().
{
// search for content end leaving only whitespaces for _end_leading
int i = _content.Length;
for (; i>0; i--) {
char ch = _content[i-1];
if (!char.IsWhiteSpace(ch))
break;
}
if (i > 0)
if (_pos.cur().getChildren().Count == 0) { // no children in last node?
if (_lastTag == TAG_START)
_pos.cur()._content += _content.Substring(0, i);
else if (_lastTag == TAG_END)
_pos.cur()._trailing += _content.Substring(0, i);
// else TAG_NONE -> don't store white space in root node
} else
_pos.cur().getChildren().Last.Value._trailing += _content.Substring(0, i);
string leading = "";
if (i < _content.Length)
leading = _content.Substring(i);
XMLNode node = new XMLNode(qName, leading);
//XMLNode node = new XMLNode(XMLHelper.String_from_XML_Char(qName), leading);
_pos.addDown(node);
node.setAttributes(reader);
_lastTag = TAG_START;
_content = "";
_isContentCDATA = false;
}

string XMLStorage::XMLDocReader::_content = "" [private] |
Definition at line 120 of file XMLDocReader.cs.
Referenced by characters(), endElement(), read(), and startElement().
bool XMLStorage::XMLDocReader::_inCDATASection = false [private] |
Definition at line 213 of file XMLDocReader.cs.
Referenced by characters(), endCDATA(), and startCDATA().
StringBuilder XMLStorage::XMLDocReader::_instructions = new StringBuilder() [private] |
Definition at line 121 of file XMLDocReader.cs.
Referenced by getInstructions(), and processingInstruction().
bool XMLStorage::XMLDocReader::_isContentCDATA = false [private] |
Definition at line 214 of file XMLDocReader.cs.
Referenced by characters(), endElement(), read(), and startElement().
int XMLStorage::XMLDocReader::_lastTag [private] |
Definition at line 126 of file XMLDocReader.cs.
Referenced by endElement(), startElement(), and XMLDocReader().
XmlReader XMLStorage::XMLDocReader::_parser [private] |
Definition at line 118 of file XMLDocReader.cs.
Referenced by read().
XMLPos XMLStorage::XMLDocReader::_pos [private] |
Definition at line 117 of file XMLDocReader.cs.
Referenced by endElement(), read(), startElement(), and XMLDocReader().
int XMLStorage::XMLDocReader::TAG_END = 2 [static, private] |
Definition at line 125 of file XMLDocReader.cs.
Referenced by endElement(), and startElement().
int XMLStorage::XMLDocReader::TAG_NONE = 0 [static, private] |
Definition at line 123 of file XMLDocReader.cs.
Referenced by XMLDocReader().
int XMLStorage::XMLDocReader::TAG_START = 1 [static, private] |
Definition at line 124 of file XMLDocReader.cs.
Referenced by endElement(), and startElement().
1.7.2