예제 #1
0
        internal string InternalReadContentAsString()
        {
            string        str           = "";
            BufferBuilder bufferBuilder = (BufferBuilder)null;

            do
            {
                switch (this.NodeType)
                {
                case XmlNodeType.Attribute:
                    return(this.Value);

                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                    if (str.Length == 0)
                    {
                        str = this.Value;
                        goto case XmlNodeType.ProcessingInstruction;
                    }
                    else
                    {
                        if (bufferBuilder == null)
                        {
                            bufferBuilder = new BufferBuilder();
                            bufferBuilder.Append(str);
                        }
                        bufferBuilder.Append(this.Value);
                        goto case XmlNodeType.ProcessingInstruction;
                    }

                case XmlNodeType.EntityReference:
                    if (this.CanResolveEntity)
                    {
                        this.ResolveEntity();
                        goto case XmlNodeType.ProcessingInstruction;
                    }
                    else
                    {
                        goto label_11;
                    }

                case XmlNodeType.ProcessingInstruction:
                case XmlNodeType.Comment:
                case XmlNodeType.EndEntity:
                    continue;

                default:
                    goto label_11;
                }
            }while ((this.AttributeCount != 0 ? (this.ReadAttributeValue() ? 1 : 0) : (this.Read() ? 1 : 0)) != 0);
label_11:
            if (bufferBuilder != null)
            {
                return(bufferBuilder.ToString());
            }
            return(str);
        }
예제 #2
0
        internal string InternalReadContentAsString()
        {
            string        value = "";
            BufferBuilder sb    = null;

            do
            {
                switch (this.NodeType)
                {
                case XmlNodeType.Attribute:
                    return(this.Value);

                case XmlNodeType.Text:
                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                case XmlNodeType.CDATA:
                    // merge text content
                    if (value.Length == 0)
                    {
                        value = this.Value;
                    }
                    else
                    {
                        if (sb == null)
                        {
                            sb = new BufferBuilder();
                            sb.Append(value);
                        }

                        sb.Append(this.Value);
                    }
                    break;

                case XmlNodeType.ProcessingInstruction:
                case XmlNodeType.Comment:
                case XmlNodeType.EndEntity:
                    // skip comments, pis and end entity nodes
                    break;

                case XmlNodeType.EntityReference:
                    if (this.CanResolveEntity)
                    {
                        this.ResolveEntity();
                        break;
                    }

                    goto default;

                case XmlNodeType.EndElement:
                default:
                    goto ReturnContent;
                }
            } while ((this.AttributeCount != 0) ? this.ReadAttributeValue() : this.Read());

ReturnContent:
            return((sb == null) ? value : sb.ToString());
        }
예제 #3
0
 internal void CopyTo(int valueOffset, BufferBuilder sb)
 {
     if (value == null)
     {
         Debug.Assert(valueStartPos != -1);
         Debug.Assert(chars != null);
         sb.Append(chars, valueStartPos + valueOffset, valueLength - valueOffset);
     }
     else
     {
         if (valueOffset <= 0)
         {
             sb.Append(value);
         }
         else
         {
             sb.Append(value, valueOffset, value.Length - valueOffset);
         }
     }
 }
        internal void Write(char[] array, int offset, int count)
        {
            if (null == array)
            {
                throw new ArgumentNullException("array");
            }

            if (0 > offset)
            {
                throw new ArgumentOutOfRangeException("offset");
            }

            if (0 > count)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            if (count > array.Length - offset)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            if (cacheAttrValue)
            {
                attrValue.Append(array, offset, count);
            }

            int  endPos = offset + count;
            int  i      = offset;
            char ch     = (char)0;

            for (;;)
            {
                int startPos = i;
                unsafe {
                    while (i < endPos && (xmlCharType.charProperties[ch = array[i]] & XmlCharType.fAttrValue) != 0)       // ( xmlCharType.IsAttributeValueChar( ( ch = array[i] ) ) ) ) {
                    {
                        i++;
                    }
                }

                if (startPos < i)
                {
                    textWriter.Write(array, startPos, i - startPos);
                }
                if (i == endPos)
                {
                    break;
                }

                switch (ch)
                {
                case (char)0x9:
                    textWriter.Write(ch);
                    break;

                case (char)0xA:
                case (char)0xD:
                    if (inAttribute)
                    {
                        WriteCharEntityImpl(ch);
                    }
                    else
                    {
                        textWriter.Write(ch);
                    }
                    break;

                case '<':
                    WriteEntityRefImpl("lt");
                    break;

                case '>':
                    WriteEntityRefImpl("gt");
                    break;

                case '&':
                    WriteEntityRefImpl("amp");
                    break;

                case '\'':
                    if (inAttribute && quoteChar == ch)
                    {
                        WriteEntityRefImpl("apos");
                    }
                    else
                    {
                        textWriter.Write('\'');
                    }
                    break;

                case '"':
                    if (inAttribute && quoteChar == ch)
                    {
                        WriteEntityRefImpl("quot");
                    }
                    else
                    {
                        textWriter.Write('"');
                    }
                    break;

                default:
                    if ((int)ch >= SurHighStart && (int)ch <= SurHighEnd)
                    {
                        if (i + 1 < endPos)
                        {
                            WriteSurrogateChar(array[++i], ch);
                        }
                        else
                        {
                            throw new ArgumentException(Res.GetString(Res.Xml_SurrogatePairSplit));
                        }
                    }
                    else if ((int)ch >= SurLowStart && (int)ch <= SurLowEnd)
                    {
                        throw XmlConvert.CreateInvalidHighSurrogateCharException(ch);
                    }
                    else
                    {
                        Debug.Assert((ch < 0x20 && !xmlCharType.IsWhiteSpace(ch)) || (ch > 0xFFFD));
                        WriteCharEntityImpl(ch);
                    }
                    break;
                }
                i++;
            }
        }