// (C) 2003 Aleksey Sanin (aleksey@aleksey.com)
//
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
using System.Collections;
using System.IO;
using System.Text;
{
xnl = nodes;
if (nodes == null || nodes.Count < 1)
- return null;
+ return new MemoryStream ();
return Canonicalize (nodes[0].OwnerDocument);
}
WriteProcessingInstructionNode (node, visible);
break;
case XmlNodeType.EntityReference:
-// throw new XmlException ("Entity references should be resolved by parser", null);
for (int i = 0; i < node.ChildNodes.Count; i++)
WriteNode (node.ChildNodes [i]);
break;
// nodes of E's attribute axis that are in the node-set. The
// result of visiting the attribute axis is computed by
// processing the attribute nodes in this merged attribute list.
- if (!exclusive && node.ParentNode != null && !IsNodeVisible (node.ParentNode.ParentNode)) {
+ if (!exclusive && node.ParentNode != null && node.ParentNode.ParentNode != null && !IsNodeVisible (node.ParentNode.ParentNode)) {
// if we have whole document then the node.ParentNode.ParentNode
// is always visible
for (XmlNode cur = node.ParentNode; cur != null; cur = cur.ParentNode) {
+ if (cur.Attributes == null)
+ continue;
foreach (XmlNode attribute in cur.Attributes) {
// we are looking for "xml:*" attributes
if (attribute.Prefix != "xml")
{
// Console.WriteLine ("Debug: text node");
if (visible)
- res.Append (NormalizeString (node.Value, XmlNodeType.Text));
+ res.Append (NormalizeString (node.Value, node.NodeType));
+// res.Append (NormalizeString (node.Value, XmlNodeType.Text));
}
// Comment Nodes
string p = string.Empty;
if (node.Prefix == "xmlns")
p = node.LocalName;
- if (p == prefix)
+ if (p == prefix)
return node.Value == uri;
}
}
return node.NamespaceURI == "http://www.w3.org/2000/xmlns/";
}
+ private bool IsTextNode (XmlNodeType type)
+ {
+ switch (type) {
+ case XmlNodeType.Text:
+ case XmlNodeType.CDATA:
+ case XmlNodeType.SignificantWhitespace:
+ case XmlNodeType.Whitespace:
+ return true;
+ }
+ return false;
+ }
+
private string NormalizeString (string input, XmlNodeType type)
{
StringBuilder sb = new StringBuilder ();
for (int i = 0; i < input.Length; i++) {
char ch = input[i];
- if (ch == '<' && (type == XmlNodeType.Attribute || type == XmlNodeType.Text))
+ if (ch == '<' && (type == XmlNodeType.Attribute || IsTextNode (type)))
sb.Append ("<");
- else if (ch == '>' && type == XmlNodeType.Text)
+ else if (ch == '>' && IsTextNode (type))
sb.Append (">");
- else if (ch == '&' && (type == XmlNodeType.Attribute || type == XmlNodeType.Text))
+ else if (ch == '&' && (type == XmlNodeType.Attribute || IsTextNode (type)))
sb.Append ("&");
else if (ch == '\"' && type == XmlNodeType.Attribute)
sb.Append (""");
sb.Append ("	");
else if (ch == '\x0A' && type == XmlNodeType.Attribute)
sb.Append ("
");
- else if (ch == '\x0D' && (type == XmlNodeType.Attribute ||
- type == XmlNodeType.Text ||
- type == XmlNodeType.Comment ||
- type == XmlNodeType.ProcessingInstruction))
+ else if (ch == '\x0D')
sb.Append ("
");
else
sb.Append (ch);