Пример #1
0
        public FlatFileSchemaElement(string name, string ns, int minOccurs, int maxOccurs, FlatFileSchemaElement parent, Encoding encoding)
        {
            Name      = name;
            Namespace = ns;
            Parent    = parent;
            MinOccurs = minOccurs;
            MaxOccurs = maxOccurs;

            // Update element names:

            // If the element has the same namespace than its parent, it does not need to be repeated:
            if ((Parent != null) && (Namespace == Parent.Namespace))
            {
                StartElement = encoding.GetBytes(string.Concat("<", Name));
            }
            // Else if the element has a namespace but it differs from parent's ns, write it:
            else if (Namespace != null)
            {
                StartElement = encoding.GetBytes($"<{Name} xmlns=\"{Namespace}\"");
            }
            // Else element has an empty namespace:
            else
            {
                StartElement = encoding.GetBytes($"<{Name} xmlns=\"\"");
            }

            EndElement         = encoding.GetBytes("</" + Name + ">");
            ElementCloser      = encoding.GetBytes(">");
            EmptyElementCloser = encoding.GetBytes(" />");

            Children = new List <FlatFileSchemaElement>();
        }
Пример #2
0
        public FlatFileSchemaElement(string name, string ns, FlatFileSchemaElement parent, Encoding encoding)
        {
            Name        = name;
            Namespace   = ns;
            Parent      = parent;
            MinOccurs   = 1;
            MaxOccurs   = 1;
            ElementType = SchemaElementType.Attribute;

            StartElement  = encoding.GetBytes(" " + Name + "=\"");
            ElementCloser = encoding.GetBytes("\"");
        }