2006-04-19 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Wed, 19 Apr 2006 11:18:36 +0000 (11:18 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Wed, 19 Apr 2006 11:18:36 +0000 (11:18 -0000)
* NvdlFilteredXmlReader.cs :
  Made placeholder element as "empty" i.e. IsEmptyElement = true.
  As long as it is at placeholder state, it keeps being placeholder
  empty element until DetachPlaceholder() is explicitly called. It
  makes this reader simpler.
* NvdlValidator.cs : (NvdlResultInterp) for AttachPlaceHolder it does
  not have to do anything other than AttachPlaceholder().
  (NvdlValidateInterp) Now that placeholder becomes an empty element
  it does not have to validate content anymore at DetachPlaceholder().

svn path=/trunk/mcs/; revision=59631

mcs/class/Commons.Xml.Relaxng/Commons.Xml.Nvdl/ChangeLog
mcs/class/Commons.Xml.Relaxng/Commons.Xml.Nvdl/NvdlFilteredXmlReader.cs
mcs/class/Commons.Xml.Relaxng/Commons.Xml.Nvdl/NvdlValidator.cs

index e26dbc9bc42a3d5e65235237bc2cd693740bacf9..4b520d130d67bbc0701df38a0bff178e816d92e2 100644 (file)
@@ -1,3 +1,15 @@
+2006-04-19  Atsushi Enomoto <atsushi@ximian.com>
+
+       * NvdlFilteredXmlReader.cs :
+         Made placeholder element as "empty" i.e. IsEmptyElement = true.
+         As long as it is at placeholder state, it keeps being placeholder
+         empty element until DetachPlaceholder() is explicitly called. It
+         makes this reader simpler.
+       * NvdlValidator.cs : (NvdlResultInterp) for AttachPlaceHolder it does
+         not have to do anything other than AttachPlaceholder().
+         (NvdlValidateInterp) Now that placeholder becomes an empty element
+         it does not have to validate content anymore at DetachPlaceholder().
+
 2006-04-19  Atsushi Enomoto <atsushi@ximian.com>
 
        * NvdlReader.cs, NvdlFilteredXmlReader.cs :
index c0ff8f8daa6f1d631b7ecbfe8b7a9c79a36814db..a35bc9196c701ea2d279444bf48b496f7b5305d5 100644 (file)
@@ -7,12 +7,17 @@ namespace Commons.Xml.Nvdl
 {
        internal class NvdlFilteredXmlReader : XmlReader, IXmlLineInfo
        {
+               // In this XmlReader, when AttachPlaceHolder() is called,
+               // it treats the next node as to point virtual "placeholder"
+               // element where IsEmptyElement is false. When it is
+               // Detached, then *current* node becomes the usual reader
+               // node.
+
                bool initial = true;
-               int placeHolderDepth = -1;
+               int placeHolderDepth = 0;
                XmlNodeType nextPlaceHolder;
                XmlNodeType placeHolder = XmlNodeType.None;
                bool placeHolderLocalNameAttr;
-               Stack placeHolderDepthStack;
                NvdlValidateInterp validate;
                XmlReader reader;
                IXmlLineInfo reader_as_line_info;
@@ -52,21 +57,14 @@ namespace Commons.Xml.Nvdl
 
                public void AttachPlaceholder ()
                {
-                       if (placeHolderDepthStack == null)
-                               placeHolderDepthStack = new Stack ();
-                       else
-                               placeHolderDepthStack.Push (placeHolderDepth);
-                       placeHolderDepth = reader.Depth;
+                       placeHolderDepth++;
                        nextPlaceHolder = XmlNodeType.Element;
                }
 
                public void DetachPlaceholder ()
                {
-                       if (placeHolderDepthStack.Count > 0)
-                               placeHolderDepth = (int) placeHolderDepthStack.Pop ();
-                       else
-                               placeHolderDepth = -1;
-                       nextPlaceHolder = XmlNodeType.EndElement;
+                       placeHolderDepth--;
+                       placeHolder = XmlNodeType.None;
                }
 
                private void AddAttribute ()
@@ -119,6 +117,12 @@ namespace Commons.Xml.Nvdl
                                return true;
                        }
 
+                       if (placeHolder != XmlNodeType.None)
+                               // Inside placeHolder, ignore all contents.
+                               // The source XmlReader should proceed
+                               // regardless of this filtered reader.
+                               return true;
+
                        if (!reader.MoveToFirstAttribute ())
                                return true;
 
@@ -175,9 +179,9 @@ namespace Commons.Xml.Nvdl
 
                public override int Depth {
                        get {
-                               if (placeHolderDepth < 0)
+                               if (placeHolderDepth == 0)
                                        return reader.Depth;
-                               int basis = reader.Depth + placeHolderDepthStack.Count + 1;
+                               int basis = reader.Depth + 1;
                                switch (placeHolder) {
                                case XmlNodeType.Text:
                                        return basis + 2;
@@ -217,7 +221,7 @@ namespace Commons.Xml.Nvdl
 
                public override bool IsEmptyElement {
                        get {
-                               return placeHolder == XmlNodeType.None &&
+                               return placeHolder != XmlNodeType.None ||
                                        reader.IsEmptyElement; 
                        }
                }
index 07da42148053d288f93232f3db242a1d3cecacb9..71233a174d7d7033f3c1e2a65e2f7e5732d9d12d 100644 (file)
@@ -478,7 +478,7 @@ NvdlDebug.Writer.WriteLine (": : : : Unwrapping StartElement ");
                                Parent.ValidateStartElement ();
                                break;
                        case NvdlResultType.AttachPlaceholder:
-                               throw new NotImplementedException ();
+                               break;
                        }
                }
                public override void ValidateEndElement ()
@@ -491,7 +491,7 @@ NvdlDebug.Writer.WriteLine (": : : : Unwrapping EndElement ");
                                Parent.ValidateEndElement ();
                                break;
                        case NvdlResultType.AttachPlaceholder:
-                               throw new NotImplementedException ();
+                               break;
                        }
                }
                public override void ValidateText ()
@@ -504,7 +504,7 @@ NvdlDebug.Writer.WriteLine (": : : : Unwrapping Text ");
                                Parent.ValidateText ();
                                break;
                        case NvdlResultType.AttachPlaceholder:
-                               throw new NotImplementedException ();
+                               break;
                        }
                }
                public override void ValidateWhitespace ()
@@ -517,7 +517,7 @@ NvdlDebug.Writer.WriteLine (": : : : Unwrapping Whitespace ");
                                Parent.ValidateWhitespace ();
                                break;
                        case NvdlResultType.AttachPlaceholder:
-                               throw new NotImplementedException ();
+                               break;
                        }
                }
        }
@@ -550,7 +550,9 @@ NvdlDebug.Writer.WriteLine ("++++++ new validate " + validate.Location);
                public override void DetachPlaceholder ()
                {
                        reader.DetachPlaceholder ();
-                       validator.Read (); // check EndElement
+                       // since placeholder is *empty*, we don't have to
+                       // validate this virtual element.
+                       //validator.Read ();
                }
 
                public override void EndSection ()