Пример #1
0
        /// <summary>
        /// Add nodes for the given element and its children
        /// </summary>
        private void CreateNodes(XElement element)
        {
            // Start namespace
            var namespaceNodes = element.Attributes().Where(x => x.IsNamespaceDeclaration).Select(x => new StartNamespace(this, x)).ToList();
            namespaceNodes.ForEach(x => nodes.Add(x));

            // Start element
            var start = new StartElement(this, element);
            nodes.Add(start);

            // Element children
            foreach (var child in element.Nodes())
            {
                var childElement = child as XElement;
                if (childElement != null)
                    CreateNodes(childElement);
                var childText = child as XText;
                if (childText != null)
                    nodes.Add(new CData(this, childText));
            }

            // End element
            nodes.Add(new EndElement(this, start));

            // End namespaces
            var endNamespaceNodes = namespaceNodes.Select(x => new EndNamespace(this, x)).Reverse().ToList();
            endNamespaceNodes.ForEach(x => nodes.Add(x));
        }
Пример #2
0
        /// <summary>
        /// Reading ctor
        /// </summary>
        public XmlTree(ResReader reader)
            : base(reader, ChunkTypes.RES_XML_TYPE)
        {
            strings = new StringPool(reader);
            resourceMap = new ResourceMap(reader);

            while (true)
            {
                var tag = reader.PeekChunkType();
                Node node;
                switch (tag)
                {
                    case ChunkTypes.RES_XML_START_NAMESPACE_TYPE:
                        node = new StartNamespace(reader, this);
                        break;
                    case ChunkTypes.RES_XML_START_ELEMENT_TYPE:
                        node = new StartElement(reader, this);
                        break;
                    case ChunkTypes.RES_XML_CDATA_TYPE:
                        node = new CData(reader, this);
                        break;
                    case ChunkTypes.RES_XML_END_ELEMENT_TYPE:
                        node = new EndElement(reader, this);
                        break;
                    case ChunkTypes.RES_XML_END_NAMESPACE_TYPE:
                        node = new EndNamespace(reader, this);
                        break;
                    default:
                        throw new IOException(string.Format("Unexpected tag: 0x{0:X}", (int)tag));
                }

                nodes.Add(node);
                if (tag == ChunkTypes.RES_XML_END_NAMESPACE_TYPE)
                    break;
            }
        }
Пример #3
0
 /// <summary>
 /// Creation ctor
 /// </summary>
 internal EndElement(XmlTree tree, StartElement start)
     : base(tree, ChunkTypes.RES_XML_END_ELEMENT_TYPE)
 {
     Name = start.Name;
     Namespace = start.Namespace;
 }