Exemplo n.º 1
0
        private void Parse(XmlReader reader, bool nestedElement)
        {
            if (reader.MoveToFirstAttribute())
            {
                do
                {
                    if (!nestedElement)
                    {
                        if (reader.LocalName?.Equals("xmlns", StringComparison.OrdinalIgnoreCase) == true)
                        {
                            continue;
                        }
                        if (reader.Prefix?.Equals("xsi", StringComparison.OrdinalIgnoreCase) == true)
                        {
                            continue;
                        }
                        if (reader.Prefix?.Equals("xmlns", StringComparison.OrdinalIgnoreCase) == true)
                        {
                            continue;
                        }
                    }

                    if (!AttributeValues.ContainsKey(reader.LocalName))
                    {
                        AttributeValues.Add(reader.LocalName, reader.Value);
                    }
                    else
                    {
                        string message = $"Duplicate attribute detected. Attribute name: [{reader.LocalName}]. Duplicate value:[{reader.Value}], Current value:[{AttributeValues[reader.LocalName]}]";
                        _parsingErrors.Add(message);
                    }
                }while (reader.MoveToNextAttribute());
                reader.MoveToElement();
            }

            LocalName = reader.LocalName;

            if (!reader.IsEmptyElement)
            {
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        break;
                    }

                    if (reader.NodeType == XmlNodeType.CDATA || reader.NodeType == XmlNodeType.Text)
                    {
                        Value += reader.Value;
                        continue;
                    }

                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        Children.Add(new NLogXmlElement(reader, true));
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void Parse(XmlReader reader)
        {
            if (reader.MoveToFirstAttribute())
            {
                do
                {
                    if (!AttributeValues.ContainsKey(reader.LocalName))
                    {
                        AttributeValues.Add(reader.LocalName, reader.Value);
                    }
                    else
                    {
                        string message = $"Duplicate attribute detected. Attribute name: [{reader.LocalName}]. Duplicate value:[{reader.Value}], Current value:[{AttributeValues[reader.LocalName]}]";
                        _parsingErrors.Add(message);
                    }
                }while (reader.MoveToNextAttribute());
                reader.MoveToElement();
            }

            LocalName = reader.LocalName;

            if (!reader.IsEmptyElement)
            {
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        break;
                    }

                    if (reader.NodeType == XmlNodeType.CDATA || reader.NodeType == XmlNodeType.Text)
                    {
                        Value += reader.Value;
                        continue;
                    }

                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        Children.Add(new NLogXmlElement(reader));
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void ParseAttributes(XmlReader reader, bool nestedElement)
        {
            if (reader.MoveToFirstAttribute())
            {
                do
                {
                    if (!nestedElement && IsSpecialXmlAttribute(reader))
                    {
                        continue;
                    }

                    if (!AttributeValues.ContainsKey(reader.LocalName))
                    {
                        AttributeValues.Add(reader.LocalName, reader.Value);
                    }
                    else
                    {
                        string message = $"Duplicate attribute detected. Attribute name: [{reader.LocalName}]. Duplicate value:[{reader.Value}], Current value:[{AttributeValues[reader.LocalName]}]";
                        _parsingErrors.Add(message);
                    }
                }while (reader.MoveToNextAttribute());
                reader.MoveToElement();
            }
        }