Author: atsushi
Date: 2008-02-11 06:01:37 -0500 (Mon, 11 Feb 2008)
New Revision: 95429
Added:
trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XObjectTest.cs
Modified:
trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog
trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs
trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XDocument.cs
trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XElement.cs
trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XNode.cs
trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XObject.cs
trunk/mcs/class/System.Xml.Linq/System.Xml.Linq_test.dll.sources
trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
Log:
2008-02-11 Atsushi Enomoto <[EMAIL PROTECTED]>
* XNode.cs XElement.cs XObject.cs XDocument.cs XContainer.cs :
support LoadOptions.SetLineInfo and LoadOptions.SetBaseUri.
* XObjectTest.cs : new. Test IXmlLineInfo.
Modified: trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog
===================================================================
--- trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog 2008-02-11
09:45:43 UTC (rev 95428)
+++ trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/ChangeLog 2008-02-11
11:01:37 UTC (rev 95429)
@@ -1,5 +1,10 @@
2008-02-11 Atsushi Enomoto <[EMAIL PROTECTED]>
+ * XNode.cs XElement.cs XObject.cs XDocument.cs XContainer.cs :
+ support LoadOptions.SetLineInfo and LoadOptions.SetBaseUri.
+
+2008-02-11 Atsushi Enomoto <[EMAIL PROTECTED]>
+
* XNodeNavigator.cs : oops, MoveToNext() always returned false.
2008-02-11 Miguel de Icaza <[EMAIL PROTECTED]>
Modified: trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs
===================================================================
--- trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs
2008-02-11 09:45:43 UTC (rev 95428)
+++ trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XContainer.cs
2008-02-11 11:01:37 UTC (rev 95429)
@@ -182,13 +182,13 @@
return null;
}
- internal void ReadContentFrom (XmlReader reader)
+ internal void ReadContentFrom (XmlReader reader, LoadOptions
options)
{
while (!reader.EOF) {
if (reader.NodeType == XmlNodeType.EndElement)
// end of the element.
break;
- Add (XNode.ReadFrom (reader));
+ Add (XNode.ReadFrom (reader, options));
}
}
Modified: trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XDocument.cs
===================================================================
--- trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XDocument.cs
2008-02-11 09:45:43 UTC (rev 95428)
+++ trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XDocument.cs
2008-02-11 11:01:37 UTC (rev 95429)
@@ -97,7 +97,7 @@
XmlReaderSettings s = new XmlReaderSettings ();
s.IgnoreWhitespace = (options &
LoadOptions.PreserveWhitespace) == 0;
using (XmlReader r = XmlReader.Create (uri, s)) {
- return LoadCore (r);
+ return LoadCore (r, options);
}
}
@@ -111,7 +111,7 @@
XmlReaderSettings s = new XmlReaderSettings ();
s.IgnoreWhitespace = (options &
LoadOptions.PreserveWhitespace) == 0;
using (XmlReader r = XmlReader.Create (reader, s)) {
- return LoadCore (r);
+ return LoadCore (r, options);
}
}
@@ -125,18 +125,18 @@
XmlReaderSettings s = reader.Settings.Clone ();
s.IgnoreWhitespace = (options &
LoadOptions.PreserveWhitespace) == 0;
using (XmlReader r = XmlReader.Create (reader, s)) {
- return LoadCore (r);
+ return LoadCore (r, options);
}
}
- static XDocument LoadCore (XmlReader reader)
+ static XDocument LoadCore (XmlReader reader, LoadOptions
options)
{
XDocument doc = new XDocument ();
- doc.ReadContent (reader);
+ doc.ReadContent (reader, options);
return doc;
}
- void ReadContent (XmlReader reader)
+ void ReadContent (XmlReader reader, LoadOptions options)
{
if (reader.ReadState == ReadState.Initial)
reader.Read ();
@@ -147,7 +147,7 @@
reader.GetAttribute ("standalone"));
reader.Read ();
}
- ReadContentFrom (reader);
+ ReadContentFrom (reader, options);
if (Root == null)
throw new InvalidOperationException ("The
document element is missing.");
}
Modified: trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XElement.cs
===================================================================
--- trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XElement.cs 2008-02-11
09:45:43 UTC (rev 95428)
+++ trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XElement.cs 2008-02-11
11:01:37 UTC (rev 95429)
@@ -358,7 +358,7 @@
XmlReaderSettings s = new XmlReaderSettings ();
s.IgnoreWhitespace = (options &
LoadOptions.PreserveWhitespace) == 0;
using (XmlReader r = XmlReader.Create (uri, s)) {
- return LoadCore (r);
+ return LoadCore (r, options);
}
}
@@ -372,7 +372,7 @@
XmlReaderSettings s = new XmlReaderSettings ();
s.IgnoreWhitespace = (options &
LoadOptions.PreserveWhitespace) == 0;
using (XmlReader r = XmlReader.Create (tr, s)) {
- return LoadCore (r);
+ return LoadCore (r, options);
}
}
@@ -386,17 +386,19 @@
XmlReaderSettings s = reader.Settings.Clone ();
s.IgnoreWhitespace = (options &
LoadOptions.PreserveWhitespace) == 0;
using (XmlReader r = XmlReader.Create (reader, s)) {
- return LoadCore (r);
+ return LoadCore (r, options);
}
}
- static XElement LoadCore (XmlReader r)
+ static XElement LoadCore (XmlReader r, LoadOptions options)
{
r.MoveToContent ();
if (r.NodeType != XmlNodeType.Element)
throw new InvalidOperationException ("The
XmlReader must be positioned at an element");
XName name = XName.Get (r.LocalName, r.NamespaceURI);
XElement e = new XElement (name);
+ e.FillLineInfoAndBaseUri (r, options);
+
if (r.MoveToFirstAttribute ()) {
do {
// not sure how current Orcas behavior
makes sense here though ...
@@ -404,12 +406,13 @@
e.SetAttributeValue
(XNamespace.None.GetName ("xmlns"), r.Value);
else
e.SetAttributeValue (XName.Get
(r.LocalName, r.NamespaceURI), r.Value);
+ e.LastAttribute.FillLineInfoAndBaseUri
(r, options);
} while (r.MoveToNextAttribute ());
r.MoveToElement ();
}
if (!r.IsEmptyElement) {
r.Read ();
- e.ReadContentFrom (r);
+ e.ReadContentFrom (r, options);
r.ReadEndElement ();
e.explicit_is_empty = false;
} else {
@@ -651,7 +654,7 @@
void IXmlSerializable.ReadXml (XmlReader reader)
{
- ReadContentFrom (reader);
+ ReadContentFrom (reader, LoadOptions.None);
}
XmlSchema IXmlSerializable.GetSchema ()
Modified: trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XNode.cs
===================================================================
--- trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XNode.cs 2008-02-11
09:45:43 UTC (rev 95428)
+++ trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XNode.cs 2008-02-11
11:01:37 UTC (rev 95429)
@@ -145,25 +145,34 @@
public static XNode ReadFrom (XmlReader r)
{
+ return ReadFrom (r, LoadOptions.None);
+ }
+
+ internal static XNode ReadFrom (XmlReader r, LoadOptions
options)
+ {
switch (r.NodeType) {
case XmlNodeType.Element:
- return XElement.Load (r);
+ return XElement.Load (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:
@@ -171,10 +180,11 @@
r.GetAttribute ("PUBLIC"),
r.GetAttribute ("System"),
r.Value);
+ d.FillLineInfoAndBaseUri (r, options);
r.Read ();
return d;
default:
- throw new NotSupportedException (String.Format
("Node type {0} is not supported", r.NodeType));
+ throw new InvalidOperationException
(String.Format ("Node type {0} is not supported", r.NodeType));
}
}
Modified: trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XObject.cs
===================================================================
--- trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XObject.cs 2008-02-11
09:45:43 UTC (rev 95428)
+++ trunk/mcs/class/System.Xml.Linq/System.Xml.Linq/XObject.cs 2008-02-11
11:01:37 UTC (rev 95429)
@@ -128,20 +128,40 @@
annotations.RemoveAt (i);
}
- [MonoTODO]
- int IXmlLineInfo.LineNumber {
+ internal int LineNumber {
get { return line; }
+ set { line = value; }
}
- [MonoTODO]
- int IXmlLineInfo.LinePosition {
+ internal int LinePosition {
get { return column; }
+ set { column = value; }
}
- [MonoTODO]
+ int IXmlLineInfo.LineNumber {
+ get { return LineNumber; }
+ }
+
+ int IXmlLineInfo.LinePosition {
+ get { return LinePosition; }
+ }
+
bool IXmlLineInfo.HasLineInfo ()
{
return line > 0;
}
+
+ internal void FillLineInfoAndBaseUri (XmlReader r, LoadOptions
options)
+ {
+ if ((options & LoadOptions.SetLineInfo) !=
LoadOptions.None) {
+ IXmlLineInfo li = r as IXmlLineInfo;
+ if (li != null && li.HasLineInfo ()) {
+ LineNumber = li.LineNumber;
+ LinePosition = li.LinePosition;
+ }
+ }
+ if ((options & LoadOptions.SetBaseUri) !=
LoadOptions.None)
+ BaseUri = r.BaseURI;
+ }
}
}
Modified: trunk/mcs/class/System.Xml.Linq/System.Xml.Linq_test.dll.sources
===================================================================
--- trunk/mcs/class/System.Xml.Linq/System.Xml.Linq_test.dll.sources
2008-02-11 09:45:43 UTC (rev 95428)
+++ trunk/mcs/class/System.Xml.Linq/System.Xml.Linq_test.dll.sources
2008-02-11 11:01:37 UTC (rev 95429)
@@ -9,5 +9,6 @@
System.Xml.Linq/XNodeNavigatorTest.cs
System.Xml.Linq/XNodeReaderTest.cs
System.Xml.Linq/XNodeWriterTest.cs
+System.Xml.Linq/XObjectTest.cs
System.Xml.Linq/XProcessingInstructionTest.cs
System.Xml.Linq/XTextTest.cs
Modified: trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
===================================================================
--- trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
2008-02-11 09:45:43 UTC (rev 95428)
+++ trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/ChangeLog
2008-02-11 11:01:37 UTC (rev 95429)
@@ -1,5 +1,9 @@
2008-02-11 Atsushi Enomoto <[EMAIL PROTECTED]>
+ * XObjectTest.cs : new. Test IXmlLineInfo.
+
+2008-02-11 Atsushi Enomoto <[EMAIL PROTECTED]>
+
* XNodeNavigatorTest.cs : new test (but it does not build yet).
2008-02-10 Atsushi Enomoto <[EMAIL PROTECTED]>
Added: trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XObjectTest.cs
===================================================================
--- trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XObjectTest.cs
2008-02-11 09:45:43 UTC (rev 95428)
+++ trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XObjectTest.cs
2008-02-11 11:01:37 UTC (rev 95429)
@@ -0,0 +1,74 @@
+//
+// 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.IO;
+using System.Xml;
+using System.Xml.Linq;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml.Linq
+{
+ [TestFixture]
+ public class XObjectTest
+ {
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void ReadFromInitial ()
+ {
+ // must be Interactive
+ XNode.ReadFrom (XmlReader.Create (new StringReader
("<root />")));
+ }
+
+ [Test]
+ public void ReadFromElement ()
+ {
+ var r = XmlReader.Create (new StringReader
("<root><foo/></root>"));
+ r.MoveToContent ();
+ XElement el = XNode.ReadFrom (r) as XElement;
+ Assert.IsNotNull (el, "#1");
+ Assert.IsFalse (((IXmlLineInfo) el).HasLineInfo (),
"#2");
+ }
+
+ [Test]
+ public void LineInfo ()
+ {
+ // must be Interactive
+ var r = XmlReader.Create (new StringReader ("<root><foo
x='y'/></root>"));
+ XElement el = XElement.Load (r,
LoadOptions.SetLineInfo) as XElement;
+ IXmlLineInfo li = el as IXmlLineInfo;
+ Assert.AreEqual (1, li.LineNumber, "#1");
+ Assert.AreEqual (2, li.LinePosition, "#2");
+ li = el.FirstNode as IXmlLineInfo;
+ Assert.AreEqual (1, li.LineNumber, "#3");
+ Assert.AreEqual (8, li.LinePosition, "#4");
+ li = ((XElement) el.FirstNode).FirstAttribute as
IXmlLineInfo;
+ Assert.AreEqual (1, li.LineNumber, "#5");
+ Assert.AreEqual (12, li.LinePosition, "#6");
+ }
+ }
+}
Property changes on:
trunk/mcs/class/System.Xml.Linq/Test/System.Xml.Linq/XObjectTest.cs
___________________________________________________________________
Name: svn:eol-style
+ native
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches