+2006-12-05 Atsushi Enomoto <atsushi@ximian.com>
+
+ * XPathEditableDocument.cs : those writers should lookup prefix when
+ WriteStartElement/WriteStartAttribute are passed null prefix.
+ Removed nodeStack in XmlDocumentInsertionWriter, since nodes are
+ always added to current node immediately.
+
2006-11-10 Atsushi Enomoto <atsushi@ximian.com>
* XPathNavigatorReader.cs : removed node type restriction on
XmlNode parent;
XmlNode current;
XmlNode nextSibling;
- Stack nodeStack = new Stack ();
+ WriteState state;
+ XmlAttribute attribute;
public XmlDocumentInsertionWriter (XmlNode owner, XmlNode nextSibling)
{
state = WriteState.Content;
}
- WriteState state;
- XmlAttribute attribute;
-
public override WriteState WriteState {
get { return state; }
}
public override void Close ()
{
- while (nodeStack.Count > 0) {
- XmlNode n = nodeStack.Pop () as XmlNode;
- n.AppendChild (current);
- current = n;
- }
+ while (current.ParentNode != null)
+ current = current.ParentNode;
+
parent.InsertBefore ((XmlDocumentFragment) current, nextSibling);
if (Closed != null)
Closed (this);
internal event XmlWriterClosedEventHandler Closed;
- internal XmlNode AppendedFirstChild;
-
public override void Flush ()
{
}
{
if (state != WriteState.Content)
throw new InvalidOperationException ("Current state is not inside element. Cannot start attribute.");
+ if (prefix == null && ns != null && ns.Length > 0)
+ prefix = LookupPrefix (ns);
attribute = current.OwnerDocument.CreateAttribute (prefix, name, ns);
state = WriteState.Attribute;
}
public override void WriteStartElement (string prefix, string name, string ns)
{
+ if (prefix == null && ns != null && ns.Length > 0)
+ prefix = LookupPrefix (ns);
XmlElement el = current.OwnerDocument.CreateElement (prefix, name, ns);
current.AppendChild (el);
- nodeStack.Push (current);
current = el;
}
public override void WriteEndElement ()
{
- if (nodeStack.Count == 0)
+ current = current.ParentNode;
+ if (current == null)
throw new InvalidOperationException ("No element is opened.");
- current = nodeStack.Pop () as XmlNode;
}
public override void WriteFullEndElement ()
internal class XmlDocumentAttributeWriter : XmlWriter
{
XmlElement element;
+ WriteState state;
+ XmlAttribute attribute;
public XmlDocumentAttributeWriter (XmlNode owner)
{
state = WriteState.Content;
}
- WriteState state;
- XmlAttribute attribute;
-
public override WriteState WriteState {
get { return state; }
}
{
if (state != WriteState.Content)
throw new InvalidOperationException ("Current state is not inside element. Cannot start attribute.");
+ if (prefix == null && ns != null && ns.Length > 0)
+ prefix = LookupPrefix (ns);
attribute = element.OwnerDocument.CreateAttribute (prefix, name, ns);
state = WriteState.Attribute;
}
+2006-12-05 Atsushi Enomoto <atsushi@ximian.com>
+
+ * XmlNode.cs : GetPrefixOfNamespace() was not correctly searching
+ ancestors' namespaces.
+
2006-11-20 Atsushi Enomoto <atsushi@ximian.com>
* XmlTextWriter2.cs : fixed some relationship between
while (node != null) {
if (node.Prefix == prefix)
return node.NamespaceURI;
- if (node.Attributes != null) {
+ if (node.NodeType == XmlNodeType.Element &&
+ ((XmlElement) node).HasAttributes) {
int count = node.Attributes.Count;
for (int i = 0; i < count; i++) {
XmlAttribute attr = node.Attributes [i];
break;
}
- while (node != null && node.Attributes != null) {
- for (int i = 0; i < Attributes.Count; i++) {
- XmlAttribute attr = Attributes [i];
- if (attr.Prefix == "xmlns" && attr.Value == namespaceURI)
- return attr.LocalName;
- else if (attr.Name == "xmlns" && attr.Value == namespaceURI)
- return String.Empty;
+ while (node != null) {
+ if (node.NodeType == XmlNodeType.Element &&
+ ((XmlElement) node).HasAttributes) {
+ for (int i = 0; i < node.Attributes.Count; i++) {
+ XmlAttribute attr = node.Attributes [i];
+ if (attr.Prefix == "xmlns" && attr.Value == namespaceURI)
+ return attr.LocalName;
+ else if (attr.Name == "xmlns" && attr.Value == namespaceURI)
+ return String.Empty;
+ }
}
node = node.ParentNode;
}
+2006-12-05 Atsushi Enomoto <atsushi@ximian.com>
+
+ * XPathNavigatorTests.cs : added test for XPath navigator editor's
+ LookupPrefix().
+
2006-11-10 Atsushi Enomoto <atsushi@ximian.com>
* XPathNavigatorTests.cs : added test for bug #79875, and some
// Authors:
// Jason Diamond <jason@injektilo.org>
// Martin Willemoes Hansen <mwh@sysrq.dk>
+// Atsushi Enomoto <atsushi@ximian.com>
//
// (C) 2002 Jason Diamond
// (C) 2003 Martin Willemoes Hansen
+// (C) 2004-2006 Novell, Inc.
//
using System;
iter.MoveNext ();
AssertEquals ("val"1 >", iter.Current.InnerXml);
}
+
+ [Test]
+ public void WriterAttributePrefix ()
+ {
+ XmlDocument doc = new XmlDocument ();
+ XmlWriter w = doc.CreateNavigator ().AppendChild ();
+ w.WriteStartElement ("foo");
+ w.WriteAttributeString ("xmlns", "x", "http://www.w3.org/2000/xmlns/", "urn:foo");
+ AssertEquals ("#0", "x", w.LookupPrefix ("urn:foo"));
+ w.WriteStartElement (null, "bar", "urn:foo");
+ w.WriteAttributeString (null, "ext", "urn:foo", "bah");
+ w.WriteEndElement ();
+ w.WriteEndElement ();
+ w.Close ();
+ AssertEquals ("#1", "x", doc.FirstChild.FirstChild.Prefix);
+ AssertEquals ("#2", "x", doc.FirstChild.FirstChild.Attributes [0].Prefix);
+ }
#endif
}
}
+2006-12-05 Atsushi Enomoto <atsushi@ximian.com>
+
+ * XmlNodeTests.cs : added another test for GetPrefixOfNamespace().
+
2006-11-20 Atsushi Enomoto <atsushi@ximian.com>
* XmlWriterSettingsTests.cs : added tests for relationship between
AssertEquals (String.Empty, n.GetPrefixOfNamespace ("foo"));
}
+ [Test]
+ public void GetPrefixOfNamespace2 ()
+ {
+ XmlDocument doc = new XmlDocument ();
+ doc.AppendChild (doc.CreateElement ("foo"));
+ doc.DocumentElement.SetAttributeNode (
+ doc.CreateAttribute ("xmlns", "u", "http://www.w3.org/2000/xmlns/"));
+ doc.DocumentElement.Attributes [0].Value = "urn:foo";
+ XmlElement el = doc.CreateElement ("bar");
+ doc.DocumentElement.AppendChild (el);
+ AssertEquals ("u", el.GetPrefixOfNamespace ("urn:foo"));
+ }
+
[Test]
public void ReplaceChild ()
{