System.Xml.XmlWellFormedWriter.WriteProcessingInstruction C# (CSharp) Méthode

WriteProcessingInstruction() public méthode

public WriteProcessingInstruction ( string name, string text ) : void
name string
text string
Résultat void
        public override void WriteProcessingInstruction(string name, string text)
        {
            try
            {
                // check name
                if (name == null || name.Length == 0)
                {
                    throw new ArgumentException(SR.Xml_EmptyName);
                }
                CheckNCName(name);

                // check text
                if (text == null)
                {
                    text = string.Empty;
                }

                // xml declaration is a special case (not a processing instruction, but we allow WriteProcessingInstruction as a convenience)
                if (name.Length == 3 && string.Equals(name, "xml", StringComparison.OrdinalIgnoreCase))
                {
                    if (_currentState != State.Start)
                    {
                        throw new ArgumentException(_conformanceLevel == ConformanceLevel.Document ? SR.Xml_DupXmlDecl : SR.Xml_CannotWriteXmlDecl);
                    }

                    _xmlDeclFollows = true;
                    AdvanceState(Token.PI);

                    if (_rawWriter != null)
                    {
                        // Translate PI into an xml declaration
                        _rawWriter.WriteXmlDeclaration(text);
                    }
                    else
                    {
                        _writer.WriteProcessingInstruction(name, text);
                    }
                }
                else
                {
                    AdvanceState(Token.PI);
                    _writer.WriteProcessingInstruction(name, text);
                }
            }
            catch
            {
                _currentState = State.Error;
                throw;
            }
        }