Example #1
0
        internal async Task WriteContentToAsync(XmlWriter writer, CancellationToken cancellationToken)
        {
            if (content != null)
            {
                string stringContent = content as string;

                if (stringContent != null)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    Task tWrite;

                    if (this is XDocument)
                    {
                        tWrite = writer.WriteWhitespaceAsync(stringContent);
                    }
                    else
                    {
                        tWrite = writer.WriteStringAsync(stringContent);
                    }

                    await tWrite.ConfigureAwait(false);
                }
                else
                {
                    XNode n = (XNode)content;
                    do
                    {
                        n = n.next;
                        await n.WriteToAsync(writer, cancellationToken).ConfigureAwait(false);
                    } while (n != content);
                }
            }
        }
Example #2
0
        public async Task WriteElementAsync(XElement e, CancellationToken cancellationToken)
        {
            PushAncestors(e);
            XElement root = e;
            XNode    n    = e;

            while (true)
            {
                e = n as XElement;
                if (e != null)
                {
                    await WriteStartElementAsync(e, cancellationToken).ConfigureAwait(false);

                    if (e.content == null)
                    {
                        await WriteEndElementAsync(cancellationToken).ConfigureAwait(false);
                    }
                    else
                    {
                        string s = e.content as string;
                        if (s != null)
                        {
                            cancellationToken.ThrowIfCancellationRequested();
                            await _writer.WriteStringAsync(s).ConfigureAwait(false);
                            await WriteFullEndElementAsync(cancellationToken).ConfigureAwait(false);
                        }
                        else
                        {
                            n = ((XNode)e.content).next;
                            continue;
                        }
                    }
                }
                else
                {
                    await n.WriteToAsync(_writer, cancellationToken).ConfigureAwait(false);
                }
                while (n != root && n == n.parent.content)
                {
                    n = n.parent;
                    await WriteFullEndElementAsync(cancellationToken).ConfigureAwait(false);
                }
                if (n == root)
                {
                    break;
                }
                n = n.next;
            }
        }