Exemplo n.º 1
0
        public static string Iterate(this XPathNavigator n, bool justText)
        {
            XPathNavigator c          = n.Clone();
            BlockWriteInfo nfo        = n.GetBlockType();
            bool           istext     = n.Name == "#text" || n.Name == "#document";
            string         name       = c.Name;
            string         temp       = c.Value.RemoveWhitespace(true);
            bool           hasContent = !string.IsNullOrEmpty(temp);

            temp = default(string);
            string output = hasContent ? c.NodeInfo(justText) : string.Empty;

            c.MoveToFirstChild();
            {
                output += c.HasChildren ? c.Iterate(justText) : c.NodeInfo(justText);
            }
            while (c.MoveToNext())
            {
                output += c.HasChildren ? c.Iterate(justText) : c.NodeInfo(justText);
            }

            string ofmt = istext ? "{epre}{cpre}{1}{cpost}{epost}" : "{epre}<{0}>{cpre}{1}{cpost}</{0}>{epost}";

            ofmt = ofmt
                   .Replace("{cpre}", nfo.HasFlag(BlockWriteInfo.LinePreContent) ? "\n" : string.Empty)
                   .Replace("{cpost}", nfo.HasFlag(BlockWriteInfo.LinePostContent) ? "\n" : string.Empty)
                   .Replace("{epre}", nfo.HasFlag(BlockWriteInfo.LinePre) ? "\n" : string.Empty)
                   .Replace("{epost}", nfo.HasFlag(BlockWriteInfo.LinePost) ? "\n" : string.Empty);
            System.Diagnostics.Debug.Print("{0} {{ Flags: {1:X6} }}", n.Name, Convert.ToInt32(nfo));
            output = nfo.HasFlag(BlockWriteInfo.CleanWhitespacePre) ? output.TrimStart() : output;
            output = nfo.HasFlag(BlockWriteInfo.CleanWhitespacePost) ? output.TrimEnd() : output;
            // we could check to see if the element contains blocking siblings, in which case we would certainly
            // pad the element with space if non-blocking.
            return(string.Format(ofmt, name, output));
        }
Exemplo n.º 2
0
        static public bool IsBlocking(this XPathNavigator n)
        {
            if (n == null)
            {
                return(false);
            }
            BlockWriteInfo mode    = n.GetBlockType();
            bool           returns = false;

            if (mode.HasFlag(BlockWriteInfo.Block) || mode.HasFlag(BlockWriteInfo.Unknown))
            {
                returns = true;
            }
            mode = default(BlockWriteInfo);
            return(returns);
        }
Exemplo n.º 3
0
        static public BlockWriteInfo PeekParentType(this XPathNavigator n)
        {
            XPathNavigator node = n.PeekParent();

            return(node.GetBlockType());
        }
Exemplo n.º 4
0
 static public bool IsLinePost(this XPathNavigator n)
 {
     return(n.GetBlockType().HasFlag(BlockWriteInfo.LinePost));
 }
Exemplo n.º 5
0
 static public bool IsCleanWhiteSpacePre(this XPathNavigator n)
 {
     return(n.GetBlockType().HasFlag(BlockWriteInfo.CleanWhitespacePre));
 }
Exemplo n.º 6
0
        static public BlockWriteInfo LogicalBlockPrev(this XPathNavigator n)
        {
            XPathNavigator node = n.PeekPrev();

            return(node.GetBlockType());
        }