XMLStreamReader is the streaming XML file reader of XMLStorage. More...


Public Member Functions | |
| XMLStreamReader (string path, XmlReaderSettings settings=null) | |
| XMLStreamReader (StreamReader source, XmlReaderSettings settings=null) | |
| void | Dispose () |
| XMLStreamNode | getNode () |
| Object | getNodeName () |
| bool | isAtNode (string nodeName) |
| IEnumerable< XMLStreamNode > | iterator () |
| Iterates over the immediate children of the current XML node. | |
| IEnumerable< XMLStreamNode > | filterChildren (XMLStreamReader reader, string name) |
| Iterates over the immediate children of the current XML node and filters by node name. | |
| string | get (string attrName) |
| Return the value of an attribute in the current node or "". | |
| string | get (string attrName, string def) |
| Return the value of an attribute in the current node or a default value. | |
| bool | goDown () |
| Go down to first child. | |
| bool | goDown (string name) |
| Search for child and go down. | |
| bool | go (XPath xpath) |
| move X-Path like to position in XML tree | |
| bool | back () |
| Move back to the next higher nesting level. | |
| string | getContent () |
| override string | ToString () |
| string | getInstructions () |
| bool | firstChild () |
| Move to the first child node. | |
| bool | firstChild (string nodeName) |
| Move to the first child node with the specified name. | |
| bool | next () |
| Move to the next sibling node independent from its name. | |
| bool | nextSkipOthers (string nodeName) |
| Move to the next sibling node with the specified name. | |
| bool | nextStopOnOthers (string nodeName) |
| Move to the next sibling node with the specified name. | |
| bool | find (string nodeName) |
| Find a children node by name. | |
| bool | find (string nodeName, int n) |
| Find the n'th children node with tag nodeName. | |
| bool | find (string nodeName, string attrName, string attrValue) |
| Search matching child node identified by key name and an attribute value. | |
| bool | find (string nodeName, string attrName, string attrValue, int n) |
| Search matching child node identified by key name and an attribute value. | |
Protected Attributes | |
| XmlReader | _reader |
| XMLStreamNode | _node |
| string | _content = "" |
| StringBuilder | _instructions = new StringBuilder() |
Private Member Functions | |
| void | init (TextReader source, XmlReaderSettings settings=null) |
| void | startElement (string nodeName) |
| void | endElement (string nodeName) |
| void | characters (string str) |
| void | processingInstruction (string target, string data) |
| bool | findNode (string targetTag, int targetLevel, int minLevel, bool stopOnOthers) |
| bool | handlePendingEndElement (int minLevel) |
| bool | findRelative (XPath xpath) |
| XPath find function. | |
| bool | find (XPathElement xelem) |
| Search matching child node identified by key name and an attribute value. | |
Private Attributes | |
| TextReader | _istream |
| int | _level = 0 |
| bool | _pendingEndElement = false |
XMLStreamReader is the streaming XML file reader of XMLStorage.
Definition at line 51 of file XMLStreamReader.cs.
| XMLStorage::XMLStreamReader::XMLStreamReader | ( | string | path, |
| XmlReaderSettings | settings = null |
||
| ) | [inline] |
| XMLStorage::XMLStreamReader::XMLStreamReader | ( | StreamReader | source, |
| XmlReaderSettings | settings = null |
||
| ) | [inline] |
Definition at line 70 of file XMLStreamReader.cs.
References init().
{
init(source, settings);
}

| bool XMLStorage::XMLStreamReader::back | ( | ) | [inline] |
Move back to the next higher nesting level.
Remark: This implementation does _not_ jump more than one level up like XMLPos.node() when using go() to move down more than one level at a time.
Definition at line 192 of file XMLStreamReader.cs.
References _level, and findNode().

| void XMLStorage::XMLStreamReader::characters | ( | string | str ) | [inline, private] |
Definition at line 230 of file XMLStreamReader.cs.
References _content, and XMLStorage::XMLHelper::encodeXMLString().
Referenced by findNode().
{
_content += XMLHelper.encodeXMLString(str);
}

| void XMLStorage::XMLStreamReader::Dispose | ( | ) | [inline] |
| void XMLStorage::XMLStreamReader::endElement | ( | string | nodeName ) | [inline, private] |
Definition at line 221 of file XMLStreamReader.cs.
References _content, _level, _node, and XMLStorage::XMLStreamNode::assign().
Referenced by findNode(), and handlePendingEndElement().

| IEnumerable<XMLStreamNode> XMLStorage::XMLStreamReader::filterChildren | ( | XMLStreamReader | reader, |
| string | name | ||
| ) | [inline] |
Iterates over the immediate children of the current XML node and filters by node name.
(replaces XMLStreamFilter)
Definition at line 126 of file XMLStreamReader.cs.
References XMLStorage::XMLStreamNode::getName(), and iterator().
{
foreach(XMLStreamNode node in iterator())
{
if (node.getName() == name)
yield return node;
}
}

| bool XMLStorage::XMLStreamReader::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 475 of file XMLStreamReader.cs.
References _node, firstChild(), XMLStorage::XMLStreamNode::get(), XMLStorage::XMLStreamNode::getName(), and nextSkipOthers().
{
if (firstChild(nodeName)) {
if (_node.getName()==nodeName && _node.get(attrName)==attrValue)
if (n-- == 0)
return true;
while(nextSkipOthers(nodeName))
if (_node.getName()==nodeName && _node.get(attrName)==attrValue)
if (n-- == 0)
return true;
}
return false;
}

| bool XMLStorage::XMLStreamReader::find | ( | XPathElement | xelem ) | [inline, private] |
Search matching child node identified by key name and an attribute value.
| xelem |
Definition at line 511 of file XMLStreamReader.cs.
References XMLStorage::XPathElement::_childName, _node, firstChild(), XMLStorage::XPathElement::matches(), and nextSkipOthers().
{
int[] n = new int[] {0}; // index in array for call-by-reference matches()
if (firstChild(xelem._childName)) {
if (xelem.matches(_node, n))
return true;
while(nextSkipOthers(xelem._childName))
if (xelem.matches(_node, n))
return true;
}
return false;
}

| bool XMLStorage::XMLStreamReader::find | ( | string | nodeName ) | [inline] |
Find a children node by name.
| nodeName |
Definition at line 423 of file XMLStreamReader.cs.
References firstChild().
Referenced by findRelative().
{
return firstChild(nodeName);
}

| bool XMLStorage::XMLStreamReader::find | ( | string | nodeName, |
| int | n | ||
| ) | [inline] |
Find the n'th children node with tag nodeName.
| nodeName | |
| n |
Definition at line 434 of file XMLStreamReader.cs.
References firstChild(), and nextSkipOthers().
{
if (!firstChild(nodeName))
return false;
for(int i=1; i<n; ++i)
if (!nextSkipOthers(nodeName))
return false;
return true;
}

| bool XMLStorage::XMLStreamReader::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 453 of file XMLStreamReader.cs.
References _node, firstChild(), XMLStorage::XMLStreamNode::get(), XMLStorage::XMLStreamNode::getName(), and nextSkipOthers().
{
if (firstChild(nodeName)) {
if (_node.getName()==nodeName && _node.get(attrName)==attrValue)
return true;
while(nextSkipOthers(nodeName))
if (_node.getName()==nodeName && _node.get(attrName)==attrValue)
return true;
}
return false;
}

| bool XMLStorage::XMLStreamReader::findNode | ( | string | targetTag, |
| int | targetLevel, | ||
| int | minLevel, | ||
| bool | stopOnOthers | ||
| ) | [inline, private] |
Definition at line 295 of file XMLStreamReader.cs.
References _content, _level, _node, _pendingEndElement, _reader, characters(), endElement(), handlePendingEndElement(), processingInstruction(), XMLStorage::XMLStreamNode::setContent(), and startElement().
Referenced by back(), firstChild(), next(), nextSkipOthers(), and nextStopOnOthers().
{
bool found = false;
if (!handlePendingEndElement(minLevel))
return false;
do {
switch(_reader.NodeType) {
case XmlNodeType.Element: {
// stop parsing if we found the target node and its content is already processed.
if (found)
goto break_parsingLoop;
// check for match in target level and eventually node name
int level = _pendingEndElement? _level-1: _level;
if (level+1 == targetLevel) {
if (targetTag==null || _reader.Name==targetTag)
found = true;
else if (stopOnOthers)
return false;
}
if (_reader.IsEmptyElement) { // node without sub nodes and text content, but maybe with attribute values {
if (!handlePendingEndElement(minLevel))
return false;
_pendingEndElement = true;
}
startElement(_reader.Name);
break;}
case XmlNodeType.EndElement: {
// stop parsing if we found the target node and its content is already processed.
if (found)
goto break_parsingLoop;
// stop before leaving the targeted level range; used by nextStopOnOthers()
int level = _pendingEndElement? _level-1: _level;
if (level == minLevel)
return false;
endElement(_reader.Name);
// stop searching if the current level leaves the target range; used by back()
if (_level < minLevel) {
_reader.Read();
return false;
}
break;}
case XmlNodeType.Text:
//Console.Write(_reader.Value);
characters(_reader.Value);
break;
case XmlNodeType.CDATA:
//Console.Write("<![CDATA[{0}]]>", _reader.Value);
characters(_reader.Value);
break;
case XmlNodeType.Comment:
//Console.Write("<!--{0}-->", _reader.Value);
characters(_reader.Value);
break;
case XmlNodeType.XmlDeclaration:
//Console.Write("<?xml version='1.0'?>");
break;
case XmlNodeType.ProcessingInstruction:
//Console.Write("<?{0} {1}?>", _reader.Name, _reader.Value);
processingInstruction(_reader.Name, _reader.Value);
break;
case XmlNodeType.DocumentType:
//Console.Write("<!DOCTYPE {0} [{1}]", _reader.Name, _reader.Value);
break;
//case XmlNodeType.Document:
// break;
//case XmlNodeType.EntityReference:
// Console.Write(reader.Name);
// break;
}
} while(_reader.Read());
break_parsingLoop:
if (found) {
_node.setContent(_content);
_content = "";
return true;
} else
return false;
}

| bool XMLStorage::XMLStreamReader::findRelative | ( | XPath | xpath ) | [inline, private] |
| bool XMLStorage::XMLStreamReader::firstChild | ( | ) | [inline] |
Move to the first child node.
Definition at line 250 of file XMLStreamReader.cs.
References _level, and findNode().
Referenced by find(), goDown(), and iterator().

| bool XMLStorage::XMLStreamReader::firstChild | ( | string | nodeName ) | [inline] |
Move to the first child node with the specified name.
Definition at line 259 of file XMLStreamReader.cs.
References _level, and findNode().

| string XMLStorage::XMLStreamReader::get | ( | string | attrName, |
| string | def | ||
| ) | [inline] |
Return the value of an attribute in the current node or a default value.
| attrName | |
| def | default value |
Definition at line 152 of file XMLStreamReader.cs.
References _node, and XMLStorage::XMLStreamNode::get().
{
return _node.get(attrName, def);
}

| string XMLStorage::XMLStreamReader::get | ( | string | attrName ) | [inline] |
Return the value of an attribute in the current node or "".
| attrName |
Definition at line 141 of file XMLStreamReader.cs.
References _node, and XMLStorage::XMLStreamNode::get().
{
return _node.get(attrName);
}

| string XMLStorage::XMLStreamReader::getContent | ( | ) | [inline] |
Definition at line 200 of file XMLStreamReader.cs.
References _node, and XMLStorage::XMLStreamNode::getContent().
{
return _node.getContent();
}

| string XMLStorage::XMLStreamReader::getInstructions | ( | ) | [inline] |
Definition at line 240 of file XMLStreamReader.cs.
References _instructions.
{
return _instructions.ToString();
}
| XMLStreamNode XMLStorage::XMLStreamReader::getNode | ( | ) | [inline] |
Definition at line 94 of file XMLStreamReader.cs.
References _node.
Referenced by XMLStorage::XMLBool::XMLBool(), XMLStorage::XMLDecimal::XMLDecimal(), XMLStorage::XMLDouble::XMLDouble(), XMLStorage::XMLInt::XMLInt(), and XMLStorage::XMLString::XMLString().
{
return _node;
}
| Object XMLStorage::XMLStreamReader::getNodeName | ( | ) | [inline] |
Definition at line 99 of file XMLStreamReader.cs.
References _node, and XMLStorage::XMLStreamNode::getName().
{
return _node.getName();
}

| bool XMLStorage::XMLStreamReader::go | ( | XPath | xpath ) | [inline] |
move X-Path like to position in XML tree
Definition at line 177 of file XMLStreamReader.cs.
References XMLStorage::XPath::_absolute, and findRelative().
{
// Absolute paths are not supported.
if (xpath._absolute)
return false;
return findRelative(xpath);
}

| bool XMLStorage::XMLStreamReader::goDown | ( | ) | [inline] |
Go down to first child.
Definition at line 161 of file XMLStreamReader.cs.
References firstChild().
{
return firstChild(null);
}

| bool XMLStorage::XMLStreamReader::goDown | ( | string | name ) | [inline] |
Search for child and go down.
| name |
Definition at line 171 of file XMLStreamReader.cs.
References firstChild().
{
return firstChild(name);
}

| bool XMLStorage::XMLStreamReader::handlePendingEndElement | ( | int | minLevel ) | [inline, private] |
Definition at line 394 of file XMLStreamReader.cs.
References _level, _node, _pendingEndElement, _reader, endElement(), XMLStorage::XMLStreamNode::getName(), and XMLStorage::AbstractXMLNode::hasAttributes().
Referenced by findNode().
{
if (_pendingEndElement) {
_pendingEndElement = false;
bool withAttributes = _node.hasAttributes();
endElement(_node.getName());
// stop searching if the current level leaves the target range; used by back()
if (_level < minLevel) {
// If there have been read attributes in AbstractXMLNode.setAttributes(), XMLReader already points to the next node,
// so don't call XmlReader.Read()
if (!withAttributes)
_reader.Read();
return false;
}
}
return true;
}

| void XMLStorage::XMLStreamReader::init | ( | TextReader | source, |
| XmlReaderSettings | settings = null |
||
| ) | [inline, private] |
Definition at line 75 of file XMLStreamReader.cs.
References _node, and _reader.
Referenced by XMLStreamReader().
| bool XMLStorage::XMLStreamReader::isAtNode | ( | string | nodeName ) | [inline] |
Definition at line 104 of file XMLStreamReader.cs.
References _node, and XMLStorage::XMLStreamNode::getName().
{
return _node.getName() == nodeName;
}

| IEnumerable<XMLStreamNode> XMLStorage::XMLStreamReader::iterator | ( | ) | [inline] |
Iterates over the immediate children of the current XML node.
Definition at line 113 of file XMLStreamReader.cs.
References _node, firstChild(), and next().
Referenced by filterChildren().
{
if (firstChild())
yield return _node;
while(next())
yield return _node;
}

| bool XMLStorage::XMLStreamReader::next | ( | ) | [inline] |
Move to the next sibling node independent from its name.
Definition at line 269 of file XMLStreamReader.cs.
References _level, and findNode().
Referenced by iterator().

| bool XMLStorage::XMLStreamReader::nextSkipOthers | ( | string | nodeName ) | [inline] |
Move to the next sibling node with the specified name.
Definition at line 278 of file XMLStreamReader.cs.
References _level, and findNode().
Referenced by find().

| bool XMLStorage::XMLStreamReader::nextStopOnOthers | ( | string | nodeName ) | [inline] |
Move to the next sibling node with the specified name.
Definition at line 287 of file XMLStreamReader.cs.
References _level, and findNode().

| void XMLStorage::XMLStreamReader::processingInstruction | ( | string | target, |
| string | data | ||
| ) | [inline, private] |
Definition at line 235 of file XMLStreamReader.cs.
References _instructions.
Referenced by findNode().
{
_instructions.Append("<?").Append(target).Append(" ").Append(data).Append("?>");
}
| void XMLStorage::XMLStreamReader::startElement | ( | string | nodeName ) | [inline, private] |
Definition at line 211 of file XMLStreamReader.cs.
References _content, _level, _node, _reader, XMLStorage::XMLStreamNode::assign(), and XMLStorage::AbstractXMLNode::setAttributes().
Referenced by findNode().

| override string XMLStorage::XMLStreamReader::ToString | ( | ) | [inline] |
Definition at line 205 of file XMLStreamReader.cs.
References _node, and XMLStorage::XMLStreamNode::ToString().
{
return _node.ToString();
}

string XMLStorage::XMLStreamReader::_content = "" [protected] |
Definition at line 58 of file XMLStreamReader.cs.
Referenced by characters(), endElement(), findNode(), and startElement().
StringBuilder XMLStorage::XMLStreamReader::_instructions = new StringBuilder() [protected] |
Definition at line 59 of file XMLStreamReader.cs.
Referenced by getInstructions(), and processingInstruction().
TextReader XMLStorage::XMLStreamReader::_istream [private] |
Definition at line 53 of file XMLStreamReader.cs.
Referenced by Dispose(), and XMLStreamReader().
int XMLStorage::XMLStreamReader::_level = 0 [private] |
Definition at line 61 of file XMLStreamReader.cs.
Referenced by back(), endElement(), findNode(), firstChild(), handlePendingEndElement(), next(), nextSkipOthers(), nextStopOnOthers(), and startElement().
XMLStreamNode XMLStorage::XMLStreamReader::_node [protected] |
Definition at line 56 of file XMLStreamReader.cs.
Referenced by endElement(), find(), findNode(), get(), getContent(), getNode(), getNodeName(), handlePendingEndElement(), init(), isAtNode(), iterator(), startElement(), and ToString().
bool XMLStorage::XMLStreamReader::_pendingEndElement = false [private] |
Definition at line 293 of file XMLStreamReader.cs.
Referenced by findNode(), and handlePendingEndElement().
XmlReader XMLStorage::XMLStreamReader::_reader [protected] |
Definition at line 54 of file XMLStreamReader.cs.
Referenced by Dispose(), findNode(), handlePendingEndElement(), init(), and startElement().
1.7.2