Imported Upstream version 4.2.0.179

Former-commit-id: 4610231f55806d2a05ed69e5ff3faa7336cc1479
This commit is contained in:
Xamarin Public Jenkins
2015-08-26 07:17:56 -04:00
committed by Jo Shields
parent aa7da660d6
commit c042cd0c52
7507 changed files with 90259 additions and 657307 deletions

View File

@@ -3,26 +3,15 @@ SUBDIRS =
include ../../build/rules.make
LIBRARY = System.Xml.Linq.dll
LIB_MCS_FLAGS = \
-r:System.dll \
-r:System.Core.dll \
-r:System.Xml.dll
LIB_REFS = System System.Core System.Xml System.Runtime.Serialization
LIB_MCS_FLAGS =
ifneq (2.1, $(FRAMEWORK_VERSION))
# This is a .NET 3.5+ only assembly, but built during the 2.0 build
LIB_MCS_FLAGS += -d:NET_3_5 -nowarn:1720
ifeq (2.1, $(FRAMEWORK_VERSION))
LIB_MCS_FLAGS += -d:MONO_HYBRID_SYSTEM_XML
endif
TEST_MCS_FLAGS = $(LIB_MCS_FLAGS)
EXTRA_DISTFILES =
VALID_PROFILE := $(filter 2 4, $(FRAMEWORK_VERSION_MAJOR))
ifndef VALID_PROFILE
LIBRARY_NAME = dummy-System.Xml.Linq.dll
NO_INSTALL = yes
NO_SIGN_ASSEMBLY = yes
NO_TEST = yes
endif
include ../../build/library.make

View File

@@ -2,33 +2,7 @@
../../build/common/Locale.cs
../../build/common/MonoTODOAttribute.cs
Assembly/AssemblyInfo.cs
System.Xml.Linq/Extensions.cs
System.Xml.Linq/LoadOptions.cs
System.Xml.Linq/ReaderOptions.cs
System.Xml.Linq/SaveOptions.cs
System.Xml.Linq/XAttribute.cs
System.Xml.Linq/XCData.cs
System.Xml.Linq/XComment.cs
System.Xml.Linq/XContainer.cs
System.Xml.Linq/XDeclaration.cs
System.Xml.Linq/XDocument.cs
System.Xml.Linq/XDocumentType.cs
System.Xml.Linq/XElement.cs
System.Xml.Linq/XIterators.cs
System.Xml.Linq/XName.cs
System.Xml.Linq/XNamespace.cs
System.Xml.Linq/XNode.cs
System.Xml.Linq/XNodeDocumentOrderComparer.cs
System.Xml.Linq/XNodeEqualityComparer.cs
System.Xml.Linq/XNodeNavigator.cs
System.Xml.Linq/XNodeReader.cs
System.Xml.Linq/XNodeWriter.cs
System.Xml.Linq/XObject.cs
System.Xml.Linq/XObjectChange.cs
System.Xml.Linq/XObjectChangeEventArgs.cs
System.Xml.Linq/XProcessingInstruction.cs
System.Xml.Linq/XStreamingElement.cs
System.Xml.Linq/XText.cs
System.Xml.Linq/XUtil.cs
System.Xml.Schema/Extensions.cs
System.Xml.XPath/Extensions.cs
../../../external/referencesource/System.Xml.Linq/System/Xml/Linq/XNodeValidator.cs
../../../external/referencesource/System.Xml.Linq/System/Xml/Linq/XNodeNavigator.cs
../../../external/referencesource/System.Xml.Linq/System/Xml/Linq/XLinq.cs
../../../external/referencesource/System.Xml.Linq/System/Xml/Linq/XComponentModel.cs

File diff suppressed because it is too large Load Diff

View File

@@ -1,176 +0,0 @@
//
// Authors:
// Atsushi Enomoto
//
// Copyright 2007 Novell (http://www.novell.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.Collections.Generic;
using System.Runtime.CompilerServices;
namespace System.Xml.Linq
{
public static class Extensions
{
public static IEnumerable<XElement> Ancestors<T> (this IEnumerable<T> source) where T : XNode
{
foreach (T item in source)
for (XElement n = item.Parent as XElement; n != null; n = n.Parent as XElement)
yield return n;
}
public static IEnumerable<XElement> Ancestors<T> (this IEnumerable<T> source, XName name) where T : XNode
{
foreach (T item in source)
for (XElement n = item.Parent as XElement; n != null; n = n.Parent as XElement)
if (n.Name == name)
yield return n;
}
public static IEnumerable<XElement> AncestorsAndSelf (this IEnumerable<XElement> source)
{
foreach (XElement item in source)
for (XElement n = item as XElement; n != null; n = n.Parent as XElement)
yield return n;
}
public static IEnumerable<XElement> AncestorsAndSelf (this IEnumerable<XElement> source, XName name)
{
foreach (XElement item in source)
for (XElement n = item as XElement; n != null; n = n.Parent as XElement)
if (n.Name == name)
yield return n;
}
public static IEnumerable <XAttribute> Attributes (this IEnumerable <XElement> source)
{
foreach (XElement item in source)
foreach (XAttribute attr in item.Attributes ())
yield return attr;
}
public static IEnumerable <XAttribute> Attributes (this IEnumerable <XElement> source, XName name)
{
foreach (XElement item in source)
foreach (XAttribute attr in item.Attributes (name))
yield return attr;
}
public static IEnumerable<XNode> DescendantNodes<T> (
this IEnumerable<T> source) where T : XContainer
{
foreach (XContainer item in source)
foreach (XNode n in item.DescendantNodes ())
yield return n;
}
public static IEnumerable<XNode> DescendantNodesAndSelf (
this IEnumerable<XElement> source)
{
foreach (XElement item in source)
foreach (XNode n in item.DescendantNodesAndSelf ())
yield return n;
}
public static IEnumerable<XElement> Descendants<T> (
this IEnumerable<T> source) where T : XContainer
{
foreach (XContainer item in source)
foreach (XElement n in item.Descendants ())
yield return n;
}
public static IEnumerable<XElement> Descendants<T> (
this IEnumerable<T> source, XName name) where T : XContainer
{
foreach (XContainer item in source)
foreach (XElement n in item.Descendants (name))
yield return n;
}
public static IEnumerable<XElement> DescendantsAndSelf (
this IEnumerable<XElement> source)
{
foreach (XElement item in source)
foreach (XElement n in item.DescendantsAndSelf ())
yield return n;
}
public static IEnumerable<XElement> DescendantsAndSelf (
this IEnumerable<XElement> source, XName name)
{
foreach (XElement item in source)
foreach (XElement n in item.DescendantsAndSelf (name))
yield return n;
}
public static IEnumerable<XElement> Elements<T> (
this IEnumerable<T> source) where T : XContainer
{
foreach (XContainer item in source)
foreach (XElement n in item.Elements ())
yield return n;
}
public static IEnumerable<XElement> Elements<T> (
this IEnumerable<T> source, XName name) where T : XContainer
{
foreach (XContainer item in source)
foreach (XElement n in item.Elements (name))
yield return n;
}
public static IEnumerable<T> InDocumentOrder<T> (
this IEnumerable<T> source) where T : XNode
{
List<XNode> list = new List<XNode> ();
foreach (XNode n in source)
list.Add (n);
list.Sort (XNode.DocumentOrderComparer);
foreach (T n in list)
yield return n;
}
public static IEnumerable<XNode> Nodes<T> (
this IEnumerable<T> source) where T : XContainer
{
foreach (XContainer item in source)
foreach (XNode n in item.Nodes ())
yield return n;
}
public static void Remove (this IEnumerable<XAttribute> source)
{
foreach (XAttribute item in source)
item.Remove ();
}
public static void Remove<T> (this IEnumerable<T> source) where T : XNode
{
var l = new List<T> (source);
foreach (T item in l)
item.Remove ();
}
}
}

View File

@@ -1,39 +0,0 @@
//
// Authors:
// Atsushi Enomoto
//
// Copyright 2007 Novell (http://www.novell.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;
namespace System.Xml.Linq
{
[Flags]
public enum LoadOptions
{
None = 0,
PreserveWhitespace = 1,
SetBaseUri = 2,
SetLineInfo = 4,
}
}

View File

@@ -1,34 +0,0 @@
//
//
// Copyright 2010 Novell (http://www.novell.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;
namespace System.Xml.Linq
{
[Flags]
public enum ReaderOptions
{
None = 0,
OmitDuplicateNamespaces = 1
}
}

View File

@@ -1,38 +0,0 @@
//
// Authors:
// Atsushi Enomoto
//
// Copyright 2007 Novell (http://www.novell.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;
namespace System.Xml.Linq
{
[Flags]
public enum SaveOptions
{
None = 0,
DisableFormatting = 1,
OmitDuplicateNamespaces = 2
}
}

View File

@@ -1,364 +0,0 @@
//
// Authors:
// Atsushi Enomoto
//
// Copyright 2007 Novell (http://www.novell.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.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Xml;
namespace System.Xml.Linq
{
public class XAttribute : XObject
{
static readonly XAttribute [] empty_array = new XAttribute [0];
public static IEnumerable <XAttribute> EmptySequence {
get { return empty_array; }
}
XName name;
string value;
XAttribute next;
XAttribute previous;
public XAttribute (XAttribute other)
{
if (other == null)
throw new ArgumentNullException ("other");
name = other.name;
value = other.value;
}
public XAttribute (XName name, object value)
{
if (name == null)
throw new ArgumentNullException ("name");
this.name = name;
SetValue (value);
}
[CLSCompliant (false)]
public static explicit operator bool (XAttribute attribute)
{
if (attribute == null)
throw new ArgumentNullException ("attribute");
return XUtil.ConvertToBoolean (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator bool? (XAttribute attribute)
{
if (attribute == null)
return null;
return attribute.value == null ? (bool?) null : XUtil.ConvertToBoolean (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator DateTime (XAttribute attribute)
{
if (attribute == null)
throw new ArgumentNullException ("attribute");
return XUtil.ToDateTime (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator DateTime? (XAttribute attribute)
{
if (attribute == null)
return null;
return attribute.value == null ? (DateTime?) null : XUtil.ToDateTime (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator DateTimeOffset (XAttribute attribute)
{
if (attribute == null)
throw new ArgumentNullException ("attribute");
return XmlConvert.ToDateTimeOffset (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator DateTimeOffset? (XAttribute attribute)
{
if (attribute == null)
return null;
return attribute.value == null ? (DateTimeOffset?) null : XmlConvert.ToDateTimeOffset (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator decimal (XAttribute attribute)
{
if (attribute == null)
throw new ArgumentNullException ("attribute");
return XmlConvert.ToDecimal (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator decimal? (XAttribute attribute)
{
if (attribute == null)
return null;
return attribute.value == null ? (decimal?) null : XmlConvert.ToDecimal (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator double (XAttribute attribute)
{
if (attribute == null)
throw new ArgumentNullException ("attribute");
return XmlConvert.ToDouble (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator double? (XAttribute attribute)
{
if (attribute == null)
return null;
return attribute.value == null ? (double?) null : XmlConvert.ToDouble (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator float (XAttribute attribute)
{
if (attribute == null)
throw new ArgumentNullException ("attribute");
return XmlConvert.ToSingle (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator float? (XAttribute attribute)
{
if (attribute == null)
return null;
return attribute.value == null ? (float?) null : XmlConvert.ToSingle (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator Guid (XAttribute attribute)
{
if (attribute == null)
throw new ArgumentNullException ("attribute");
return XmlConvert.ToGuid (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator Guid? (XAttribute attribute)
{
if (attribute == null)
return null;
return attribute.value == null ? (Guid?) null : XmlConvert.ToGuid (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator int (XAttribute attribute)
{
if (attribute == null)
throw new ArgumentNullException ("attribute");
return XmlConvert.ToInt32 (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator int? (XAttribute attribute)
{
if (attribute == null)
return null;
return attribute.value == null ? (int?) null : XmlConvert.ToInt32 (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator long (XAttribute attribute)
{
if (attribute == null)
throw new ArgumentNullException ("attribute");
return XmlConvert.ToInt64 (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator long? (XAttribute attribute)
{
if (attribute == null)
return null;
return attribute.value == null ? (long?) null : XmlConvert.ToInt64 (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator uint (XAttribute attribute)
{
if (attribute == null)
throw new ArgumentNullException ("attribute");
return XmlConvert.ToUInt32 (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator uint? (XAttribute attribute)
{
if (attribute == null)
return null;
return attribute.value == null ? (uint?) null : XmlConvert.ToUInt32 (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator ulong (XAttribute attribute)
{
if (attribute == null)
throw new ArgumentNullException ("attribute");
return XmlConvert.ToUInt64 (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator ulong? (XAttribute attribute)
{
if (attribute == null)
return null;
return attribute.value == null ? (ulong?) null : XmlConvert.ToUInt64 (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator TimeSpan (XAttribute attribute)
{
if (attribute == null)
throw new ArgumentNullException ("attribute");
return XmlConvert.ToTimeSpan (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator TimeSpan? (XAttribute attribute)
{
if (attribute == null)
return null;
return attribute.value == null ? (TimeSpan?) null : XmlConvert.ToTimeSpan (attribute.value);
}
[CLSCompliant (false)]
public static explicit operator string (XAttribute attribute)
{
if (attribute == null)
return null;
return attribute.value;
}
public bool IsNamespaceDeclaration {
get { return name.Namespace == XNamespace.Xmlns || (name.LocalName == "xmlns" && name.Namespace == XNamespace.None); }
}
public XName Name {
get { return name; }
}
public XAttribute NextAttribute {
get { return next; }
internal set { next = value; }
}
public override XmlNodeType NodeType {
get { return XmlNodeType.Attribute; }
}
public XAttribute PreviousAttribute {
get { return previous; }
internal set { previous = value; }
}
public string Value {
get { return XUtil.ToString (value); }
set { SetValue (value); }
}
public void Remove ()
{
if (Parent != null) {
var owner = Owner;
owner.OnRemovingObject (this);
if (next != null)
next.previous = previous;
if (previous != null)
previous.next = next;
if (Parent.FirstAttribute == this)
Parent.FirstAttribute = next;
if (Parent.LastAttribute == this)
Parent.LastAttribute = previous;
SetOwner (null);
owner.OnRemovedObject (this);
}
next = null;
previous = null;
}
public void SetValue (object value)
{
if (value == null)
throw new ArgumentNullException ("value");
OnValueChanging (this);
this.value = XUtil.ToString (value);
OnValueChanged (this);
}
static readonly char [] escapeChars = new char [] {'<', '>', '&', '"', '\r', '\n', '\t'};
private static string GetPrefixOfNamespace (XNamespace ns)
{
string namespaceName = ns.NamespaceName;
if (namespaceName.Length == 0)
return string.Empty;
if (namespaceName == XNamespace.Xml.NamespaceName)
return "xml";
if (namespaceName == XNamespace.Xmlns.NamespaceName)
return "xmlns";
return null;
}
public override string ToString ()
{
using (StringWriter sw = new StringWriter (CultureInfo.InvariantCulture)) {
XmlWriterSettings ws = new XmlWriterSettings ();
ws.ConformanceLevel = ConformanceLevel.Fragment;
using (XmlWriter w = XmlWriter.Create (sw, ws)) {
w.WriteAttributeString (GetPrefixOfNamespace (Name.Namespace), Name.LocalName,
Name.NamespaceName, Value);
}
return sw.ToString ().Trim ();
}
}
}
}

View File

@@ -1,71 +0,0 @@
//
// Authors:
// Atsushi Enomoto
//
// Copyright 2007 Novell (http://www.novell.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.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
namespace System.Xml.Linq
{
public class XCData : XText
{
public XCData (string value)
: base (value)
{
}
public XCData (XCData other)
: base (other)
{
}
public override XmlNodeType NodeType {
get { return XmlNodeType.CDATA; }
}
public override void WriteTo (XmlWriter writer)
{
int start = 0;
StringBuilder sb = null;
for (int i = 0; i < Value.Length - 2; i++) {
if (Value [i] == ']' && Value [i + 1] == ']'
&& Value [i + 2] == '>') {
if (sb == null)
sb = new StringBuilder ();
sb.Append (Value, start, i - start);
sb.Append ("]]&gt;");
start = i + 3;
}
}
if (start != 0 && start != Value.Length)
sb.Append (Value, start, Value.Length - start);
writer.WriteCData (sb == null ? Value : sb.ToString ());
}
}
}

View File

@@ -1,63 +0,0 @@
//
// Authors:
// Atsushi Enomoto
//
// Copyright 2007 Novell (http://www.novell.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.Linq;
using System.Xml;
namespace System.Xml.Linq
{
public class XComment : XNode
{
string value;
public XComment (string value)
{
this.value = value;
}
public XComment (XComment other)
{
this.value = other.value;
}
public override XmlNodeType NodeType {
get { return XmlNodeType.Comment; }
}
public string Value {
get { return value; }
set { this.value = value; }
}
public override void WriteTo (XmlWriter writer)
{
var v = value.Replace ("--", "- -");
v = v.LastOrDefault () == '-' ? v.Substring (0, v.Length - 1) +"&#2D;" : v;
writer.WriteComment (v);
}
}
}

View File

@@ -1,242 +0,0 @@
//
// Authors:
// Atsushi Enomoto
//
// Copyright 2007 Novell (http://www.novell.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.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
namespace System.Xml.Linq
{
public abstract class XContainer : XNode
{
internal XContainer ()
{
}
XNode first;
XNode last;
public XNode FirstNode {
get { return first; }
internal set { first = value; }
}
public XNode LastNode {
get { return last; }
internal set { last = value; }
}
void CheckChildType (object o, bool addFirst)
{
if (o == null || o is string || o is XNode)
return;
if (o is IEnumerable) {
foreach (object oc in ((IEnumerable) o))
CheckChildType (oc, addFirst);
return;
}
else
throw new ArgumentException ("Invalid child type: " + o.GetType ());
}
public void Add (object content)
{
if (content == null)
return;
foreach (object o in XUtil.ExpandArray (content))
{
if (o == null)
continue;
if (!OnAddingObject (o, false, last, false))
{
var node = XUtil.ToNode (o);
OnAddingObject (node);
AddNode (node);
OnAddedObject (node);
}
}
}
void AddNode (XNode n)
{
CheckChildType (n, false);
n = (XNode) XUtil.GetDetachedObject (n);
n.SetOwner (this);
if (first == null)
last = first = n;
else {
last.NextNode = n;
n.PreviousNode = last;
last = n;
}
}
public void Add (params object [] content)
{
if (content == null)
return;
foreach (object o in XUtil.ExpandArray (content))
Add (o);
}
public void AddFirst (object content)
{
if (first == null)
Add (content);
else
first.AddBeforeSelf (XUtil.ExpandArray (content));
}
public void AddFirst (params object [] content)
{
if (content == null)
return;
if (first == null)
Add (content);
else
foreach (object o in XUtil.ExpandArray (content))
if (!OnAddingObject (o, false, first.PreviousNode, true))
first.AddBeforeSelf (o);
}
internal virtual bool OnAddingObject (object o, bool rejectAttribute, XNode refNode, bool addFirst)
{
return false;
}
public XmlWriter CreateWriter ()
{
return new XNodeWriter (this);
}
public IEnumerable <XNode> Nodes ()
{
XNode next;
for (XNode n = FirstNode; n != null; n = next) {
next = n.NextNode;
yield return n;
}
}
public IEnumerable<XNode> DescendantNodes ()
{
foreach (XNode n in Nodes ()) {
yield return n;
XContainer c = n as XContainer;
if (c != null)
foreach (XNode d in c.DescendantNodes ())
yield return d;
}
}
public IEnumerable <XElement> Descendants ()
{
foreach (XNode n in DescendantNodes ()) {
XElement el = n as XElement;
if (el != null)
yield return el;
}
}
public IEnumerable <XElement> Descendants (XName name)
{
foreach (XElement el in Descendants ())
if (el.Name == name)
yield return el;
}
public IEnumerable <XElement> Elements ()
{
foreach (XNode n in Nodes ()) {
XElement el = n as XElement;
if (el != null)
yield return el;
}
}
public IEnumerable <XElement> Elements (XName name)
{
foreach (XNode n in Nodes ()) {
XElement el = n as XElement;
if (el != null && el.Name == name)
yield return el;
}
}
public XElement Element (XName name)
{
foreach (XNode n in Nodes ()) {
XElement el = n as XElement;
if (el != null && el.Name == name)
return el;
}
return null;
}
internal void ReadContentFrom (XmlReader reader, LoadOptions options)
{
while (!reader.EOF) {
if (reader.NodeType == XmlNodeType.EndElement)
// end of the element.
break;
Add (XNode.ReadFrom (reader, options));
}
}
public void RemoveNodes ()
{
foreach (XNode n in Nodes ())
n.Remove ();
}
public void ReplaceNodes (object content)
{
// First, it creates a snapshot copy, then removes the contents, and then adds the copy. http://msdn.microsoft.com/en-us/library/system.xml.linq.xcontainer.replacenodes.aspx
if (FirstNode == null) {
Add (content);
return;
}
var l = new List<object> ();
foreach (var obj in XUtil.ExpandArray (content))
l.Add (obj);
RemoveNodes ();
Add (l);
}
public void ReplaceNodes (params object [] content)
{
ReplaceNodes ((object) content);
}
}
}

View File

@@ -1,101 +0,0 @@
//
// Authors:
// Atsushi Enomoto
//
// Copyright 2007 Novell (http://www.novell.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.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
namespace System.Xml.Linq
{
public class XDeclaration
{
string encoding, standalone, version;
public XDeclaration (string version, string encoding, string standalone)
{
this.version = version;
this.encoding = encoding;
this.standalone = standalone;
}
public XDeclaration (XDeclaration other)
{
if (other == null)
throw new ArgumentNullException ("other");
this.version = other.version;
this.encoding = other.encoding;
this.standalone = other.standalone;
}
public string Encoding {
get { return encoding; }
set { encoding = value; }
}
public string Standalone {
get { return standalone; }
set { standalone = value; }
}
public string Version {
get { return version; }
set { version = value; }
}
public override string ToString ()
{
return String.Concat ("<?xml",
version != null ? " version=\"" : null,
version != null ? version : null,
version != null ? "\"" : null,
encoding != null ? " encoding=\"" : null,
encoding != null ? encoding : null,
encoding != null ? "\"" : null,
standalone != null ? " standalone=\"" : null,
standalone != null ? standalone : null,
standalone != null ? "\"" : null,
"?>");
}
/*
public override void WriteTo (XmlWriter w)
{
StringBuilder sb = new StringBuilder ();
sb.AppendFormat ("version=\"{0}\"", version);
if (encoding != null)
sb.AppendFormat (" encoding=\"{0}\"", encoding);
if (standalone != null)
sb.AppendFormat (" standalone=\"{0}\"", standalone);
// "xml" is not allowed PI, but because of nasty
// XmlWriter API design it must pass.
w.WriteProcessingInstruction ("xml", sb.ToString ());
}
*/
}
}

View File

@@ -1,286 +0,0 @@
//
// Authors:
// Atsushi Enomoto
//
// Copyright 2007 Novell (http://www.novell.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.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
namespace System.Xml.Linq
{
public class XDocument : XContainer
{
XDeclaration xmldecl;
public XDocument ()
{
}
public XDocument (params object [] content)
{
Add (content);
}
public XDocument (XDeclaration declaration, params object [] content)
{
Declaration = declaration;
Add (content);
}
public XDocument (XDocument other)
{
foreach (object o in other.Nodes ())
Add (XUtil.Clone (o));
}
public XDeclaration Declaration {
get { return xmldecl; }
set { xmldecl = value; }
}
public XDocumentType DocumentType {
get {
foreach (object o in Nodes ())
if (o is XDocumentType)
return (XDocumentType) o;
return null;
}
}
public override XmlNodeType NodeType {
get { return XmlNodeType.Document; }
}
public XElement Root {
get {
foreach (object o in Nodes ())
if (o is XElement)
return (XElement) o;
return null;
}
}
public static XDocument Load (string uri)
{
return Load (uri, LoadOptions.None);
}
public static XDocument Load (string uri, LoadOptions options)
{
XmlReaderSettings s = new XmlReaderSettings ();
s.ProhibitDtd = false; // see XNodeNavigatorTest.MoveToId().
s.IgnoreWhitespace = (options & LoadOptions.PreserveWhitespace) == 0;
using (XmlReader r = XmlReader.Create (uri, s)) {
return LoadCore (r, options);
}
}
public static XDocument Load (Stream stream)
{
return Load (new StreamReader (stream), LoadOptions.None);
}
public static XDocument Load (Stream stream, LoadOptions options)
{
return Load (new StreamReader (stream), options);
}
public static XDocument Load (TextReader textReader)
{
return Load (textReader, LoadOptions.None);
}
public static XDocument Load (TextReader textReader, LoadOptions options)
{
XmlReaderSettings s = new XmlReaderSettings ();
s.ProhibitDtd = false; // see XNodeNavigatorTest.MoveToId().
s.IgnoreWhitespace = (options & LoadOptions.PreserveWhitespace) == 0;
using (XmlReader r = XmlReader.Create (textReader, s)) {
return LoadCore (r, options);
}
}
public static XDocument Load (XmlReader reader)
{
return Load (reader, LoadOptions.None);
}
public static XDocument Load (XmlReader reader, LoadOptions options)
{
XmlReaderSettings s = reader.Settings != null ? reader.Settings.Clone () : new XmlReaderSettings ();
s.IgnoreWhitespace = (options & LoadOptions.PreserveWhitespace) == 0;
using (XmlReader r = XmlReader.Create (reader, s)) {
return LoadCore (r, options);
}
}
static XDocument LoadCore (XmlReader reader, LoadOptions options)
{
XDocument doc = new XDocument ();
doc.ReadContent (reader, options);
return doc;
}
void ReadContent (XmlReader reader, LoadOptions options)
{
if (reader.ReadState == ReadState.Initial)
reader.Read ();
this.FillLineInfoAndBaseUri (reader, options);
if (reader.NodeType == XmlNodeType.XmlDeclaration) {
Declaration = new XDeclaration (
reader.GetAttribute ("version"),
reader.GetAttribute ("encoding"),
reader.GetAttribute ("standalone"));
reader.Read ();
}
ReadContentFrom (reader, options);
if (Root == null)
throw new InvalidOperationException ("The document element is missing.");
}
static void ValidateWhitespace (string s)
{
for (int i = 0; i < s.Length; i++)
switch (s [i]) {
case ' ': case '\t': case '\n': case '\r':
continue;
default:
throw new ArgumentException ("Non-whitespace text appears directly in the document.");
}
}
public static XDocument Parse (string text)
{
return Parse (text, LoadOptions.None);
}
public static XDocument Parse (string text, LoadOptions options)
{
return Load (new StringReader (text), options);
}
public void Save (string fileName)
{
Save (fileName, SaveOptions.None);
}
public void Save (string fileName, SaveOptions options)
{
XmlWriterSettings s = new XmlWriterSettings ();
if ((options & SaveOptions.DisableFormatting) == SaveOptions.None)
s.Indent = true;
if ((options & SaveOptions.OmitDuplicateNamespaces) == SaveOptions.OmitDuplicateNamespaces)
s.NamespaceHandling |= NamespaceHandling.OmitDuplicates;
using (XmlWriter w = XmlWriter.Create (fileName, s)) {
Save (w);
}
}
public void Save (TextWriter textWriter)
{
Save (textWriter, SaveOptions.None);
}
public void Save (TextWriter textWriter, SaveOptions options)
{
XmlWriterSettings s = new XmlWriterSettings ();
if ((options & SaveOptions.DisableFormatting) == SaveOptions.None)
s.Indent = true;
if ((options & SaveOptions.OmitDuplicateNamespaces) == SaveOptions.OmitDuplicateNamespaces)
s.NamespaceHandling |= NamespaceHandling.OmitDuplicates;
using (XmlWriter w = XmlWriter.Create (textWriter, s)) {
Save (w);
}
}
public void Save (XmlWriter writer)
{
WriteTo (writer);
}
public override void WriteTo (XmlWriter writer)
{
if (xmldecl != null && xmldecl.Standalone != null)
writer.WriteStartDocument (xmldecl.Standalone == "yes");
else
writer.WriteStartDocument ();
foreach (XNode node in Nodes ())
node.WriteTo (writer);
}
internal override bool OnAddingObject (object obj, bool rejectAttribute, XNode refNode, bool addFirst)
{
VerifyAddedNode (obj, addFirst);
return false;
}
void VerifyAddedNode (object node, bool addFirst)
{
if (node == null)
throw new InvalidOperationException ("Only a node is allowed here");
if (node is string)
ValidateWhitespace ((string) node);
if (node is XText)
ValidateWhitespace (((XText) node).Value);
else if (node is XDocumentType) {
if (DocumentType != null)
throw new InvalidOperationException ("There already is another document type declaration");
if (Root != null && !addFirst)
throw new InvalidOperationException ("A document type cannot be added after the document element");
}
else if (node is XElement) {
if (Root != null)
throw new InvalidOperationException ("There already is another document element");
if (DocumentType != null && addFirst)
throw new InvalidOperationException ("An element cannot be added before the document type declaration");
}
}
public void Save (Stream stream)
{
Save (stream, SaveOptions.None);
}
public void Save (Stream stream, SaveOptions options)
{
XmlWriterSettings s = new XmlWriterSettings ();
if ((options & SaveOptions.DisableFormatting) == SaveOptions.None)
s.Indent = true;
if ((options & SaveOptions.OmitDuplicateNamespaces) == SaveOptions.OmitDuplicateNamespaces)
s.NamespaceHandling |= NamespaceHandling.OmitDuplicates;
using (var writer = XmlWriter.Create (stream, s)){
Save (writer);
}
}
}
}

View File

@@ -1,106 +0,0 @@
//
// Authors:
// Atsushi Enomoto
//
// Copyright 2007 Novell (http://www.novell.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.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
namespace System.Xml.Linq
{
public class XDocumentType : XNode
{
string name, pubid, sysid, intSubset;
public XDocumentType (string name, string publicId, string systemId, string internalSubset)
{
this.name = name;
pubid = publicId;
sysid = systemId;
intSubset = internalSubset;
}
public XDocumentType (XDocumentType other)
{
if (other == null)
throw new ArgumentNullException ("other");
name = other.name;
pubid = other.pubid;
sysid = other.sysid;
intSubset = other.intSubset;
}
public string Name {
get { return name; }
set {
if (value == null)
throw new ArgumentNullException ("value");
name = value;
}
}
public string PublicId {
get { return pubid; }
set {
if (value == null)
throw new ArgumentNullException ("value");
pubid = value;
}
}
public string SystemId {
get { return sysid; }
set {
if (value == null)
throw new ArgumentNullException ("value");
sysid = value;
}
}
public string InternalSubset {
get { return intSubset; }
set {
if (value == null)
throw new ArgumentNullException ("value");
intSubset = value;
}
}
public override XmlNodeType NodeType {
get { return XmlNodeType.DocumentType; }
}
public override void WriteTo (XmlWriter writer)
{
XDocument doc = Document;
XElement root = doc.Root;
if (root != null)
writer.WriteDocType (root.Name.LocalName, pubid, sysid, intSubset);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,137 +0,0 @@
//
// Authors:
// Atsushi Enomoto
//
// Copyright 2007 Novell (http://www.novell.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.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using XPI = System.Xml.Linq.XProcessingInstruction;
namespace System.Xml.Linq
{
/*
// Iterators
internal class XFilterIterator <T> : IEnumerable <T>
{
IEnumerable <object> source;
XName name;
public XFilterIterator (IEnumerable <object> source, XName name)
{
this.source = source;
this.name = name;
}
public IEnumerator <T> GetEnumerator ()
{
foreach (object o in source) {
if (! (o is T))
continue;
if (name != null) {
if (o is XElement) {
if (((XElement) o).Name != name)
continue;
}
else if (o is XAttribute) {
if (((XAttribute) o).Name != name)
continue;
}
}
yield return (T) o;
}
}
IEnumerator IEnumerable.GetEnumerator ()
{
return GetEnumerator ();
}
}
internal class XDescendantIterator <T> : IEnumerable <T>
{
IEnumerable <T> source;
public XDescendantIterator (IEnumerable <object> source)
{
this.source = new XFilterIterator <T> (source, null);
}
public IEnumerator <T> GetEnumerator ()
{
foreach (T t1 in source) {
yield return t1;
XContainer xc = t1 as XContainer;
if (xc == null || xc.FirstChild == null)
continue;
foreach (T t2 in new XDescendantIterator <T> (xc.Content ()))
yield return t2;
}
}
IEnumerator IEnumerable.GetEnumerator ()
{
return GetEnumerator ();
}
}
*/
#if !LIST_BASED
internal class XChildrenIterator : IEnumerable <object>
{
XContainer source;
XNode n;
public XChildrenIterator (XContainer source)
{
this.source = source;
}
public IEnumerator <object> GetEnumerator ()
{
if (n == null) {
n = source.FirstNode;
if (n == null)
yield break;
}
do {
yield return n;
n = n.NextNode;
} while (n != source.LastNode);
}
IEnumerator IEnumerable.GetEnumerator ()
{
return GetEnumerator ();
}
}
#endif
}

View File

@@ -1,170 +0,0 @@
//
// Authors:
// Atsushi Enomoto
//
// Copyright 2007 Novell (http://www.novell.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.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.Text;
using System.Xml;
using XPI = System.Xml.Linq.XProcessingInstruction;
namespace System.Xml.Linq
{
[Serializable]
public sealed class XName : IEquatable<XName>, ISerializable
{
string local;
XNamespace ns;
XName (SerializationInfo info, StreamingContext context)
{
string expandedName = info.GetString ("name");
string local, ns;
ExpandName (expandedName, out local, out ns);
this.local = local;
this.ns = XNamespace.Get (ns);
}
internal XName (string local, XNamespace ns)
{
this.local = XmlConvert.VerifyNCName (local);
this.ns = ns;
}
static Exception ErrorInvalidExpandedName ()
{
return new ArgumentException ("Invalid expanded name.");
}
public string LocalName {
get { return local; }
}
public XNamespace Namespace {
get { return ns; }
}
public string NamespaceName {
get { return ns.NamespaceName; }
}
public override bool Equals (object obj)
{
XName n = obj as XName;
return n != null && this == n;
}
bool IEquatable<XName>.Equals (XName other)
{
return this == other;
}
public static XName Get (string expandedName)
{
string local, ns;
ExpandName (expandedName, out local, out ns);
return Get (local, ns);
}
static void ExpandName (string expandedName, out string local, out string ns)
{
if (expandedName == null)
throw new ArgumentNullException ("expandedName");
ns = null;
local = null;
if (expandedName.Length == 0)
throw ErrorInvalidExpandedName ();
//this.expanded = expandedName;
if (expandedName [0] == '{') {
for (int i = 1; i < expandedName.Length; i++) {
if (expandedName [i] == '}')
ns = expandedName.Substring (1, i - 1);
}
if (String.IsNullOrEmpty (ns)) // {}foo is invalid
throw ErrorInvalidExpandedName ();
if (expandedName.Length == ns.Length + 2) // {foo} is invalid
throw ErrorInvalidExpandedName ();
local = expandedName.Substring (ns.Length + 2);
}
else {
local = expandedName;
ns = String.Empty;
}
}
public static XName Get (string localName, string namespaceName)
{
return XNamespace.Get (namespaceName).GetName (localName);
}
public override int GetHashCode ()
{
return local.GetHashCode () ^ ns.GetHashCode ();
}
public static bool operator == (XName left, XName right)
{
if ((object) left == null)
return (object) right == null;
else if ((object) right == null)
return false;
return object.ReferenceEquals (left, right) ||
left.local == right.local && left.ns == right.ns;
}
[CLSCompliant (false)]
public static implicit operator XName (string expandedName)
{
return expandedName == null ? null : Get (expandedName);
}
public static bool operator != (XName left, XName right)
{
return ! (left == right);
}
public override string ToString ()
{
if (Object.ReferenceEquals (ns, XNamespace.None))
return local;
return String.Concat ("{", ns.NamespaceName, "}", local);
}
// in .NET it is serialized as "NameSerializer". dunno how to create it.
void ISerializable.GetObjectData (SerializationInfo info, StreamingContext context)
{
if (info == null)
throw new ArgumentNullException ("info");
info.AddValue ("name", ToString ());
}
}
}

View File

@@ -1,141 +0,0 @@
//
// Authors:
// Atsushi Enomoto
//
// Copyright 2007 Novell (http://www.novell.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.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
namespace System.Xml.Linq
{
public sealed class XNamespace
{
static readonly XNamespace blank, xml, xmlns;
static Dictionary<string, XNamespace> nstable;
static XNamespace ()
{
nstable = new Dictionary<string, XNamespace> ();
blank = Get (String.Empty);
xml = Get ("http://www.w3.org/XML/1998/namespace");
xmlns = Get ("http://www.w3.org/2000/xmlns/");
}
public static XNamespace None {
get { return blank; }
}
public static XNamespace Xml {
get { return xml; }
}
public static XNamespace Xmlns {
get { return xmlns; }
}
public static XNamespace Get (string namespaceName)
{
lock (nstable) {
XNamespace ret;
if (!nstable.TryGetValue (namespaceName, out ret)) {
ret = new XNamespace (namespaceName);
nstable [namespaceName] = ret;
}
return ret;
}
}
public XName GetName (string localName)
{
lock (nstable) {
if (table == null)
table = new Dictionary<string, XName> ();
XName ret;
if (!table.TryGetValue (localName, out ret)) {
ret = new XName (localName, this);
table [localName] = ret;
}
return ret;
}
}
string uri;
Dictionary<string, XName> table;
XNamespace (string namespaceName)
{
if (namespaceName == null)
throw new ArgumentNullException ("namespaceName");
uri = namespaceName;
}
public string NamespaceName {
get { return uri; }
}
public override bool Equals (object obj)
{
if (Object.ReferenceEquals (this, obj))
return true;
XNamespace ns = obj as XNamespace;
return ns != null && uri == ns.uri;
}
public static bool operator == (XNamespace left, XNamespace right)
{
return (object) left != null ? left.Equals (right) : (object) right == null;
}
public static bool operator != (XNamespace left, XNamespace right)
{
return ! (left == right);
}
public static XName operator + (XNamespace ns, string localName)
{
return new XName (localName, ns);
}
[CLSCompliant (false)]
public static implicit operator XNamespace (string namespaceName)
{
return namespaceName != null ? XNamespace.Get (namespaceName) : null;
}
public override int GetHashCode ()
{
return uri.GetHashCode ();
}
public override string ToString ()
{
return uri;
}
}
}

View File

@@ -1,345 +0,0 @@
//
// Authors:
// Atsushi Enomoto
//
// Copyright 2007 Novell (http://www.novell.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.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using XPI = System.Xml.Linq.XProcessingInstruction;
namespace System.Xml.Linq
{
public abstract class XNode : XObject
{
public static int CompareDocumentOrder (XNode n1, XNode n2)
{
return order_comparer.Compare (n1, n2);
}
public static bool DeepEquals (XNode n1, XNode n2)
{
return eq_comparer.Equals (n1, n2);
}
static XNodeEqualityComparer eq_comparer =
new XNodeEqualityComparer ();
static XNodeDocumentOrderComparer order_comparer =
new XNodeDocumentOrderComparer ();
XNode previous;
XNode next;
internal XNode ()
{
}
public static XNodeDocumentOrderComparer DocumentOrderComparer {
get { return order_comparer; }
}
public static XNodeEqualityComparer EqualityComparer {
get { return eq_comparer; }
}
public XNode PreviousNode {
get { return previous; }
internal set { previous = value; }
}
public XNode NextNode {
get { return next; }
internal set { next = value; }
}
public string ToString (SaveOptions options)
{
StringWriter sw = new StringWriter ();
XmlWriterSettings s = new XmlWriterSettings () {
ConformanceLevel = ConformanceLevel.Auto,
Indent = options != SaveOptions.DisableFormatting,
OmitXmlDeclaration = true };
XmlWriter xw = XmlWriter.Create (sw, s);
WriteTo (xw);
xw.Close ();
return sw.ToString ();
}
public void AddAfterSelf (object content)
{
if (Owner == null)
throw new InvalidOperationException ();
XNode here = this;
XNode orgNext = next;
foreach (object o in XUtil.ExpandArray (content)) {
if (o == null || Owner.OnAddingObject (o, true, here, false))
continue;
XNode n = XUtil.ToNode (o);
Owner.OnAddingObject (n);
n = (XNode) XUtil.GetDetachedObject (n);
n.SetOwner (Owner);
n.previous = here;
here.next = n;
n.next = orgNext;
if (orgNext != null)
orgNext.previous = n;
else
Owner.LastNode = n;
here = n;
Owner.OnAddedObject (n);
}
}
public void AddAfterSelf (params object [] content)
{
if (Owner == null)
throw new InvalidOperationException ();
AddAfterSelf ((object) content);
}
public void AddBeforeSelf (object content)
{
if (Owner == null)
throw new InvalidOperationException ();
foreach (object o in XUtil.ExpandArray (content)) {
if (o == null || Owner.OnAddingObject (o, true, previous, true))
continue;
XNode n = XUtil.ToNode (o);
Owner.OnAddingObject (n);
n = (XNode) XUtil.GetDetachedObject (n);
n.SetOwner (Owner);
n.previous = previous;
n.next = this;
if (previous != null)
previous.next = n;
previous = n;
if (Owner.FirstNode == this)
Owner.FirstNode = n;
Owner.OnAddedObject (n);
}
}
public void AddBeforeSelf (params object [] content)
{
if (Owner == null)
throw new InvalidOperationException ();
AddBeforeSelf ((object) content);
}
public static XNode ReadFrom (XmlReader reader)
{
return ReadFrom (reader, LoadOptions.None);
}
internal static XNode ReadFrom (XmlReader r, LoadOptions options)
{
switch (r.NodeType) {
case XmlNodeType.Element:
return XElement.LoadCore (r, options);
case XmlNodeType.Whitespace:
case XmlNodeType.SignificantWhitespace:
case XmlNodeType.Text:
XText t = new XText (r.Value);
t.FillLineInfoAndBaseUri (r, options);
r.Read ();
return t;
case XmlNodeType.CDATA:
XCData c = new XCData (r.Value);
c.FillLineInfoAndBaseUri (r, options);
r.Read ();
return c;
case XmlNodeType.ProcessingInstruction:
XPI pi = new XPI (r.Name, r.Value);
pi.FillLineInfoAndBaseUri (r, options);
r.Read ();
return pi;
case XmlNodeType.Comment:
XComment cm = new XComment (r.Value);
cm.FillLineInfoAndBaseUri (r, options);
r.Read ();
return cm;
case XmlNodeType.DocumentType:
XDocumentType d = new XDocumentType (r.Name,
r.GetAttribute ("PUBLIC"),
r.GetAttribute ("SYSTEM"),
r.Value);
d.FillLineInfoAndBaseUri (r, options);
r.Read ();
return d;
default:
throw new InvalidOperationException (String.Format ("Node type {0} is not supported", r.NodeType));
}
}
public void Remove ()
{
if (Owner == null)
throw new InvalidOperationException ("Owner is missing");
var owner = Owner;
owner.OnRemovingObject (this);
if (Owner.FirstNode == this)
Owner.FirstNode = next;
if (Owner.LastNode == this)
Owner.LastNode = previous;
if (previous != null)
previous.next = next;
if (next != null)
next.previous = previous;
previous = null;
next = null;
SetOwner (null);
owner.OnRemovedObject (this);
}
public override string ToString ()
{
return ToString (SaveOptions.None);
}
public abstract void WriteTo (XmlWriter writer);
public IEnumerable<XElement> Ancestors ()
{
for (XElement el = Parent; el != null; el = el.Parent)
yield return el;
}
public IEnumerable<XElement> Ancestors (XName name)
{
foreach (XElement el in Ancestors ())
if (el.Name == name)
yield return el;
}
public XmlReader CreateReader ()
{
return new XNodeReader (this);
}
public XmlReader CreateReader (ReaderOptions readerOptions)
{
var r = new XNodeReader (this);
if ((readerOptions & ReaderOptions.OmitDuplicateNamespaces) != 0)
r.OmitDuplicateNamespaces = true;
return r;
}
public IEnumerable<XElement> ElementsAfterSelf ()
{
foreach (XNode n in NodesAfterSelf ())
if (n is XElement)
yield return (XElement) n;
}
public IEnumerable<XElement> ElementsAfterSelf (XName name)
{
foreach (XElement el in ElementsAfterSelf ())
if (el.Name == name)
yield return el;
}
public IEnumerable<XElement> ElementsBeforeSelf ()
{
foreach (XNode n in NodesBeforeSelf ())
if (n is XElement)
yield return (XElement) n;
}
public IEnumerable<XElement> ElementsBeforeSelf (XName name)
{
foreach (XElement el in ElementsBeforeSelf ())
if (el.Name == name)
yield return el;
}
public bool IsAfter (XNode node)
{
return XNode.DocumentOrderComparer.Compare (this, node) > 0;
}
public bool IsBefore (XNode node)
{
return XNode.DocumentOrderComparer.Compare (this, node) < 0;
}
public IEnumerable<XNode> NodesAfterSelf ()
{
if (Owner == null)
yield break;
for (XNode n = NextNode; n != null; n = n.NextNode)
yield return n;
}
public IEnumerable<XNode> NodesBeforeSelf ()
{
if (Owner == null)
yield break;
for (XNode n = Owner.FirstNode; n != this; n = n.NextNode)
yield return n;
}
public void ReplaceWith (object content)
{
if (Owner == null)
throw new InvalidOperationException ();
XNode here = previous;
XNode orgNext = next;
XContainer orgOwner = Owner;
Remove();
foreach (object o in XUtil.ExpandArray (content)) {
if (o == null || orgOwner.OnAddingObject (o, true, here, false))
continue;
XNode n = XUtil.ToNode (o);
n = (XNode) XUtil.GetDetachedObject (n);
n.SetOwner (orgOwner);
n.previous = here;
if (here != null)
here.next = n;
else
orgOwner.FirstNode = n;
n.next = orgNext;
if (orgNext != null)
orgNext.previous = n;
else
orgOwner.LastNode = n;
here = n;
}
}
public void ReplaceWith (params object [] content)
{
if (Owner == null)
throw new InvalidOperationException ();
ReplaceWith ((object) content);
}
}
}

View File

@@ -1,155 +0,0 @@
//
// Authors:
// Atsushi Enomoto
//
// Copyright 2007 Novell (http://www.novell.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.Collections.Generic;
namespace System.Xml.Linq
{
public sealed class XNodeDocumentOrderComparer : IComparer, IComparer<XNode>
{
public XNodeDocumentOrderComparer ()
{
}
enum CompareResult
{
Same,
Random,
Parent,
Child,
Ancestor,
Descendant,
Preceding,
Following
}
public int Compare (XNode x, XNode y)
{
switch (CompareCore (x,y)) {
case CompareResult.Same:
return 0;
case CompareResult.Random:
return DateTime.Now.Ticks % 2 == 1 ? 1 : -1;
case CompareResult.Parent:
case CompareResult.Ancestor:
case CompareResult.Preceding:
return 1;
default:
return -1;
}
}
CompareResult CompareCore (XNode n1, XNode n2)
{
if (n1 == n2)
return CompareResult.Same;
if (n1.Owner == null) {
if (n2.Owner == null)
// n1 and n2 do not share the same
// top-level node, so return semi-
// random value.
return CompareResult.Random;
CompareResult result = CompareCore (n1, n2.Owner);
switch (result) {
case CompareResult.Same:
return CompareResult.Child;
case CompareResult.Child:
case CompareResult.Descendant:
return CompareResult.Descendant;
case CompareResult.Parent:
case CompareResult.Ancestor:
throw new Exception ("INTERNAL ERROR: should not happen");
default:
return result;
}
}
// else
if (n2.Owner == null) {
// do reverse
CompareResult rev = CompareCore (n2, n1);
switch (rev) {
case CompareResult.Parent:
return CompareResult.Child;
case CompareResult.Child:
return CompareResult.Parent;
case CompareResult.Ancestor:
return CompareResult.Descendant;
case CompareResult.Descendant:
return CompareResult.Ancestor;
case CompareResult.Following:
return CompareResult.Preceding;
case CompareResult.Preceding:
return CompareResult.Following;
case CompareResult.Same:
case CompareResult.Random:
return rev;
}
}
// both have parents
CompareResult ret = CompareCore (n1.Owner, n2.Owner);
switch (ret) {
case CompareResult.Same:
// n1 and n2 are sibling each other.
return CompareSibling (n1, n2, CompareResult.Same);
case CompareResult.Child:
return CompareSibling (n1, n2.Owner, CompareResult.Child);
case CompareResult.Parent:
return CompareSibling (n1.Owner, n2, CompareResult.Parent);
case CompareResult.Descendant:
for (XNode i2 = n2; ; i2 = i2.Owner)
if (i2.Owner == n1.Owner)
return CompareSibling (n1, i2, CompareResult.Descendant);
case CompareResult.Ancestor:
for (XNode i1 = n1; ; i1 = i1.Owner)
if (i1.Owner == n2.Owner)
return CompareSibling (i1, n2, CompareResult.Ancestor);
default:
return ret;
}
}
// results are returned as following/preceding, as it is also
// used for comparing parents.
CompareResult CompareSibling (XNode n1, XNode n2, CompareResult forSameValue)
{
if (n1 == n2)
return forSameValue;
for (XNode n = n1.NextNode; n != null; n = n.NextNode)
if (n == n2)
return CompareResult.Following;
return CompareResult.Preceding;
}
int IComparer.Compare (object n1, object n2)
{
return Compare ((XNode) n1, (XNode) n2);
}
}
}

Some files were not shown because too many files have changed in this diff Show More