Пример #1
0
        public override bool Match(XsltDebuggerContext ctx)
        {
            XPathNavigator last_node = ctx.Session.CustomCache [CustomCacheId] as XPathNavigator;

            XmlNodeWriter w = ctx.Session.Output as XmlNodeWriter;
            XmlNode       n = w != null ? w.Document : null;

            if (n == null)
            {
                return(false);                // it is not ready for debugging.
            }
            if (exp == null)
            {
                exp = n.CreateNavigator().Compile(xpath);
            }

            exp.SetContext(ctx.Session.Debugger.NamespaceManager);
            XPathNodeIterator i = w.Current.CreateNavigator().Select(exp);
            bool next           = last_node == null;

            while (i.MoveNext())
            {
                if (next)
                {
                    ctx.Session.CustomCache [CustomCacheId] = i.Current;
                    return(true);
                }
                else if (i.Current.IsSamePosition(last_node))
                {
                    next = true;
                }
            }
            return(false);
        }
Пример #2
0
        public void PerformXmlRoundTrip(string xml)
        {
            var doc = new XmlDocument();

            using (var str = new StringReader(xml))
                using (var reader = XmlReader.Create(str))
                    using (var writer = new XmlNodeWriter(doc))
                    {
                        writer.WriteNode(reader, false);
                    }

            var settings = new XmlWriterSettings()
            {
                Indent             = true,
                IndentChars        = "  ",
                OmitXmlDeclaration = true
            };

            using (var reader = new XmlNodeReader(doc))
                using (var str = new StringWriter())
                    using (var writer = XmlWriter.Create(str, settings))
                    {
                        writer.WriteNode(reader, false);
                        writer.Flush();
                        str.Flush();
                        Assert.AreEqual(xml, str.ToString());
                    }
        }
Пример #3
0
    public void PerformXmlRoundTrip(string xml)
    {
      var doc = new XmlDocument();

      using (var str = new StringReader(xml))
      using (var reader = XmlReader.Create(str))
      using (var writer = new XmlNodeWriter(doc))
      {
        writer.WriteNode(reader, false);
      }

      var settings = new XmlWriterSettings()
      {
        Indent = true,
        IndentChars = "  ",
        OmitXmlDeclaration = true
      };

      using (var reader = new XmlNodeReader(doc))
      using (var str = new StringWriter())
      using (var writer = XmlWriter.Create(str, settings))
      {
        writer.WriteNode(reader, false);
        writer.Flush();
        str.Flush();
        Assert.AreEqual(xml, str.ToString());
      }
    }
Пример #4
0
 /// <summary>
 /// Saves tree of nodes (this and descendants) to an XML file.
 /// </summary>
 /// <param name="file">XML file. Must be full path. Can contain environment variables etc, see <see cref="APath.ExpandEnvVar"/>.</param>
 /// <param name="nodeWriter">Callback function that writes node's XML start element (see <see cref="XmlWriter.WriteStartElement(string)"/>) and attributes (see <see cref="XmlWriter.WriteAttributeString(string, string)"/>). Must not write children and end element. Also should not write value, unless your reader knows how to read it.</param>
 /// <param name="sett">XML formatting settings. Optional.</param>
 /// <param name="children">If not null, writes these nodes as if they were children of this node.</param>
 /// <exception cref="ArgumentException">Not full path.</exception>
 /// <exception cref="Exception">Exceptions of <see cref="XmlWriter.Create(string)"/> and other <b>XmlWriter</b> methods.</exception>
 /// <remarks>
 /// Uses <see cref="AFile.Save"/>. It ensures that existing file data is not damaged on exception etc.
 /// </remarks>
 /// <example><see cref="ATreeBase{T}"/></example>
 protected void XmlSave(string file, XmlNodeWriter nodeWriter, XmlWriterSettings sett = null, IEnumerable <T> children = null)
 {
     file = APath.NormalizeForNET_(file);
     sett ??= new XmlWriterSettings()
     {
         OmitXmlDeclaration = true, Indent = true, IndentChars = "  "
     };
     AFile.Save(file, temp => {
         using var x = XmlWriter.Create(temp, sett);
         XmlSave(x, nodeWriter, children);
     });
 }
Пример #5
0
        // It is indicated by ThreadManager.StartDebug().
        internal void Run()
        {
            custom_cache = new Hashtable();
            transform    = (XslTransform)Activator.CreateInstance(typeof(XslTransform), BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, new object [] { injector }, CultureInfo.CurrentCulture);
            debugger.LoadStylesheet(transform);
            output = new XmlNodeWriter(false);
            debugger.Transform(transform, output);

            if (Completed != null)
            {
                Completed(this, new XsltCompleteEventArgs());
            }
        }
Пример #6
0
 void _XmlWrite(XmlWriter x, XmlNodeWriter nodeWriter)
 {
     nodeWriter(x, this as T);
     if (_lastChild != null)
     {
         var c = _lastChild;
         do
         {
             c = c._next;
             c._XmlWrite(x, nodeWriter);
         } while(c != _lastChild);
     }
     x.WriteEndElement();
 }
Пример #7
0
 /// <summary>
 /// Writes tree of nodes (this and descendants) to an <see cref="XmlWriter"/>.
 /// </summary>
 /// <param name="x"></param>
 /// <param name="nodeWriter"></param>
 /// <param name="children"></param>
 /// <remarks>More info: <see cref="XmlSave(string, XmlNodeWriter, XmlWriterSettings, IEnumerable{T})"/>.</remarks>
 /// <exception cref="Exception">Exceptions of <b>XmlWriter</b> methods.</exception>
 /// <example><see cref="ATreeBase{T}"/></example>
 protected void XmlSave(XmlWriter x, XmlNodeWriter nodeWriter, IEnumerable <T> children = null)
 {
     if (x == null || nodeWriter == null)
     {
         throw new ArgumentNullException();
     }
     x.WriteStartDocument();
     if (children == null)
     {
         _XmlWrite(x, nodeWriter);
     }
     else
     {
         nodeWriter(x, this as T);
         foreach (var n in children)
         {
             n._XmlWrite(x, nodeWriter);
         }
         x.WriteEndElement();
     }
     x.WriteEndDocument();
 }
Пример #8
0
 public void Dispose()
 {
     debugger  = null;
     transform = null;
     output    = null;
 }