예제 #1
0
 public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
 {
     if (writer == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer"));
     }
     if (!MoveToFirst())
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.XmlTokenBufferIsEmpty)));
     }
     int depth = 0;
     int recordedDepth = -1;
     bool include = true;
     do
     {
         switch (this.NodeType)
         {
             case XmlNodeType.Element:
                 bool isEmpty = this.IsEmptyElement;
                 depth++;
                 if (include
                     && (null == excludedElementDepth || excludedElementDepth == (depth - 1))
                     && this.LocalName == this.excludedElement 
                     && this.NamespaceUri == this.excludedElementNamespace)
                 {
                     include = false;
                     recordedDepth = depth;
                 }
                 if (include)
                 {
                     writer.WriteStartElement(this.Prefix, this.LocalName, this.NamespaceUri);
                 }
                 if (MoveToFirstAttribute())
                 {
                     do
                     {
                         if (include)
                         {
                             writer.WriteAttributeString(this.Prefix, this.LocalName, this.NamespaceUri, this.Value);
                         }
                     }
                     while (MoveToNextAttribute());
                 }
                 if (isEmpty)
                 {
                     goto case XmlNodeType.EndElement;
                 }
                 break;
             case XmlNodeType.EndElement:
                 if (include)
                 {
                     writer.WriteEndElement();
                 }
                 else if (recordedDepth == depth)
                 {
                     include = true;
                     recordedDepth = -1;
                 }
                 depth--;
                 break;
             case XmlNodeType.CDATA:
                 if (include)
                 {
                     writer.WriteCData(this.Value);
                 }
                 break;
             case XmlNodeType.Comment:
                 if (include)
                 {
                     writer.WriteComment(this.Value);
                 }
                 break;
             case XmlNodeType.Text:
                 if (include)
                 {
                     writer.WriteString(this.Value);
                 }
                 break;
             case XmlNodeType.SignificantWhitespace:
             case XmlNodeType.Whitespace:
                 if (include)
                 {
                     writer.WriteWhitespace(this.Value);
                 }
                 break;
             case XmlNodeType.DocumentType:
             case XmlNodeType.XmlDeclaration:
                 break;
         }
     }
     while (MoveToNext());
 }
        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
        {
            try
            {
                do
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element:
                            writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                writer.WriteAttributeString(reader.LocalName, reader.NamespaceURI, reader.Value.Replace(sourcePattern, targetPattern));
                            }
                            reader.MoveToElement();
                            if (reader.IsEmptyElement)
                            {
                                writer.WriteEndElement();
                            }
                            break;

                        case XmlNodeType.Text:
                            writer.WriteString(reader.Value.Replace(sourcePattern, targetPattern));
                            break;

                        case XmlNodeType.Whitespace:
                        case XmlNodeType.SignificantWhitespace:
                            writer.WriteWhitespace(reader.Value);
                            break;

                        case XmlNodeType.CDATA:
                            writer.WriteCData(reader.Value);
                            break;

                        case XmlNodeType.EntityReference:
                            writer.WriteEntityRef(reader.Name);
                            break;

                        case XmlNodeType.XmlDeclaration:
                        case XmlNodeType.ProcessingInstruction:
                            writer.WriteProcessingInstruction(reader.Name, reader.Value);
                            break;
                        case XmlNodeType.DocumentType:
                            writer.WriteDocType(reader.Name, reader.GetAttribute("PUBLIC"), reader.GetAttribute("SYSTEM"), reader.Value);
                            break;
                        case XmlNodeType.Comment:
                            writer.WriteComment(reader.Value);
                            break;
                        case XmlNodeType.EndElement:
                            writer.WriteFullEndElement();
                            break;
                    }
                }
                while (reader.Read());
                writer.Flush();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }
        }
            public void WriteTo(XmlDictionaryWriter writer, DictionaryManager dictionaryManager)
            {
                bool isEmptyElement;
                if (writer == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("writer"));
                }
                if (!this.MoveToFirst())
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.IdentityModel.SR.GetString("XmlTokenBufferIsEmpty")));
                }
                int num = 0;
                int num2 = -1;
                bool flag = true;
            Label_0040:
                switch (this.NodeType)
                {
                    case XmlNodeType.Element:
                        isEmptyElement = this.IsEmptyElement;
                        num++;
                        if (flag)
                        {
                            if (this.excludedElementDepth.HasValue)
                            {
                                int? excludedElementDepth = this.excludedElementDepth;
                                int num3 = num - 1;
                                if (!((excludedElementDepth.GetValueOrDefault() == num3) && excludedElementDepth.HasValue))
                                {
                                    break;
                                }
                            }
                            if ((this.LocalName == this.excludedElement) && (this.NamespaceUri == this.excludedElementNamespace))
                            {
                                flag = false;
                                num2 = num;
                            }
                        }
                        break;

                    case XmlNodeType.Text:
                        if (flag)
                        {
                            writer.WriteString(this.Value);
                        }
                        goto Label_01AD;

                    case XmlNodeType.CDATA:
                        if (flag)
                        {
                            writer.WriteCData(this.Value);
                        }
                        goto Label_01AD;

                    case XmlNodeType.Comment:
                        if (flag)
                        {
                            writer.WriteComment(this.Value);
                        }
                        goto Label_01AD;

                    case XmlNodeType.Whitespace:
                    case XmlNodeType.SignificantWhitespace:
                        if (flag)
                        {
                            writer.WriteWhitespace(this.Value);
                        }
                        goto Label_01AD;

                    case XmlNodeType.EndElement:
                        goto Label_0152;

                    default:
                        goto Label_01AD;
                }
                if (flag)
                {
                    writer.WriteStartElement(this.Prefix, this.LocalName, this.NamespaceUri);
                }
                if (this.MoveToFirstAttribute())
                {
                    do
                    {
                        if (flag)
                        {
                            writer.WriteAttributeString(this.Prefix, this.LocalName, this.NamespaceUri, this.Value);
                        }
                    }
                    while (this.MoveToNextAttribute());
                }
                if (!isEmptyElement)
                {
                    goto Label_01AD;
                }
            Label_0152:
                if (flag)
                {
                    writer.WriteEndElement();
                }
                else if (num2 == num)
                {
                    flag = true;
                    num2 = -1;
                }
                num--;
            Label_01AD:
                if (this.MoveToNext())
                {
                    goto Label_0040;
                }
            }
예제 #4
0
 public override void WriteComment(string text)
 {
     writer.WriteComment(text);
 }