Example #1
0
 public XmlNode(NanoXmlNode nanoXmlNode)
 {
     Name = nanoXmlNode.Name;
     Attributes =
         new List<IAttribute>(
             nanoXmlNode.Attributes.Select(a => new NodeAttribute {Name = a.Name, Value = a.Value}));
     SubNodes = new List<INode>(nanoXmlNode.SubNodes.Select(n => new XmlNode(n)));
 }
Example #2
0
        /// <summary>
        ///     Public constructor. Loads xml document from raw string
        /// </summary>
        /// <param name="xmlString">String with xml</param>
        public NanoXmlDocument(string xmlString)
        {
            int i = 0;

            while (true)
            {
                SkipSpaces(xmlString, ref i);

                if (xmlString[i] != '<')
                {
                    throw new NanoXmlParsingException("Unexpected token");
                }

                i++;                     // skip <

                if (xmlString[i] == '?') // declaration
                {
                    i++;                 // skip ?
                    ParseAttributes(xmlString, ref i, _declarations, '?', '>');
                    i++;                 // skip ending ?
                    i++;                 // skip ending >

                    continue;
                }

                if (xmlString[i] == '!')        // doctype
                {
                    while (xmlString[i] != '>') // skip doctype
                    {
                        i++;
                    }

                    i++; // skip >

                    continue;
                }

                _rootNode = new NanoXmlNode(xmlString, ref i);
                break;
            }
        }
Example #3
0
 private void InnerText(ref StringBuilder builder)
 {
     for (int i = 0; i < SubNodes.Count; i++)
     {
         NanoXmlNode node = SubNodes[i];
         builder.Append("<");
         builder.Append(node.Name);
         foreach (NanoXmlAttribute attribute in node.Attributes)
         {
             builder.AppendFormat(" {0}=\"{1}\"", attribute.Name, attribute.Value);
         }
         builder.Append(">");
         if (node.Value == null)
         {
             node.InnerText(ref builder);
         }
         else
         {
             builder.Append(node.Value);
         }
         builder.AppendFormat("</{0}>", node.Name);
     }
 }
Example #4
0
        /// <summary>
        ///     Public constructor. Loads xml document from raw string
        /// </summary>
        /// <param name="xmlString">String with xml</param>
        public NanoXmlDocument(string xmlString)
        {
            int i = 0;

            while (true)
            {
                SkipSpaces(xmlString, ref i);

                if (xmlString[i] != '<')
                    throw new NanoXmlParsingException("Unexpected token");

                i++; // skip <

                if (xmlString[i] == '?') // declaration
                {
                    i++; // skip ?
                    ParseAttributes(xmlString, ref i, _declarations, '?', '>');
                    i++; // skip ending ?
                    i++; // skip ending >

                    continue;
                }

                if (xmlString[i] == '!') // doctype
                {
                    while (xmlString[i] != '>') // skip doctype
                        i++;

                    i++; // skip >

                    continue;
                }

                _rootNode = new NanoXmlNode(xmlString, ref i);
                break;
            }
        }