ImageResizer  3.4.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Properties | List of all members
ImageResizer.Configuration.Xml.Node Class Reference

No support for namespaces, no intention of eventual serialization. Everything is case-insensitive, but preserves case. Not thread safe. More...

Public Member Functions

 Node (string localName)
 
 Node (XmlElement e, IIssueReceiver ir)
 Builds a tree of Nodes from the specified XML subtree. Duplicate attributes are sent to 'ir' More...
 
IList< NodechildrenByName (string elementName)
 Returns the subset of Children with a matching element name. (Case-insensitive) More...
 
string queryAttr (string selector)
 Queryies the subtree for the specified attribute on the specified element. Example selector: element.element.attrname Assumes that the last segment of the selector is an attribute name. Throws an ArgumentException if there is only one segment ( element ). Uses the cache. More...
 
string queryAttr (string nodeSelector, string attrName)
 
Node queryFirst (string selector)
 
void setAttr (string selector, string attrValue)
 Sets the specified attribute value, creating parent elements if needed. Clears the query cache. More...
 
void setAttr (string nodeSelector, string attrName, string attrValue)
 Sets the specified attribute value, creating parent elements if needed. Clears the query cache. More...
 
Node makeNodeTree (string selector)
 Traverses the specified path, creating any missing elements along the way. Uses existing nodes if found. More...
 
ICollection< Nodequery (string selector)
 Same as query(), except results are cached until clearQueryCache() is called. Faster, but can be incorrect if existing nodes are renamed, moved, or deleted. More...
 
void clearQueryCache ()
 
ICollection< NodequeryUncached (string selector)
 
Node deepCopy ()
 Makes a recusive copy of the subtree, keeping no duplicate references to mutable types. More...
 
XmlElement ToXmlElement ()
 
XmlElement ToXmlElement (XmlDocument doc)
 
override string ToString ()
 

Static Public Member Functions

static Node FromXmlFragment (string xml, IssueSink sink)
 

Protected Member Functions

KeyValuePair< string, string > parseAttributeName (string selector)
 

Protected Attributes

Dictionary< string,
ICollection< Node > > 
_cachedResults = new Dictionary<string, ICollection<Node>>(StringComparer.OrdinalIgnoreCase)
 

Properties

NameValueCollection Attrs [get, set]
 Attributes More...
 
string this[string name] [get, set]
 Access attributes by name More...
 
string TextContents [get, set]
 The concatenated text, significant whitespace, and entity references within this element. Not XML compliant for sure. More...
 
string Name [get, set]
 The name of the element. More...
 
List< NodeChildren [get, set]
 Child nodes More...
 
bool IsEmpty [get]
 Returns true if the element has neither attributes nor children. More...
 

Detailed Description

No support for namespaces, no intention of eventual serialization. Everything is case-insensitive, but preserves case. Not thread safe.

Definition at line 15 of file Node.cs.

Constructor & Destructor Documentation

ImageResizer.Configuration.Xml.Node.Node ( XmlElement  e,
IIssueReceiver  ir 
)
inline

Builds a tree of Nodes from the specified XML subtree. Duplicate attributes are sent to 'ir'

Parameters
e
ir

Definition at line 24 of file Node.cs.

24  {
25  name = e.LocalName;
26  //Copy attributes, raising an issue if duplicates are found
27  foreach (XmlAttribute a in e.Attributes) {
28  if (attrs[a.LocalName] != null){
29  ir.AcceptIssue(new Issue("Two or more attributes named " + a.LocalName + " found on element " + name + " in "
30  + e.ParentNode != null ? e.ParentNode.Name : "(unknown node)"));
31  }
32  attrs[a.LocalName] = a.Value;
33  }
34  //Parse children
35  if (e.HasChildNodes) {
36  StringBuilder sb = null;
37  foreach (XmlNode n in e.ChildNodes) {
38  if (n.NodeType == XmlNodeType.Element) {
39  XmlElement child = n as XmlElement;
40  if (child != null) children.Add(new Node(child, ir));
41  //Collect text and whitespace
42  } else if (n.NodeType == XmlNodeType.Text || n.NodeType == XmlNodeType.EntityReference || n.NodeType == XmlNodeType.SignificantWhitespace) { //|| n.NodeType == XmlNodeType.Whitespace
43  if (sb == null) sb = new StringBuilder();
44  sb.Append(n.Value);
45  }
46  }
47  //Save text/whitespace
48  if (sb != null) TextContents = sb.ToString();
49  }
50 
51  }
string TextContents
The concatenated text, significant whitespace, and entity references within this element. Not XML compliant for sure.
Definition: Node.cs:77

Member Function Documentation

IList<Node> ImageResizer.Configuration.Xml.Node.childrenByName ( string  elementName)
inline

Returns the subset of Children with a matching element name. (Case-insensitive)

Parameters
elementName
Returns

Definition at line 102 of file Node.cs.

102  {
103  List<Node> results = new List<Node>();
104  if (children == null || children.Count == 0) return results;
105  foreach(Node n in children)
106  if (n.Name.Equals(elementName, StringComparison.OrdinalIgnoreCase)) results.Add(n);
107 
108  return results;
109  }
Node ImageResizer.Configuration.Xml.Node.deepCopy ( )
inline

Makes a recusive copy of the subtree, keeping no duplicate references to mutable types.

Returns

Definition at line 244 of file Node.cs.

244  {
245  Node n = new Node(this.name);
246  //copy attrs
247  foreach (string key in this.Attrs.Keys) {
248  n[key] = this[key];
249  }
250 
251  //copy children recursive
252  if (this.children != null)
253  foreach (Node c in this.Children)
254  n.Children.Add(c.deepCopy());
255  //Copy text contents
256  n.TextContents = this.TextContents;
257 
258  return n;
259  }
NameValueCollection Attrs
Attributes
Definition: Node.cs:56
List< Node > Children
Child nodes
Definition: Node.cs:93
Node ImageResizer.Configuration.Xml.Node.makeNodeTree ( string  selector)
inline

Traverses the specified path, creating any missing elements along the way. Uses existing nodes if found.

Parameters
selector
Returns

Definition at line 171 of file Node.cs.

171  {
172  Node n = this;
173  Selector s = new Selector(selector);
174  foreach (string part in s) {
175  IList<Node> results = n.childrenByName(part);
176  //Add it if doesn't exist
177  if (results == null || results.Count == 0) {
178  Node newNode = new Node(part);
179  if (n.children == null) n.children = new List<Node>();
180  n.Children.Add(newNode);
181  n = newNode;
182  } else {
183  n = results[0];
184  }
185  }
186  return n;
187  }
ICollection<Node> ImageResizer.Configuration.Xml.Node.query ( string  selector)
inline

Same as query(), except results are cached until clearQueryCache() is called. Faster, but can be incorrect if existing nodes are renamed, moved, or deleted.

Parameters
selector
Returns

Definition at line 196 of file Node.cs.

196  {
197 
198  if (_cachedResults.ContainsKey(selector)) return _cachedResults[selector];
199 
200  IList<Node> uncachedResults = queryUncached(selector) as IList<Node>;
201  //cache miss
202  ICollection<Node> results = _cachedResults[selector] = uncachedResults != null ? new ReadOnlyCollection<Node>(uncachedResults) : null;
203  return results;
204  }
string ImageResizer.Configuration.Xml.Node.queryAttr ( string  selector)
inline

Queryies the subtree for the specified attribute on the specified element. Example selector: element.element.attrname Assumes that the last segment of the selector is an attribute name. Throws an ArgumentException if there is only one segment ( element ). Uses the cache.

Parameters
selector
Returns

Definition at line 119 of file Node.cs.

119  {
120  KeyValuePair<string, string> parsed = parseAttributeName(selector);
121  return queryAttr(parsed.Key, parsed.Value);
122  }
string queryAttr(string selector)
Queryies the subtree for the specified attribute on the specified element. Example selector: element...
Definition: Node.cs:119
void ImageResizer.Configuration.Xml.Node.setAttr ( string  selector,
string  attrValue 
)
inline

Sets the specified attribute value, creating parent elements if needed. Clears the query cache.

Parameters
selector
attrValue

Definition at line 149 of file Node.cs.

149  {
150 
151  KeyValuePair<string, string> parsed = parseAttributeName(selector);
152  setAttr(parsed.Key, parsed.Value, attrValue);
153  }
void setAttr(string selector, string attrValue)
Sets the specified attribute value, creating parent elements if needed. Clears the query cache...
Definition: Node.cs:149
void ImageResizer.Configuration.Xml.Node.setAttr ( string  nodeSelector,
string  attrName,
string  attrValue 
)
inline

Sets the specified attribute value, creating parent elements if needed. Clears the query cache.

Parameters
nodeSelector
attrName
attrValue

Definition at line 160 of file Node.cs.

160  {
161  Node n = queryFirst(nodeSelector);
162  if (n == null) n = makeNodeTree(nodeSelector);
163  n.Attrs[attrName] = attrValue;
164  this.clearQueryCache();
165  }
Node makeNodeTree(string selector)
Traverses the specified path, creating any missing elements along the way. Uses existing nodes if fou...
Definition: Node.cs:171

Property Documentation

NameValueCollection ImageResizer.Configuration.Xml.Node.Attrs
getset
List<Node> ImageResizer.Configuration.Xml.Node.Children
getset

Child nodes

Definition at line 93 of file Node.cs.

Referenced by ImageResizer.Configuration.PluginConfig.loadPluginsInternal().

bool ImageResizer.Configuration.Xml.Node.IsEmpty
get

Returns true if the element has neither attributes nor children.

Definition at line 264 of file Node.cs.

string ImageResizer.Configuration.Xml.Node.Name
getset
string ImageResizer.Configuration.Xml.Node.TextContents
getset

The concatenated text, significant whitespace, and entity references within this element. Not XML compliant for sure.

Definition at line 77 of file Node.cs.

string ImageResizer.Configuration.Xml.Node.this[string name]
getset

Access attributes by name

Parameters
name
Returns

Definition at line 65 of file Node.cs.


The documentation for this class was generated from the following file: