diff options
author | Atsushi Eno <atsushieno@gmail.com> | 2004-03-26 19:12:40 +0300 |
---|---|---|
committer | Atsushi Eno <atsushieno@gmail.com> | 2004-03-26 19:12:40 +0300 |
commit | 9c7eff610045de8251965b0ed06e4c8ee46c55ab (patch) | |
tree | c59bfdda1850d1f5a78fe459a3c54df12581e298 /mcs/class/System.Security/Mono.Xml | |
parent | da7c4adefdc3787b3bece302a2ef86ee7aa6d023 (diff) |
2004-03-26 Atsushi Enomoto <atsushi@ximian.com>
* XmlCanonicalizer.cs :
Don't output 
 for Whitespace node.
To filter every kind of nodes, make sure node.Attributes isnot null.
This makes some phaos tests passed.
svn path=/trunk/mcs/; revision=24637
Diffstat (limited to 'mcs/class/System.Security/Mono.Xml')
-rwxr-xr-x | mcs/class/System.Security/Mono.Xml/ChangeLog | 7 | ||||
-rwxr-xr-x | mcs/class/System.Security/Mono.Xml/XmlCanonicalizer.cs | 34 |
2 files changed, 32 insertions, 9 deletions
diff --git a/mcs/class/System.Security/Mono.Xml/ChangeLog b/mcs/class/System.Security/Mono.Xml/ChangeLog index d303a835474..4ab97a3aaa2 100755 --- a/mcs/class/System.Security/Mono.Xml/ChangeLog +++ b/mcs/class/System.Security/Mono.Xml/ChangeLog @@ -1,3 +1,10 @@ +2004-03-26 Atsushi Enomoto <atsushi@ximian.com> + + * XmlCanonicalizer.cs : + Don't output 
 for Whitespace node. + To filter every kind of nodes, make sure node.Attributes isnot null. + This makes some phaos tests passed. + 2004-02-14 Atsushi Enomoto <atsushi@ximian.com> * XmlCanonicalizer.cs: Use child nodes of entity reference nodes (it diff --git a/mcs/class/System.Security/Mono.Xml/XmlCanonicalizer.cs b/mcs/class/System.Security/Mono.Xml/XmlCanonicalizer.cs index 3aee88206cf..b4ca937657a 100755 --- a/mcs/class/System.Security/Mono.Xml/XmlCanonicalizer.cs +++ b/mcs/class/System.Security/Mono.Xml/XmlCanonicalizer.cs @@ -7,7 +7,7 @@ // // (C) 2003 Aleksey Sanin (aleksey@aleksey.com) // - +using System; using System.Collections; using System.IO; using System.Text; @@ -96,7 +96,6 @@ namespace Mono.Xml { 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; @@ -297,10 +296,12 @@ namespace Mono.Xml { // 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") @@ -352,7 +353,8 @@ namespace Mono.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 @@ -447,7 +449,7 @@ namespace Mono.Xml { string p = string.Empty; if (node.Prefix == "xmlns") p = node.LocalName; - if (p == prefix) + if (p == prefix) return node.Value == uri; } } @@ -462,16 +464,28 @@ namespace Mono.Xml { 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 ("""); @@ -480,10 +494,12 @@ namespace Mono.Xml { else if (ch == '\x0A' && type == XmlNodeType.Attribute) sb.Append ("
"); else if (ch == '\x0D' && (type == XmlNodeType.Attribute || - type == XmlNodeType.Text || + IsTextNode (type) && type != XmlNodeType.Whitespace || type == XmlNodeType.Comment || type == XmlNodeType.ProcessingInstruction)) sb.Append ("
"); + else if (ch == '\x0D') + continue; else sb.Append (ch); } |