Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAtsushi Eno <atsushieno@gmail.com>2006-11-10 04:39:23 +0300
committerAtsushi Eno <atsushieno@gmail.com>2006-11-10 04:39:23 +0300
commit25fc3e1f3bce5d54e27f31535a73c392978aedb4 (patch)
tree545534d71d24fafdaec843aec1fc1f00e045e38a /mcs/class/System.XML/System.Xml.XPath
parentc2113a28944a55c46a31c84cc6181cfbd7bb37cf (diff)
2006-11-10 Atsushi Enomoto <atsushi@ximian.com>
* XPathNavigator.cs : - ReadSubtree() should reject everything but Element or Root. - InnerXml and OuterXml should not use ReadSubtree() when it is not positioned on an Element or the Root. Thus, implement them in their own ways. Fixed bug #79875. * XPathNavigatorTests.cs : added test for bug #79875, and some "escaped" text tests for InnerXml. * XPathNavigatorReaderTests.cs : make sure that most of XPath nodes are rejected to read subtree. svn path=/trunk/mcs/; revision=67659
Diffstat (limited to 'mcs/class/System.XML/System.Xml.XPath')
-rw-r--r--mcs/class/System.XML/System.Xml.XPath/ChangeLog8
-rw-r--r--mcs/class/System.XML/System.Xml.XPath/XPathNavigator.cs75
2 files changed, 81 insertions, 2 deletions
diff --git a/mcs/class/System.XML/System.Xml.XPath/ChangeLog b/mcs/class/System.XML/System.Xml.XPath/ChangeLog
index ce3d8453919..52cf2749030 100644
--- a/mcs/class/System.XML/System.Xml.XPath/ChangeLog
+++ b/mcs/class/System.XML/System.Xml.XPath/ChangeLog
@@ -1,5 +1,13 @@
2006-11-10 Atsushi Enomoto <atsushi@ximian.com>
+ * XPathNavigator.cs :
+ - ReadSubtree() should reject everything but Element or Root.
+ - InnerXml and OuterXml should not use ReadSubtree() when it is
+ not positioned on an Element or the Root. Thus, implement them
+ in their own ways. Fixed bug #79875.
+
+2006-11-10 Atsushi Enomoto <atsushi@ximian.com>
+
* XPathNavigator.cs : InnerXml should allow Text-only content. Fixed
bug #79874, when tied to XPathNavigatorReader fix.
diff --git a/mcs/class/System.XML/System.Xml.XPath/XPathNavigator.cs b/mcs/class/System.XML/System.Xml.XPath/XPathNavigator.cs
index 311271ce55e..a4ea087110c 100644
--- a/mcs/class/System.XML/System.Xml.XPath/XPathNavigator.cs
+++ b/mcs/class/System.XML/System.Xml.XPath/XPathNavigator.cs
@@ -834,7 +834,13 @@ namespace System.Xml.XPath
public virtual XmlReader ReadSubtree ()
{
- return new XPathNavigatorReader (this);
+ switch (NodeType) {
+ case XPathNodeType.Element:
+ case XPathNodeType.Root:
+ return new XPathNavigatorReader (this);
+ default:
+ throw new InvalidOperationException (String.Format ("NodeType {0} is not supported to read as a subtree of an XPathNavigator.", NodeType));
+ }
}
public virtual XPathNodeIterator Select (string xpath, IXmlNamespaceResolver nsResolver)
@@ -874,9 +880,48 @@ namespace System.Xml.XPath
writer.WriteNode (this, false);
}
- [MonoTODO]
+ static readonly char [] escape_text_chars =
+ new char [] {'&', '<', '>'};
+ static readonly char [] escape_attr_chars =
+ new char [] {'"', '&', '<', '>', '\r', '\n'};
+
+ static string EscapeString (string value, bool attr)
+ {
+ StringBuilder sb = null;
+ char [] escape = attr ? escape_attr_chars : escape_text_chars;
+ if (value.IndexOfAny (escape) < 0)
+ return value;
+ sb = new StringBuilder (value, value.Length + 10);
+ if (attr)
+ sb.Replace ("\"", "&quot;");
+ sb.Replace ("<", "&lt;");
+ sb.Replace (">", "&gt;");
+ if (attr) {
+ sb.Replace ("\r\n", "&#10;");
+ sb.Replace ("\r", "&#10;");
+ sb.Replace ("\n", "&#10;");
+ }
+ return sb.ToString ();
+ }
+
public virtual string InnerXml {
get {
+ switch (NodeType) {
+ case XPathNodeType.Element:
+ case XPathNodeType.Root:
+ break;
+ case XPathNodeType.Attribute:
+ case XPathNodeType.Namespace:
+ return EscapeString (Value, true);
+ case XPathNodeType.Text:
+ case XPathNodeType.Whitespace:
+ case XPathNodeType.SignificantWhitespace:
+ return String.Empty;
+ case XPathNodeType.ProcessingInstruction:
+ case XPathNodeType.Comment:
+ return Value;
+ }
+
XmlReader r = ReadSubtree ();
r.Read (); // start
// skip the element itself (or will reach to
@@ -910,6 +955,32 @@ namespace System.Xml.XPath
public virtual string OuterXml {
get {
+ switch (NodeType) {
+ case XPathNodeType.Attribute:
+ return String.Concat (
+ Prefix,
+ Prefix.Length > 0 ? ":" : String.Empty,
+ LocalName,
+ "=\"",
+ EscapeString (Value, true),
+ "\"");
+ break;
+ case XPathNodeType.Namespace:
+ return String.Concat (
+ "xmlns",
+ LocalName.Length > 0 ? ":" : String.Empty,
+ LocalName,
+ "=\"",
+ EscapeString (Value, true),
+ "\"");
+ break;
+ case XPathNodeType.Text:
+ return EscapeString (Value, false);
+ case XPathNodeType.Whitespace:
+ case XPathNodeType.SignificantWhitespace:
+ return Value;
+ }
+
XmlWriterSettings s = new XmlWriterSettings ();
s.Indent = true;
s.OmitXmlDeclaration = true;