Пример #1
0
        public override void WriteEndAttribute()
        {
            try
            {
                AdvanceState(Token.EndAttribute);

                if (_specAttr != SpecialAttribute.No)
                {
                    string value;

                    switch (_specAttr)
                    {
                        case SpecialAttribute.DefaultXmlns:
                            value = _attrValueCache.StringValue;
                            if (PushNamespaceExplicit(string.Empty, value))
                            { // returns true if the namespace declaration should be written out
                                if (_rawWriter != null)
                                {
                                    if (_rawWriter.SupportsNamespaceDeclarationInChunks)
                                    {
                                        _rawWriter.WriteStartNamespaceDeclaration(string.Empty);
                                        _attrValueCache.Replay(_rawWriter);
                                        _rawWriter.WriteEndNamespaceDeclaration();
                                    }
                                    else
                                    {
                                        _rawWriter.WriteNamespaceDeclaration(string.Empty, value);
                                    }
                                }
                                else
                                {
                                    _writer.WriteStartAttribute(string.Empty, "xmlns", XmlReservedNs.NsXmlNs);
                                    _attrValueCache.Replay(_writer);
                                    _writer.WriteEndAttribute();
                                }
                            }
                            _curDeclPrefix = null;
                            break;
                        case SpecialAttribute.PrefixedXmlns:
                            value = _attrValueCache.StringValue;
                            if (value.Length == 0)
                            {
                                throw new ArgumentException(SR.Xml_PrefixForEmptyNs);
                            }
                            if (value == XmlReservedNs.NsXmlNs || (value == XmlReservedNs.NsXml && _curDeclPrefix != "xml"))
                            {
                                throw new ArgumentException(SR.Xml_CanNotBindToReservedNamespace);
                            }
                            if (PushNamespaceExplicit(_curDeclPrefix, value))
                            { // returns true if the namespace declaration should be written out
                                if (_rawWriter != null)
                                {
                                    if (_rawWriter.SupportsNamespaceDeclarationInChunks)
                                    {
                                        _rawWriter.WriteStartNamespaceDeclaration(_curDeclPrefix);
                                        _attrValueCache.Replay(_rawWriter);
                                        _rawWriter.WriteEndNamespaceDeclaration();
                                    }
                                    else
                                    {
                                        _rawWriter.WriteNamespaceDeclaration(_curDeclPrefix, value);
                                    }
                                }
                                else
                                {
                                    _writer.WriteStartAttribute("xmlns", _curDeclPrefix, XmlReservedNs.NsXmlNs);
                                    _attrValueCache.Replay(_writer);
                                    _writer.WriteEndAttribute();
                                }
                            }
                            _curDeclPrefix = null;
                            break;
                        case SpecialAttribute.XmlSpace:
                            _attrValueCache.Trim();
                            value = _attrValueCache.StringValue;

                            if (value == "default")
                            {
                                _elemScopeStack[_elemTop].xmlSpace = XmlSpace.Default;
                            }
                            else if (value == "preserve")
                            {
                                _elemScopeStack[_elemTop].xmlSpace = XmlSpace.Preserve;
                            }
                            else
                            {
                                throw new ArgumentException(SR.Xml_InvalidXmlSpace, value);
                            }
                            _writer.WriteStartAttribute("xml", "space", XmlReservedNs.NsXml);
                            _attrValueCache.Replay(_writer);
                            _writer.WriteEndAttribute();
                            break;
                        case SpecialAttribute.XmlLang:
                            value = _attrValueCache.StringValue;
                            _elemScopeStack[_elemTop].xmlLang = value;
                            _writer.WriteStartAttribute("xml", "lang", XmlReservedNs.NsXml);
                            _attrValueCache.Replay(_writer);
                            _writer.WriteEndAttribute();
                            break;
                    }
                    _specAttr = SpecialAttribute.No;
                    _attrValueCache.Clear();
                }
                else
                {
                    _writer.WriteEndAttribute();
                }
            }
            catch
            {
                _currentState = State.Error;
                throw;
            }
        }
Пример #2
0
 /// <summary>
 /// IF an attribute of the specified special type exists in the sequence, return it.  Otherwise return null.
 /// </summary>
 public static ICustomAttribute FindAttribute(IEnumerable<ICustomAttribute> attrs, SpecialAttribute sa) {
   foreach (var a in attrs)
     if (GetAttributeType(a) == sa)
       return a;
   return null;
 }
Пример #3
0
        private void SetSpecialAttribute(SpecialAttribute special)
        {
            _specAttr = special;
            if (State.Attribute == _currentState)
                _currentState = State.SpecialAttr;
            else if (State.RootLevelAttr == _currentState)
                _currentState = State.RootLevelSpecAttr;
            else
                Debug.Assert(false, "State.Attribute == currentState || State.RootLevelAttr == currentState");

            if (_attrValueCache == null)
            {
                _attrValueCache = new AttributeValueCache();
            }
        }
 private void SetSpecialAttribute(SpecialAttribute special) {
     specAttr = special;
     if (State.Attribute == currentState)
         currentState = State.SpecialAttr;
     else if (State.RootLevelAttr == currentState)
         currentState = State.RootLevelSpecAttr;
     else
         Debug.Assert(false, "State.Attribute == currentState || State.RootLevelAttr == currentState");
 }
        public override void WriteEndAttribute() {
            try {
                AdvanceState(Token.EndAttribute);

                if (specAttr != SpecialAttribute.No) {
                    string value;
                    if (attrValue != null) {
                        value = attrValue.ToString();
                        attrValue.Length = 0;
                    }
                    else {
                        value = string.Empty;
                    }

                    switch (specAttr) {
                        case SpecialAttribute.DefaultXmlns:
                            PushNamespace(string.Empty, value, true);
                            if (rawWriter != null) {
                                rawWriter.WriteNamespaceDeclaration(string.Empty, value);
                            }
                            else {
                                writer.WriteAttributeString(string.Empty, "xmlns", XmlReservedNs.NsXmlNs, value);
                            }
                            curDeclPrefix = null;
                            break;
                        case SpecialAttribute.PrefixedXmlns:
                            if (value.Length == 0) {
                                throw new ArgumentException(Res.GetString(Res.Xml_PrefixForEmptyNs));
                            }
                            if (value == XmlReservedNs.NsXmlNs || (value == XmlReservedNs.NsXml && curDeclPrefix != "xml")) {
                                throw new ArgumentException(Res.GetString(Res.Xml_CanNotBindToReservedNamespace));
                            }
                            PushNamespace(curDeclPrefix, value, true);
                            if (rawWriter != null) {
                                rawWriter.WriteNamespaceDeclaration(curDeclPrefix, value);
                            }
                            else {
                                writer.WriteAttributeString("xmlns", curDeclPrefix, XmlReservedNs.NsXmlNs, value);
                            }
                            curDeclPrefix = null;
                            break;
                        case SpecialAttribute.XmlSpace:
                            value = XmlConvert.TrimString(value);
                            if (value == "default") {
                                elemScopeStack[elemTop].xmlSpace = XmlSpace.Default;
                            }
                            else if (value == "preserve") {
                                elemScopeStack[elemTop].xmlSpace = XmlSpace.Preserve;
                            }
                            else {
                                throw new ArgumentException(Res.GetString(Res.Xml_InvalidXmlSpace, value));
                            }
                            writer.WriteAttributeString("xml", "space", XmlReservedNs.NsXml, value);
                            break;
                        case SpecialAttribute.XmlLang:
                            elemScopeStack[elemTop].xmlLang = value;
                            writer.WriteAttributeString("xml", "lang", XmlReservedNs.NsXml, value);
                            break;
                    }
                    specAttr = SpecialAttribute.No;
                }
                else {
                    writer.WriteEndAttribute();
                }
            }
            catch {
                currentState = State.Error;
                throw;
            }
        }
Пример #6
0
        private static char ConvertSpecial(Specials special)
        {
            SpecialAttribute attribute = EnumHelper.GetAttribute <SpecialAttribute>(special);

            return(attribute == null ? '?' : attribute.ShortName);
        }
Пример #7
0
        private static string GetSpecialString(Specials special)
        {
            SpecialAttribute attribute = EnumHelper.GetAttribute <SpecialAttribute>(special);

            return(attribute == null?special.ToString() : attribute.LongName);
        }
Пример #8
0
 /// <summary>
 /// IF an attribute of the specified special type exists in the sequence, return it.  Otherwise return null.
 /// </summary>
 public static ICustomAttribute FindAttribute(IEnumerable <ICustomAttribute> attrs, SpecialAttribute sa)
 {
     foreach (var a in attrs)
     {
         if (GetAttributeType(a) == sa)
         {
             return(a);
         }
     }
     return(null);
 }
        public override void WriteEndAttribute()
        {
            try
            {
                string stringValue;
                this.AdvanceState(Token.EndAttribute);
                switch (this.specAttr)
                {
                    case SpecialAttribute.DefaultXmlns:
                        stringValue = this.attrValueCache.StringValue;
                        if (this.PushNamespaceExplicit(string.Empty, stringValue))
                        {
                            if (this.rawWriter == null)
                            {
                                goto Label_00A9;
                            }
                            if (!this.rawWriter.SupportsNamespaceDeclarationInChunks)
                            {
                                break;
                            }
                            this.rawWriter.WriteStartNamespaceDeclaration(string.Empty);
                            this.attrValueCache.Replay(this.rawWriter);
                            this.rawWriter.WriteEndNamespaceDeclaration();
                        }
                        goto Label_00DF;

                    case SpecialAttribute.PrefixedXmlns:
                        stringValue = this.attrValueCache.StringValue;
                        if (stringValue.Length == 0)
                        {
                            throw new ArgumentException(Res.GetString("Xml_PrefixForEmptyNs"));
                        }
                        goto Label_010F;

                    case SpecialAttribute.XmlSpace:
                        this.attrValueCache.Trim();
                        stringValue = this.attrValueCache.StringValue;
                        if (!(stringValue == "default"))
                        {
                            goto Label_0235;
                        }
                        this.elemScopeStack[this.elemTop].xmlSpace = System.Xml.XmlSpace.Default;
                        goto Label_0277;

                    case SpecialAttribute.XmlLang:
                        stringValue = this.attrValueCache.StringValue;
                        this.elemScopeStack[this.elemTop].xmlLang = stringValue;
                        this.writer.WriteStartAttribute("xml", "lang", "http://www.w3.org/XML/1998/namespace");
                        this.attrValueCache.Replay(this.writer);
                        this.writer.WriteEndAttribute();
                        goto Label_0308;

                    case SpecialAttribute.No:
                        goto Label_031C;

                    default:
                        goto Label_0308;
                }
                this.rawWriter.WriteNamespaceDeclaration(string.Empty, stringValue);
                goto Label_00DF;
            Label_00A9:
                this.writer.WriteStartAttribute(string.Empty, "xmlns", "http://www.w3.org/2000/xmlns/");
                this.attrValueCache.Replay(this.writer);
                this.writer.WriteEndAttribute();
            Label_00DF:
                this.curDeclPrefix = null;
                goto Label_0308;
            Label_010F:
                if ((stringValue == "http://www.w3.org/2000/xmlns/") || ((stringValue == "http://www.w3.org/XML/1998/namespace") && (this.curDeclPrefix != "xml")))
                {
                    throw new ArgumentException(Res.GetString("Xml_CanNotBindToReservedNamespace"));
                }
                if (this.PushNamespaceExplicit(this.curDeclPrefix, stringValue))
                {
                    if (this.rawWriter != null)
                    {
                        if (this.rawWriter.SupportsNamespaceDeclarationInChunks)
                        {
                            this.rawWriter.WriteStartNamespaceDeclaration(this.curDeclPrefix);
                            this.attrValueCache.Replay(this.rawWriter);
                            this.rawWriter.WriteEndNamespaceDeclaration();
                        }
                        else
                        {
                            this.rawWriter.WriteNamespaceDeclaration(this.curDeclPrefix, stringValue);
                        }
                    }
                    else
                    {
                        this.writer.WriteStartAttribute("xmlns", this.curDeclPrefix, "http://www.w3.org/2000/xmlns/");
                        this.attrValueCache.Replay(this.writer);
                        this.writer.WriteEndAttribute();
                    }
                }
                this.curDeclPrefix = null;
                goto Label_0308;
            Label_0235:
                if (stringValue == "preserve")
                {
                    this.elemScopeStack[this.elemTop].xmlSpace = System.Xml.XmlSpace.Preserve;
                }
                else
                {
                    throw new ArgumentException(Res.GetString("Xml_InvalidXmlSpace", new object[] { stringValue }));
                }
            Label_0277:
                this.writer.WriteStartAttribute("xml", "space", "http://www.w3.org/XML/1998/namespace");
                this.attrValueCache.Replay(this.writer);
                this.writer.WriteEndAttribute();
            Label_0308:
                this.specAttr = SpecialAttribute.No;
                this.attrValueCache.Clear();
                return;
            Label_031C:
                this.writer.WriteEndAttribute();
            }
            catch
            {
                this.currentState = State.Error;
                throw;
            }
        }
 private void SetSpecialAttribute(SpecialAttribute special)
 {
     this.specAttr = special;
     if (State.Attribute == this.currentState)
     {
         this.currentState = State.SpecialAttr;
     }
     else if (State.RootLevelAttr == this.currentState)
     {
         this.currentState = State.RootLevelSpecAttr;
     }
     if (this.attrValueCache == null)
     {
         this.attrValueCache = new AttributeValueCache();
     }
 }
Пример #11
0
 public void AddAssetsSpecial(SpecialAttribute item)
 {
     _specialRep.Add(item);
 }
Пример #12
0
    /// <summary>
    /// IF an attribute of the specified special type exists in the sequence, return it.  Otherwise return null.
    /// </summary>
    public static ICustomAttribute FindAttribute(IEnumerable<ICustomAttribute> attrs, SpecialAttribute sa) {
      Contract.Requires(attrs != null);

      foreach (var a in attrs)
        if (GetAttributeType(a) == sa)
          return a;
      return null;
    }