Exemplo n.º 1
0
            private C0323E7167F4 ParseDocument(XmlReader current)
            {
                C0323E7167F4 node = new C0323E7167F4()
                {
                    Name   = current.LocalName,
                    Value  = current.Value,
                    Parent = null,
                    Prefix = current.Prefix,
                };

                ParseAttributes(current, node);
                ParseNamespace(node);

                if (this.Combine.Document != null)
                {
                    if (!(string.Equals(this.Combine.Document.Prefix, node.Prefix, StringComparison.CurrentCultureIgnoreCase) &&
                          string.Equals(this.Combine.Document.Name, node.Name, StringComparison.CurrentCultureIgnoreCase)))
                    {
                        throw new RainbowException($"The XML root node is not consistent and must be '{this.Combine.Document.Prefix}:{this.Combine.Document.Name}'");
                    }

                    foreach (DCA6AE8014E9 attr in node.Attributes)
                    {
                        this.AddAttribute(this.Combine.Document, attr);
                    }
                }
                else
                {
                    this.Combine.Document = node;
                }

                return(this.Combine.Document);
            }
Exemplo n.º 2
0
            private C0323E7167F4 AddElement(C0323E7167F4 parent, C0323E7167F4 node)
            {
                XmlSchemaElement element = this.Combine.Namespaces.TryGetElementByPrefix(node.Prefix, node.Name);

                if (element != null && element.MaxOccurs == 1)
                {
                    C0323E7167F4 ins = parent.Childs.FirstOrDefault(p =>
                                                                    string.Equals(p.Name, node.Name, StringComparison.OrdinalIgnoreCase) &&
                                                                    string.Equals(p.Prefix, node.Prefix, StringComparison.OrdinalIgnoreCase));

                    if (ins != null)
                    {
                        ins.Value = node.Value;

                        foreach (DCA6AE8014E9 attr in node.Attributes)
                        {
                            AddAttribute(ins, attr);
                        }
                        return(ins);
                    }
                }

                parent.Childs.Add(node);
                return(node);
            }
Exemplo n.º 3
0
 private void ParseNamespace(C0323E7167F4 node)
 {
     node.Prefix = this.Namespaces.GetMappingByPrefix(node.Prefix);
     foreach (DCA6AE8014E9 attr in node.Attributes)
     {
         if (string.IsNullOrWhiteSpace(attr.Prefix))
         {
             attr.Prefix = node.Prefix;
         }
     }
 }
Exemplo n.º 4
0
            private C0323E7167F4 ParseElement(XmlReader current, C0323E7167F4 parent)
            {
                C0323E7167F4 node = new C0323E7167F4()
                {
                    Name   = current.LocalName,
                    Value  = current.Value,
                    Parent = parent,
                    Prefix = current.Prefix,
                };

                ParseAttributes(current, node);
                ParseNamespace(node);

                return(AddElement(parent, node));
            }
Exemplo n.º 5
0
            private DCA6AE8014E9 AddAttribute(C0323E7167F4 node, DCA6AE8014E9 attr)
            {
                DCA6AE8014E9 current = node.Attributes.FirstOrDefault(p => string.Equals(p.Prefix, attr.Prefix, StringComparison.OrdinalIgnoreCase) &&
                                                                      string.Equals(p.Name, attr.Name, StringComparison.OrdinalIgnoreCase));

                if (current != null)
                {
                    current.Value = attr.Value;
                    return(current);
                }
                else
                {
                    node.Attributes.Add(attr);
                    return(attr);
                }
            }
Exemplo n.º 6
0
        private void ToFormatString(XmlWriter xml, C0323E7167F4 node)
        {
            if (node != null)
            {
                xml.WriteStartElement(node.Prefix, node.Name, this.Namespaces.GetUriByPrefix(node.Prefix));

                if (node.Attributes.Count > 0)
                {
                    foreach (DCA6AE8014E9 attr in node.Attributes)
                    {
                        if (string.Equals(attr.Prefix, node.Prefix, StringComparison.OrdinalIgnoreCase) ||
                            string.IsNullOrWhiteSpace(node.Prefix))
                        {
                            xml.WriteAttributeString(attr.Name, attr.Value);
                        }
                        else
                        {
                            xml.WriteAttributeString(attr.Prefix, attr.Name, this.Namespaces.GetUriByPrefix(attr.Prefix), attr.Value);
                        }
                    }
                }

                if (!string.IsNullOrWhiteSpace(node.Value))
                {
                    xml.WriteString(node.Value);
                }

                if (node.Childs.Count > 0)
                {
                    foreach (C0323E7167F4 current in node.Childs)
                    {
                        ToFormatString(xml, current);
                    }
                }

                xml.WriteEndElement();
            }
        }
Exemplo n.º 7
0
            public void Parse()
            {
                C0323E7167F4 root = null;

                while (this.Current.Read())
                {
                    switch (this.Current.NodeType)
                    {
                    case XmlNodeType.Element:
                        bool isEmpty = this.Current.IsEmptyElement;
                        root = this.Current.Depth == 0 ? ParseDocument(this.Current) : ParseElement(this.Current, root);
                        if (isEmpty)
                        {
                            root = root.Parent;
                        }
                        break;

                    case XmlNodeType.EndElement:
                        root = root.Parent;
                        break;
                    }
                }
            }
Exemplo n.º 8
0
            private void ParseAttributes(XmlReader current, C0323E7167F4 node)
            {
                if (current.HasAttributes)
                {
                    List <DCA6AE8014E9> attrs = new List <DCA6AE8014E9>();

                    while (current.MoveToNextAttribute())
                    {
                        if (string.Equals(XMLNS_NAME, current.Prefix, StringComparison.OrdinalIgnoreCase))
                        {
                            this.AddNamespace(current.LocalName, current.Value);
                        }
                        else if (string.Equals(XMLNS_NAME, current.LocalName, StringComparison.OrdinalIgnoreCase))
                        {
                            this.AddNamespace("", current.Value);
                        }
                        else
                        {
                            DCA6AE8014E9 attr = new DCA6AE8014E9()
                            {
                                Name   = current.LocalName,
                                Value  = current.Value,
                                Prefix = current.Prefix
                            };
                            attrs.Add(attr);
                        }
                    }

                    foreach (DCA6AE8014E9 attr in attrs)
                    {
                        attr.Prefix = string.IsNullOrWhiteSpace(attr.Prefix) ?
                                      "" : this.Namespaces.GetMappingByPrefix(attr.Prefix);
                        this.AddAttribute(node, attr);
                    }
                }
            }