예제 #1
0
        public override void OnElement(Element element)
        {
            //Getting namespace and prefix
            string prefix, ns;

            NamespaceResolver.GetPrefixAndNs(element, _currentDocument,
                                             () => ScopeContext.Peek(),
                                             out prefix, out ns);

            if (string.IsNullOrEmpty(element.NsPrefix))
            {
                prefix = null;
            }
            //Starting Element
            if (!string.IsNullOrEmpty(element.Name))
            {
                if (element.Delimiter != DelimiterEnum.CCC)
                {
                    //not text node
                    _xmlTextWriter.WriteStartElement(prefix, element.Name, ns);
                    AddLocationMapRecord(_currentModuleMember.Module.FileName, (IMappedPair)element);

                    //Write all namespace declarations in the root element
                    if (!_rootElementAdded)
                    {
                        WritePendingNamespaceDeclarations(ns);
                        _rootElementAdded = true;
                    }
                }
            }
            else
            {
                if (element.Parent.Delimiter == DelimiterEnum.CCC && (element.Delimiter == DelimiterEnum.C || element.Delimiter == DelimiterEnum.CC))
                {
                    // This is item of explicit array (:::)
                    WriteExplicitArrayItem(element);
                }
            }

            if (!ResolveValue(element) && !EnterChoiceContainer(element, element.Entities))
            {
                base.OnElement(element);
            }

            //End Element
            if (!string.IsNullOrEmpty(element.Name))
            {
                if (element.Delimiter != DelimiterEnum.CCC) //not text node and not explicit array
                {
                    _xmlTextWriter.WriteEndElement();
                }
            }
            else
            {
                if (element.Parent.Delimiter == DelimiterEnum.CCC && (element.Delimiter == DelimiterEnum.C || element.Delimiter == DelimiterEnum.CC))
                {
                    _xmlTextWriter.WriteEndElement();
                }
            }
        }
예제 #2
0
 public override void OnElement(Element pair)
 {
     PrintNodeName(pair);
     PrintNodeStart(pair);
     base.OnElement(pair);
     PrintNodeEnd(pair);
 }
예제 #3
0
        /// <inheritdoc />
        public override void Visit(Element element)
        {
            //Getting namespace and prefix
            NamespaceResolver.GetPrefixAndNs(element, CurrentDocument, CurrentModuleMember,
                                             ScopeContext.Peek(),
                                             out var prefix, out var ns);

            if (string.IsNullOrEmpty(element.NsPrefix))
            {
                prefix = null;
            }
            //Starting Element
            if (!string.IsNullOrEmpty(element.Name))
            {
                if (element.Assignment != AssignmentEnum.CCC)
                {
                    //not text node
                    XmlTextWriter.WriteStartElement(prefix, element.Name, ns);
                    AddLocationMapRecord(CurrentModuleMember.Module.FileName, (IMappedPair)element);

                    //Write all namespace declarations in the root element
                    if (!DocumentElementAdded)
                    {
                        WritePendingNamespaceDeclarations(ns);
                        DocumentElementAdded = true;
                    }
                }
            }
            else
            {
                if (element.Parent.Assignment == AssignmentEnum.CCC && (element.Assignment == AssignmentEnum.C || element.Assignment == AssignmentEnum.CC || element.Assignment == AssignmentEnum.E || element.Assignment == AssignmentEnum.EE))
                {
                    // This is item of explicit array (:::)
                    WriteExplicitArrayItem(element, prefix, ns);
                }
            }

            if (!ResolveValue(element) && !EnterChoiceContainer(element, element.Entities))
            {
                base.Visit(element);
            }

            //End Element
            if (!string.IsNullOrEmpty(element.Name))
            {
                if (element.Assignment != AssignmentEnum.CCC) //not text node and not explicit array
                {
                    XmlTextWriter.WriteEndElement();
                }
            }
            else
            {
                if (element.Parent.Assignment == AssignmentEnum.CCC && (element.Assignment == AssignmentEnum.C || element.Assignment == AssignmentEnum.CC || element.Assignment == AssignmentEnum.E || element.Assignment == AssignmentEnum.EE))
                {
                    XmlTextWriter.WriteEndElement();
                }
            }
        }
예제 #4
0
 private void WriteExplicitArrayItem(Element element, string prefix, string ns)
 {
     if (string.IsNullOrEmpty(element.NsPrefix))
     {
         prefix = null;
     }
     XmlTextWriter.WriteStartElement(prefix, element.Parent.Name, ns);
     AddLocationMapRecord(CurrentModuleMember.Module.FileName, (IMappedPair)element);
 }
예제 #5
0
        public override void OnElement(Element element)
        {
            CheckBlockStart(element);

            if (!string.IsNullOrEmpty(element.Name) && element.Delimiter != DelimiterEnum.None)
            {
                _jsonWriter.WritePropertyName((element.NsPrefix != null ? element.NsPrefix + "." : "") + element.Name);
            }

            if (ResolveValue(element))
            {
                return;                        //Block has value therefore it has no block.
            }
            //Working with node's block
            _blockStart = true;
            var prevBlockStateCount = _blockState.Count;

            base.OnElement(element);

            _blockStart = false;

            if (_blockState.Count > prevBlockStateCount)
            {
                if (_blockState.Pop() == BlockState.Array)
                {
                    _jsonWriter.WriteEndArray();
                }
                else
                {
                    _jsonWriter.WriteEndObject();
                }
                return;
            }

            //Element hase nor block no value. Writing an empty object as a value.
            if (!string.IsNullOrEmpty(element.Name) || ((DOM.Mapped.Element)element).ValueType == ValueType.Object)
            {
                if (element.Delimiter == DelimiterEnum.CC)
                {
                    _jsonWriter.WriteStartArray();
                    _jsonWriter.WriteEndArray();
                }
                else
                {
                    _jsonWriter.WriteStartObject();
                    _jsonWriter.WriteEndObject();
                }
            }
        }
예제 #6
0
        private void WriteExplicitArrayItem(Element element)
        {
            string prefix;
            string ns;

            NamespaceResolver.GetPrefixAndNs((INsNode)element.Parent, _currentDocument,
                                             () => ScopeContext.Peek(),
                                             out prefix, out ns);
            if (string.IsNullOrEmpty(element.NsPrefix))
            {
                prefix = null;
            }
            _xmlTextWriter.WriteStartElement(prefix, element.Parent.Name, ns);
            AddLocationMapRecord(_currentModuleMember.Module.FileName, (IMappedPair)element);
        }
예제 #7
0
        /// <inheritdoc />
        public override void Visit(Element element)
        {
            CheckBlockStart(element);

            if (!string.IsNullOrEmpty(element.Name) && element.Assignment != AssignmentEnum.None)
            {
                JsonWriter.WritePropertyName((element.NsPrefix != null ? element.NsPrefix + "." : "") + element.Name);
            }

            if (ResolveValue(element))
            {
                return;                        //Element has value therefore it has no block.
            }
            //Working with node's block

            var prevBlockStateCount = BlockState.Count;
            var mp = (IMappedPair)element;

            if (BlockState.Peek() == BlockStateEnum.Array && mp.BlockType == BlockType.JsonObject)
            {
                BlockIsStarting = false;
                JsonWriter.WriteStartObject(); //start array
                BlockState.Push(BlockStateEnum.Object);
            }
            else if (!string.IsNullOrEmpty(element.Name) || element.Assignment != AssignmentEnum.None)
            {
                BlockIsStarting = true;
            }

            base.Visit(element);

            BlockIsStarting = false;

            if (BlockState.Count > prevBlockStateCount)
            {
                var blockState = BlockState.Pop();
                if (blockState == BlockStateEnum.Array)
                {
                    JsonWriter.WriteEndArray();
                }
                else if (blockState == BlockStateEnum.Object)
                {
                    JsonWriter.WriteEndObject();
                }
                return;
            }

            //Element has no block and no value. Writing an empty object as a value.
            if (!string.IsNullOrEmpty(element.Name) || ((DOM.Mapped.Element)element).Assignment.IsObjectAssignment())
            {
                if (element.Assignment == AssignmentEnum.CC || ((IMappedPair)element).BlockType == BlockType.JsonArray)
                {
                    JsonWriter.WriteStartArray();
                    JsonWriter.WriteEndArray();
                }
                else
                {
                    JsonWriter.WriteStartObject();
                    JsonWriter.WriteEndObject();
                }
            }
        }